23 nh.param(this_node::getName() +
"/loop_rate", loop_rate, 5.0);
25 nh.param(this_node::getName() +
"/queue_size", queue_size, 10);
27 nh.param(this_node::getName() +
"/tracking_timeout", timeout, 5.0);
28 this->timeout = Duration(timeout);
32 target_found_pub =
nh.advertise<cpswarm_msgs::TargetPositionEvent>(
"target_found", queue_size,
true);
33 target_update_pub =
nh.advertise<cpswarm_msgs::TargetPositionEvent>(
"target_update", queue_size,
true);
34 target_lost_pub =
nh.advertise<cpswarm_msgs::TargetPositionEvent>(
"target_lost", queue_size,
true);
35 target_done_pub =
nh.advertise<cpswarm_msgs::TargetPositionEvent>(
"target_done", queue_size,
true);
38 rate =
new Rate(loop_rate);
46 ROS_DEBUG(
"Found target %d at (%.2f,%.2f)",
id, pose.position.x, pose.position.y);
49 cpswarm_msgs::TargetPositionEvent
target;
50 geometry_msgs::PoseStamped ps;
52 ps.header.frame_id =
"local_origin_ned";
54 target.header.stamp = Time::now();
55 target.swarmio.name =
"target_found";
85 cpswarm_msgs::TargetPositionEvent
target;
86 geometry_msgs::PoseStamped ps;
88 ps.header.frame_id =
"local_origin_ned";
90 target.header.stamp = Time::now();
91 target.swarmio.name =
"target_lost";
108 ROS_DEBUG(
"Target %d already done",
id);
116 nh.getParam(this_node::getNamespace() +
"/targets_done", done);
118 nh.setParam(this_node::getNamespace() +
"/targets_done", done);
121 cpswarm_msgs::TargetPositionEvent
target;
122 geometry_msgs::PoseStamped ps;
124 ps.header.frame_id =
"local_origin_ned";
126 target.header.stamp = Time::now();
127 target.swarmio.name =
"target_done";
136 ROS_DEBUG(
"Target %d done",
id);
143 ROS_DEBUG(
"Target %d already assigned",
id);
155 ROS_DEBUG(
"Target %d assigned",
id);
163 double moved = hypot(
last_pose.position.x - pose.position.x,
last_pose.position.y - pose.position.y);
171 ROS_DEBUG(
"Found target %d at (%.2f,%.2f)",
id, pose.position.x, pose.position.y);
174 cpswarm_msgs::TargetPositionEvent
target;
175 geometry_msgs::PoseStamped ps;
177 ps.header.frame_id =
"local_origin_ned";
179 target.header.stamp = Time::now();
180 target.swarmio.name =
"target_found";
192 cpswarm_msgs::TargetPositionEvent
target;
193 geometry_msgs::PoseStamped ps;
195 ps.header.frame_id =
"local_origin_ned";
197 target.header.stamp = Time::now();
198 target.swarmio.name =
"target_update";
202 ROS_DEBUG(
"Target %d update",
id);
~target()
Destructor that destroys all objects.
void lost()
Check whether the target tracked by this CPS has been lost. Switch state from TARGET_TRACKED to TARGE...
int id
The ID of this target. Negative IDs are invalid.
Time stamp
Time stamp of latest update of the target.
Publisher target_update_pub
Publisher for transmitting updated information about targets to other CPSs.
double target_tolerance
Minimum distance between two consecutive target positions such that a target update event is publishe...
Duration timeout
The time in seconds after which a target transitions into the state TARGET_LOST when no target update...
Publisher target_lost_pub
Publisher for transmitting information about lost targets to other CPSs.
Publisher target_done_pub
Publisher for transmitting information about completed targets to other CPSs.
void update(target_state_t state, geometry_msgs::Pose pose, Time stamp)
Update the information about a target.
target_state_t state
State of the target.
geometry_msgs::Pose get_pose()
Get the position of the target.
geometry_msgs::Pose last_pose
The position of the target the last time it was published as target position event.
void operator=(const target &t)
Assignment operator.
geometry_msgs::Pose pose
Position of the target.
A target that is monitored by the CPSs.
Rate * rate
The loop rate object for running the behavior control loops at a specific frequency.
target_state_t
An enumeration for the state of a target.
NodeHandle nh
A node handle for the main ROS node.
Publisher target_found_pub
Publisher for transmitting information about found targets to other CPSs.