Skip to content

Latest commit

 

History

History
94 lines (71 loc) · 1.25 KB

pubsub2python.md

File metadata and controls

94 lines (71 loc) · 1.25 KB

Publisher and Subscriber C++ Implementation

Create a folder name scripts inside src folder

mkdir scripts

Publisher modification

Change

rospy.init_node('talker', anonymous=True)

to

rospy.init_node('publisher', anonymous=True)

Open a terminal in the file location and Run

chmod +x publisher.py

Subscriber modification

Change

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

to

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

and open a terminal in the file location and Run,

chmod +x subscriber.py

CMakeLists.txt file modifications

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

catkin_install_python(PROGRAMS scripts/subscriber.py scripts/publisher.py
  DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

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.py

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

source devel/setup.bash
rosrun session2_pubsub subscriber.py