2 #include <actionlib/server/simple_action_server.h> 3 #include <geometry_msgs/Pose.h> 4 #include <geometry_msgs/PoseStamped.h> 5 #include <swarmros/String.h> 6 #include <cpswarm_msgs/TaskAllocationEvent.h> 7 #include <cpswarm_msgs/TaskAllocatedEvent.h> 8 #include <cpswarm_msgs/TaskAllocationAction.h> 16 typedef actionlib::SimpleActionServer<cpswarm_msgs::TaskAllocationAction>
Server;
86 double distance = hypot(goal->task_pose.pose.position.x -
pose.position.x, goal->task_pose.pose.position.y -
pose.position.y);
89 ROS_INFO(
"TASK_BID - Compute bid for task %d, value: %.2f",
task_id, 1.0/distance);
92 cpswarm_msgs::TaskAllocationEvent task_allocation;
93 task_allocation.header.stamp = Time::now();
94 task_allocation.header.frame_id =
"local_origin_ned";
95 task_allocation.swarmio.name =
"cps_selection";
96 task_allocation.swarmio.node = goal->auctioneer;
98 task_allocation.bid = 1.0 / distance;
103 nh.param(this_node::getName() +
"/loop_rate", loop_rate, 5.0);
104 Rate rate(loop_rate);
105 while (ok() && !as->isPreemptRequested() &&
allocation.task_id < 0) {
106 ROS_DEBUG_ONCE(
"TASK_BID - Waiting for auction to end");
112 ROS_INFO(
"TASK_BID - Task allocated to: %s",
allocation.cps_id.c_str());
115 if (as->isPreemptRequested()) {
121 cpswarm_msgs::TaskAllocationResult result;
123 result.task_pose = goal->task_pose;
124 as->setSucceeded(result);
143 int main(
int argc,
char **argv)
146 init(argc, argv,
"task_allocation_bid");
157 nh.param(this_node::getName() +
"/loop_rate", loop_rate, 5.0);
158 Rate rate(loop_rate);
160 nh.param(this_node::getName() +
"/queue_size", queue_size, 10);
163 Subscriber pose_subscriber = nh.subscribe<geometry_msgs::PoseStamped>(
"pos_provider/pose", queue_size,
pose_callback);
164 Subscriber allocation_subscriber = nh.subscribe<cpswarm_msgs::TaskAllocatedEvent>(
"bridge/events/cps_selected", queue_size,
allocation_callback);
165 Subscriber uuid_subscriber = nh.subscribe<swarmros::String>(
"bridge/uuid", 1,
uuid_callback);
166 publisher = nh.advertise<cpswarm_msgs::TaskAllocationEvent>(
"cps_selection", queue_size);
170 ROS_DEBUG_ONCE(
"TASK_BID - Waiting for position or UUID...");
176 Server server(nh,
"cmd/task_allocation_bid", boost::bind(&
bid_callback, _1, &server),
false);
178 ROS_INFO(
"TASK_BID - Task allocation bid action available");
actionlib::SimpleActionServer< cpswarm_msgs::TaskAllocationAction > Server
The server object that offers the task allocation auction as action server.
string uuid
The UUID if this CPS.
actionlib::SimpleActionServer< cpswarm_msgs::TaskAllocationAction > Server
The server object that offers the task allocation auction as action server.
geometry_msgs::Pose pose
Position of this CPS.
void pose_callback(const geometry_msgs::PoseStamped::ConstPtr &msg)
Callback function to receive the position of this CPS.
Publisher publisher
Publisher to submit a bid to the auction.
int task_id
The ID of the task that is auctioned.
void uuid_callback(const swarmros::String::ConstPtr &msg)
Callback function to receive the UUID of this CPS.
bool pose_received
Whether a position of this CPS has been received.
int main(int argc, char **argv)
A ROS node that exchanges relative kinematics between CPSs in a swarm.
cpswarm_msgs::TaskAllocatedEvent allocation
The result of the task allocation auction.
void bid_callback(const cpswarm_msgs::TaskAllocationGoal::ConstPtr &goal, Server *as)
Callback function to participate in a task allocation auction.
void allocation_callback(const cpswarm_msgs::TaskAllocatedEvent::ConstPtr &msg)
Callback function to receive the task allocation result.