7 nh.
param(this_node::getName() +
"/loop_rate", loop_rate, 5.0);
10 nh.
param(this_node::getName() +
"/queue_size", queue_size, 10);
11 nh.
param(this_node::getName() +
"/fov",
fov, 0.5);
18 nh.
getParam(this_node::getNamespace() +
"/targets_done", done);
20 target_map.emplace(piecewise_construct, forward_as_tuple(t), forward_as_tuple(make_shared<target>(t,
TARGET_DONE)));
33 while (
ok() &&
cps ==
"") {
42 vector<double> targets_x;
43 vector<double> targets_y;
44 nh.
getParam(this_node::getName() +
"/targets_x", targets_x);
45 nh.
getParam(this_node::getName() +
"/targets_y", targets_y);
46 if (targets_x.size() != targets_y.size()) {
47 ROS_FATAL(
"Invalid targets specified! Exiting...");
50 else if (targets_x.size() < 1)
52 for (
int i = 0; i < targets_x.size(); ++i) {
53 ROS_DEBUG(
"Target %d at [%.2f, %.2f]", i, targets_x[i], targets_y[i]);
54 geometry_msgs::Pose new_target_pose;
55 new_target_pose.position.x = targets_x[i];
56 new_target_pose.position.y = targets_y[i];
57 new_target_pose.orientation.w = 1;
67 if (t.second->lost()) {
75 geometry_msgs::Pose t_pose = t.second->get_pose();
77 ROS_DEBUG(
"Target %d distance %.2f < %.2f", t.first, hypot(pose.position.x - t_pose.position.x, pose.position.y - t_pose.position.y),
fov);
80 if (hypot(pose.position.x - t_pose.position.x, pose.position.y - t_pose.position.y) <=
fov) {
82 cpswarm_msgs::TargetTracking track;
83 track.header.stamp = Time::now();
94 geometry_msgs::Pose
pose;
97 ROS_DEBUG(
"Target %d at [%.2f, %.2f]", msg.id, pose.position.x, pose.position.y);
105 target_map[msg.id]->update(state, pose, msg.header.stamp);
119 ROS_DEBUG(
"Not publishing event for target");
125 target_map.emplace(piecewise_construct, forward_as_tuple(msg.id), forward_as_tuple(make_shared<target>(msg.id, state, pose, msg.header.stamp)));
137 cpswarm_msgs::TargetPositionEvent
target;
138 geometry_msgs::PoseStamped ps;
140 ps.header.frame_id =
"local_origin_ned";
142 target.header.stamp = Time::now();
143 target.swarmio.name = event;
147 if (event ==
"target_found")
150 else if (event ==
"target_update")
153 else if (event ==
"target_lost")
156 else if (event ==
"target_done")
160 ROS_ERROR(
"Not publishing invalid event %s!", event.c_str());
170 double dx = p2.position.x - p1.position.x;
171 double dy = p2.position.y - p1.position.y;
172 double distance = hypot(dx, dy);
173 double direction = (M_PI / 2.0) -
tf2::getYaw(orientation1) + atan2(dy, dx);
176 geometry_msgs::Transform tf;
179 tf.translation.x = -distance * cos(direction);
180 tf.translation.y = distance * sin(direction);
183 p1.orientation.w *= -1;
targets()
Constructor that initializes the private member variables.
void publish_event(string event, int id)
Publish a target position event.
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())
unordered_map< unsigned int, shared_ptr< target > > target_map
A map holding ID and target object of all known targets.
double fov
Range of the target tracking camera in meter. It is used to simulate target detection. Targets within this distance are detected by the CPS.
void uuid_callback(const swarmros::String::ConstPtr &msg)
Callback function to receive the UUID from the communication library.
geometry_msgs::Transform transform(geometry_msgs::Pose p1, geometry_msgs::Pose p2) const
Compute the transformation between two poses.
Publisher target_done_pub
Publisher for transmitting information about completed targets locally to other nodes and remotely to...
Publisher target_lost_pub
Publisher for transmitting information about lost targets locally to other nodes and remotely to othe...
unordered_map< unsigned int, shared_ptr< target > > simulated_targets
A map holding ID and target object of simulated targets, including the ones not yet found...
void simulate()
Read simulated targets from parameter file.
string cps
The UUID of the CPS that owns this class instance.
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)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
double getYaw(const A &a)
geometry_msgs::Pose pose
Position of the target.
A target that is monitored by the CPSs.
NodeHandle nh
A node handle for the main ROS node.
Publisher target_found_pub
Publisher for transmitting information about found targets locally to other nodes and remotely to oth...
ROSCONSOLE_DECL void shutdown()
bool getParam(const std::string &key, std::string &s) const
Publisher tracking_pub
Publisher for transmitting target tracking information in simulation.
target_state_t
An enumeration for the state of a target.
Publisher target_update_pub
Publisher for transmitting updated information about targets locally to other nodes and remotely to o...
ROSCPP_DECL void spinOnce()
geometry_msgs::Pose pose
Current position of the CPS.