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> 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);
107 publisher.
publish(task_allocation);
121 cpswarm_msgs::TaskAllocationResult result;
123 result.task_pose = goal->task_pose;
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);
166 publisher = nh.
advertise<cpswarm_msgs::TaskAllocationEvent>(
"cps_selection", queue_size);
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");
void publish(const boost::shared_ptr< M > &message) const
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)
string uuid
The UUID if this CPS.
#define ROS_DEBUG_ONCE(...)
actionlib::SimpleActionServer< cpswarm_msgs::TaskAllocationAction > Server
The server object that offers the task allocation auction as action server.
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
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.
void setPreempted(const Result &result=Result(), const std::string &text=std::string(""))
Publisher publisher
Publisher to submit a bid to the auction.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
int task_id
The ID of the task that is auctioned.
bool isPreemptRequested()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void setAborted(const Result &result=Result(), const std::string &text=std::string(""))
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.
ROSCPP_DECL void spinOnce()
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.