2 #include <actionlib/server/simple_action_server.h> 3 #include <geometry_msgs/Pose.h> 4 #include <cpswarm_msgs/TaskAllocationEvent.h> 5 #include <cpswarm_msgs/TaskAllocatedEvent.h> 6 #include <cpswarm_msgs/TaskAllocationAction.h> 14 typedef actionlib::SimpleActionServer<cpswarm_msgs::TaskAllocationAction>
Server;
55 void bid_callback(
const cpswarm_msgs::TaskAllocationEvent::ConstPtr& msg)
58 ROS_DEBUG(
"TASK_AUCTION - New bid received from %s", msg->swarmio.node.c_str());
61 winner = msg->swarmio.node;
63 ROS_INFO(
"TASK_AUCTION - Highest bid %.4f received from %s", msg->bid, msg->swarmio.node.c_str());
81 ROS_INFO(
"TASK_AUCTION - Starting task allocation auction for task %d at position (%.6f, %.6f)",
task_id,
task_pose.position.x,
task_pose.position.y);
86 nh.param(this_node::getName() +
"/loop_rate", loop_rate, 5.0);
88 Time start_time = Time::now();
89 while (ok() && !as->isPreemptRequested() && Time::now() - start_time < Duration(
timeout)) {
96 if (
winner.compare(
"") != 0) {
98 allocation.header.stamp = Time::now();
99 allocation.header.frame_id =
"local_origin_ned";
100 allocation.swarmio.name =
"cps_selected";
102 allocation.cps_id =
winner;
104 ROS_INFO(
"TASK_AUCTION - Task %d allocated to %s",
task_id,
winner.c_str());
108 if (as->isPreemptRequested()) {
114 cpswarm_msgs::TaskAllocationResult result;
120 if (
winner.compare(
"") == 0) {
121 as->setAborted(result);
126 as->setSucceeded(result);
137 int main(
int argc,
char **argv)
140 init(argc, argv,
"task_allocation_auction");
149 nh.param(this_node::getName() +
"/timeout",
timeout, 10.0);
151 nh.param(this_node::getName() +
"/queue_size", queue_size, 10);
154 Subscriber cost_subscriber = nh.subscribe<cpswarm_msgs::TaskAllocationEvent>(
"bridge/events/cps_selection", queue_size,
bid_callback);
155 publisher = nh.advertise<cpswarm_msgs::TaskAllocatedEvent>(
"cps_selected", queue_size,
true);
160 ROS_INFO(
"TASK_AUCTION - Task allocation auction action available");
string winner
The UUID of the CPS that is the current highest bidder.
actionlib::SimpleActionServer< cpswarm_msgs::TaskAllocationAction > Server
The server object that offers the task allocation auction as action server.
bool auction_open
Whether the auction is currently open for bidding.
void auction_callback(const cpswarm_msgs::TaskAllocationGoal::ConstPtr &goal, Server *as)
Callback function to start a task allocation auction.
void bid_callback(const cpswarm_msgs::TaskAllocationEvent::ConstPtr &msg)
Callback function to receive auction bids.
int task_id
ID of the task that is auctioned.
double highest_bid
The highest current bid.
int main(int argc, char **argv)
A ROS node that exchanges relative kinematics between CPSs in a swarm.
geometry_msgs::Pose task_pose
Location of the task that is auctioned.
double timeout
The auction duration.
Publisher publisher
Publisher to announce the winner of the auction.
cpswarm_msgs::TaskAllocatedEvent allocation
The result of the task allocation auction.