ROS-Subscriber
Study note for ROS subscriber.
Model of Topic
- Publisher(turtlesim)
- –[Message(geometry_msgs::Twist)]–>
- Topic (/turtle1/pose)
- –[Message(geometry_msgs::Twist)]–>
- Subscriber(Pose Listener)
Programming realization
How to realize a subscriber
- initialize ROS node
- subscribe required topic
- loop wait the msgs from topic, after receiving msgs, enter callback function
- implement msgs processing in the callback function
Code
Also we put this node into function package learning_topic
Create velocity_publisher.cpp
file in learning_topic/src
:
1 |
|
Note
- Callback function must be sufficient, or newer data will be blocked
Configure the compile run of subscriber
Steps same as publisher
Add two lines to learning\_topic/CMakeLists.txt
(in build part):
1 | add_executable(velocity_publisher src/pose_subscriber.cpp) |
Compile
1 | $ cd ~/ROS_study/catkin_ws |
The output of pose_subscriber:
1 | ... |
ROS-Subscriber