Skip to content

Latest commit

 

History

History
81 lines (60 loc) · 1.07 KB

pubsub2cpp.md

File metadata and controls

81 lines (60 loc) · 1.07 KB

Publisher and Subscriber C++ Implementation

Publisher modification

Change

ros::init(argc, argv,"talker");

to

ros::init(argc, argv,"publisher");

Subscriber modification

Change

ros::init(argc, argv,"listener");

to

ros::init(argc, argv,"subscriber");

CMakeLists.txt file modifications

Open session2_pubsub/CMakeLists.txt and add following lines to the bottom of the file.

add_executable(publisher src/publisher.cpp)
target_link_libraries(publisher ${catkin_LIBRARIES})

add_executable(subscriber src/subscriber.cpp)
target_link_libraries(subscriber ${catkin_LIBRARIES})

Build the code

Go to root of the workspace

cd ~/ros_workshop/
catkin build

or

catkin_make

Run the code

Open a terminal and run,

roscore

Open a 2nd terminal in the workspace root and run,

source devel/setup.bash
rosrun session2_pubsub publisher

Open a 3rd terminal in the workspace root and run,

source devel/setup.bash
rosrun session2_pubsub subscriber