This repository provides a simple example to run ROS publisher and sibscriber
-
include
-- listener.hpp
-- talker.hpp -
src
-- listener.cpp
-- talker.cpp
-- listener_node.cpp
-- talker_node.cpp
listener_node.cpp and talker_node.cpp are the files where the objectes for the classes Listener and Talker are created.
- Create a catkin workspace catkin_ws
- Clone the package inside catkin_ws/src using
git clone https://github.com/sakshikakde/beginner_tutorials.git
- Change the directory
cd catkin_ws
- run
catkin build
- Change the directory
cd catkin_ws
- Source the workspace
sourcedevel/setup.bash
- In a terminal, run
roscore
- In a new terminal, run the talker by using
rosrun beginner_tutorials talker
- In a new terminal, run the listener by using
rosrun beginner_tutorials listener
cd catkin_ws
2)Source the workspace
sourcedevel/setup.bash
- In a terminal, run
roslaunch beginner_tutorials talker_chatter.launch platform_name:="my_laptop"
- platform_name : default="sakshi"
- publisher_topic_name : default="/chatter"
- publisher_rate : default = 20
- service_name : default="add_two_ints"
- subscriber_topic_name : default="/chatter"
Use the following command to call the ros service from terminal:
rosservice call /add_two_ints "a: 10
b: 30"
- Change the directory to the workspace
cd catkin_ws
- Build the workspace using the following command:
catkin build --catkin-make-args test
3)Source the workspace
source devel/setup.bash
- In a terminal, run
rostest beginner_tutorials test_broadcaster.launch
- Change the directory to the workspace
cd catkin_ws
- Source the workspace
source devel/setup.bash
- In a terminal, run
roslaunch beginner_tutorials talker_chatter.launch record_bag:=true bags_directory:=/home/sakshi/courses/ENPM808X/week11/catkin_ws/src/beginner_tutorials/results/bag
Note that you need to update the bags_directory param to a suitable location
-
Change the directory to the location where rosbag is recorded
-
Run the command
rosbag play <bagfile_name> --pause
- In a new terminal, change the directory to the workspace
cd catkin_ws
- Source the workspace
source devel/setup.bash
- Run
rosrun beginner_tutorials listener
- Unpause the bag file. the listener node should be able to get the topic messages from the bag file.