moving_objects_echoer_node.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <find_moving_objects/MovingObjectArray.h>
3 #include <find_moving_objects/MovingObject.h>
4 
5 using namespace std;
6 
7 
8 
9 void callback(const find_moving_objects::MovingObjectArray::ConstPtr & msg)
10 {
11  cout << "Received message from node " << msg->origin_node_name
12  << " containing " << msg->objects.size() << " detected moving objects." << endl;
13 
14  for (int i=0; i<msg->objects.size(); ++i)
15  {
16  cout << " Object " << i << " has center point at ("
17  << msg->objects[i].position.x << ","
18  << msg->objects[i].position.y << ","
19  << msg->objects[i].position.z << ") relative the sensor (i.e. in frame "
20  << msg->objects[i].header.frame_id << ")"
21  << endl << " and at ("
22  << msg->objects[i].position_in_map_frame.x << ","
23  << msg->objects[i].position_in_map_frame.y << ","
24  << msg->objects[i].position_in_map_frame.z << ") in the map (i.e. in frame "
25  << msg->objects[i].map_frame << ")" << endl
26  << " and is travelling with relative speed "
27  << msg->objects[i].speed << "m/s" << endl
28  << " and absolute speed "
29  << msg->objects[i].speed_in_map_frame << "m/s." << endl;
30  }
31 
32  // See msg/MovingObject.msg for the other fields in the message which can be accessed in the same way.
33 }
34 
35 
36 
37 int main (int argc, char ** argv)
38 {
39  // Init ROS
40  ros::init(argc, argv, "moving_object_echoer_node", ros::init_options::AnonymousName);
43 
44  // Wait for time to become valid
46 
47  // Init publisher
48  string topic;
49  int buffer_size;
50  nh_priv.param("topic", topic, string("moving_objects"));
51  nh_priv.param("buffer_size", buffer_size, 10);
52 
53  ros::Subscriber sub = nh.subscribe(topic, buffer_size, callback);
54 
55  // Start main ROS loop
56  ros::spin();
57 
58  return 0;
59 }
int main(int argc, char **argv)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
void callback(const find_moving_objects::MovingObjectArray::ConstPtr &msg)
static bool waitForValid()


find_moving_objects
Author(s): Andreas Gustavsson
autogenerated on Mon Jun 10 2019 13:13:19