3 #include <actionlib/server/simple_action_server.h> 4 #include <geometry_msgs/Pose.h> 5 #include <cpswarm_msgs/TaskAllocatedEvent.h> 6 #include <cpswarm_msgs/TargetPositionEvent.h> 7 #include <cpswarm_msgs/TargetTracking.h> 8 #include <cpswarm_msgs/TargetAction.h> 17 typedef actionlib::SimpleActionServer<cpswarm_msgs::TargetAction>
action_server_t;
49 geometry_msgs::Quaternion
rotate (geometry_msgs::Quaternion rotation)
67 double distance = hypot(msg->tf.translation.x, msg->tf.translation.y);
68 double direction =
yaw() + atan2(msg->tf.translation.y, -msg->tf.translation.x) - M_PI / 2;
71 cpswarm_msgs::TargetPositionEvent event;
73 event.pose.pose.position.x =
pose.position.x + distance * cos(direction);
74 event.pose.pose.position.y =
pose.position.y + distance * sin(direction);
75 event.pose.pose.orientation =
rotate(msg->tf.rotation);
76 event.header.stamp = msg->header.stamp;
105 cpswarm_msgs::TargetPositionEvent event;
106 event.id = msg->task_id;
107 event.header.stamp = msg->header.stamp;
136 if (msg->header.stamp.isValid())
154 cpswarm_msgs::TargetPositionEvent event;
156 event.pose = goal->pose;
157 event.header = goal->pose.header;
172 int main (
int argc,
char** argv)
175 init(argc, argv,
"target_monitor");
180 nh.
param(this_node::getName() +
"/simulation", simulation,
false);
182 nh.
param(this_node::getName() +
"/queue_size", queue_size, 10);
186 nh.
param(this_node::getName() +
"/loop_rate", loop_rate, 5.0);
187 Rate rate(loop_rate);
void found_callback(const cpswarm_msgs::TargetPositionEvent::ConstPtr &msg)
Callback function to receive information about targets found by other CPSs.
targets * monitor
The targets being monitored.
#define ROS_DEBUG_THROTTLE(rate,...)
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 lost_callback(const cpswarm_msgs::TargetPositionEvent::ConstPtr &msg)
Callback function to receive information about targets lost by other CPSs.
#define ROS_DEBUG_ONCE(...)
int main(int argc, char **argv)
Main function to be executed by ROS.
void simulate()
Read simulated targets from parameter file.
void update_callback(const cpswarm_msgs::TargetPositionEvent::ConstPtr &msg)
Callback function to receive updated information about targets from other CPSs.
void assigned_callback(const cpswarm_msgs::TaskAllocatedEvent::ConstPtr &msg)
Callback function to receive information about targets assigned to a CPSs.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void update(geometry_msgs::Pose pose)
Update the state of all targets. If no update has been received for a target within a fixed period...
void fromMsg(const A &, B &b)
double yaw()
Compute the current yaw orientation of the CPS.
void tracking_callback(const cpswarm_msgs::TargetTracking::ConstPtr &msg)
Callback function for target position.
double getYaw(const A &a)
void set_done(const cpswarm_msgs::TargetGoalConstPtr &goal, action_server_t *as)
Callback of the action server which sets the target state to done.
void done_callback(const cpswarm_msgs::TargetPositionEvent::ConstPtr &msg)
Callback function for incoming target done events.
geometry_msgs::Quaternion rotate(geometry_msgs::Quaternion rotation)
Compute the orientation resulting from the rotated CPS orientation.
void pose_callback(const geometry_msgs::PoseStamped::ConstPtr &msg)
Callback function for position updates.
A collection of target objects that are searched, tracked, and rescued by the CPSs.
bool pose_valid
Whether a valid position has been received.
ROSCPP_DECL void spinOnce()
geometry_msgs::Pose pose
Current position of the CPS.
actionlib::SimpleActionServer< cpswarm_msgs::TargetAction > action_server_t
An action server type that allows to set the state of a target.