|
1 | 1 | #include "ros/ros.h"
|
2 |
| -#include "std_msgs/String.h" |
| 2 | +#include "sensor_msgs/Image.h" |
3 | 3 |
|
4 |
| -/** |
5 |
| - * This tutorial demonstrates simple receipt of messages over the ROS system. |
6 |
| - */ |
7 |
| -void chatterCallback(const std_msgs::String::ConstPtr& msg) |
| 4 | +std::string topic_; |
| 5 | +void imgCallback(const sensor_msgs::Image::ConstPtr& msg) |
8 | 6 | {
|
9 |
| - ROS_INFO("I heard: [%s]", msg->data.c_str()); |
| 7 | + ROS_INFO("I heard image on %s",topic_.c_str()); |
10 | 8 | }
|
11 | 9 |
|
12 | 10 | int main(int argc, char **argv)
|
13 | 11 | {
|
14 |
| - /** |
15 |
| - * The ros::init() function needs to see argc and argv so that it can perform |
16 |
| - * any ROS arguments and name remapping that were provided at the command line. |
17 |
| - * For programmatic remappings you can use a different version of init() which takes |
18 |
| - * remappings directly, but for most command-line programs, passing argc and argv is |
19 |
| - * the easiest way to do it. The third argument to init() is the name of the node. |
20 |
| - * |
21 |
| - * You must call one of the versions of ros::init() before using any other |
22 |
| - * part of the ROS system. |
23 |
| - */ |
| 12 | + |
24 | 13 | ros::init(argc, argv, "listener");
|
25 | 14 |
|
26 |
| - /** |
27 |
| - * NodeHandle is the main access point to communications with the ROS system. |
28 |
| - * The first NodeHandle constructed will fully initialize this node, and the last |
29 |
| - * NodeHandle destructed will close down the node. |
30 |
| - */ |
31 | 15 | ros::NodeHandle n;
|
32 | 16 |
|
33 |
| - /** |
34 |
| - * The subscribe() call is how you tell ROS that you want to receive messages |
35 |
| - * on a given topic. This invokes a call to the ROS |
36 |
| - * master node, which keeps a registry of who is publishing and who |
37 |
| - * is subscribing. Messages are passed to a callback function, here |
38 |
| - * called chatterCallback. subscribe() returns a Subscriber object that you |
39 |
| - * must hold on to until you want to unsubscribe. When all copies of the Subscriber |
40 |
| - * object go out of scope, this callback will automatically be unsubscribed from |
41 |
| - * this topic. |
42 |
| - * |
43 |
| - * The second parameter to the subscribe() function is the size of the message |
44 |
| - * queue. If messages are arriving faster than they are being processed, this |
45 |
| - * is the number of messages that will be buffered up before beginning to throw |
46 |
| - * away the oldest ones. |
47 |
| - */ |
48 |
| - ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback); |
49 |
| - |
50 |
| - /** |
51 |
| - * ros::spin() will enter a loop, pumping callbacks. With this version, all |
52 |
| - * callbacks will be called from within this thread (the main one). ros::spin() |
53 |
| - * will exit when Ctrl-C is pressed, or the node is shutdown by the master. |
54 |
| - */ |
| 17 | + |
| 18 | + n.param<std::string>("topic", topic_, "/cam0/image_raw"); |
| 19 | + |
| 20 | + ros::Subscriber sub = n.subscribe(topic_, 1000, imgCallback); |
| 21 | + |
55 | 22 | ros::spin();
|
56 | 23 |
|
57 | 24 | return 0;
|
|
0 commit comments