3 #include <geometry_msgs/Pose.h> 4 #include <cpswarm_msgs/TaskAllocationEvent.h> 5 #include <cpswarm_msgs/TaskAllocatedEvent.h> 6 #include <cpswarm_msgs/TaskAllocationAction.h> 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());
86 nh.
param(this_node::getName() +
"/loop_rate", loop_rate, 5.0);
88 Time start_time = Time::now();
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;
114 cpswarm_msgs::TaskAllocationResult result;
120 if (
winner.compare(
"") == 0) {
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);
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.
void publish(const boost::shared_ptr< M > &message) const
bool auction_open
Whether the auction is currently open for bidding.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void init(const M_string &remappings)
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.
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
int task_id
ID of the task that is auctioned.
void setPreempted(const Result &result=Result(), const std::string &text=std::string(""))
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
double highest_bid
The highest current bid.
bool isPreemptRequested()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
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.
void setAborted(const Result &result=Result(), const std::string &text=std::string(""))
double timeout
The auction duration.
Publisher publisher
Publisher to announce the winner of the auction.
ROSCPP_DECL void spinOnce()
cpswarm_msgs::TaskAllocatedEvent allocation
The result of the task allocation auction.