1. roscpp(ros c++开发接口)
第六章 roscpp · 中国大学MOOC———《机器人操作系统入门》讲义
2. rospy(ros python开发接口)
***Implement a simple Publisher/Subscriber
Publisher
First lets create a 'scripts' folder to store our Python scripts in:
$ mkdir scripts $ cd scripts
Then download the example script talker.py to your new scripts directory and make it executable:
$ wget https://raw.github.com/ros/ros_tutorials/kinetic-devel/rospy_tutorials/001_talker_listener/talker.py $ chmod +x talker.py
Add the following to your CMakeLists.txt. This makes sure the python script gets installed properly, and uses the right python interpreter.
catkin_install_python(PROGRAMS scripts/talker.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
Subscriber $ roscd beginner_tutorials/scripts/ $ wget https://raw.github.com/ros/ros_tutorials/kinetic-devel/rospy_tutorials/001_talker_listener/listener.py $ chmod +x listener.py
Then, edit the catkin_install_python() call in your CMakeLists.txt so it looks like the following:
catkin_install_python(PROGRAMS scripts/talker.py scripts/listener.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
Building your nodes
We use CMake as our build system and, yes, you have to use it even for Python nodes. This is to make sure that the autogenerated Python code for messages and services is created.
Go to your catkin workspace and run catkin_make:
$ cd ~/catkin_ws $ catkin_make
Examining the Simple Publisher and Subscriber roscore
$ cd ~/catkin_ws $ source ./devel/setup.bash
In the last tutorial we made a publisher called "talker". Let's run it:
$ source ./devel/setup.bash #(#(必须的,否则[rospack] Error: package 'beginner_tutorials' not found) $ rosrun beginner_tutorials talker (C++) $ rosrun beginner_tutorials talker.py (Python)
$ source ./devel/setup.bash #(必须的,否则[rospack] Error: package 'beginner_tutorials' not found) $ rosrun beginner_tutorials listener (C++) $ rosrun beginner_tutorials listener.py (Python)
###特别注意
如果执行
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc
此后打开的终端,默认配置新创建的workspace的ros环境,无需每次打开一个终端都需要再source ~/catkin_ws/devel/setup.bash(注意直接编辑 ~/.bashrc添加相应的bash文件,再source ~/.bashrc也是不可以的。)



