Create a folder name scripts inside src folder
mkdir scripts
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
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
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}
)
Go to root of the workspace
cd ~/ros_workshop/
catkin build
or
catkin_make
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