工作空间
创建工作空间
1.创建catkin_ws的文件夹,并在这个文件夹中创建src文件夹
2.在src中输入catkin_init_workspace
3.在catkin_ws中输入catkin_make
4.设置环境变量,输入source devel/setup.bash
5.输入vi ~/.bashrc修改环境变量,最后一行增加source ~/catkin_ws/devel/setup.bash,再在终端输入source ~/.bashrc
6.检查环境变量终端输入echo $ROS_PACKAGE_PATH
创建功能包
1.在src中终端输入catkin_create_pkg learning_commnication roscpp rospy ros_msgs
2.在cakin_ws中输入catkin_make
话题编程流程
1.在cmake_list中输入
target_link_libraries(talker {catkin_LIBRARIES})
add_executable(talker src/talker.cpp)
add_executable(listener src/listener.cpp)
2.在工作空间下面输入catkin_make
定义话题消息
1.创建msg文件
2.在package.xml中添加功能包
** <build_depend>message_generation</build_depend>**
<exec_depend>message_runtime</exec_depend>
3.在cmakelists.txt中添加
message_generation
添加依赖message_runtime
添加add_message_files(FILES Person.msg)
generate_messages(DEPENDENCIES std_msgs)
4.终端输入catkin_make
服务编程
添加add_service_files(FILES AddTwoInts.srv)
ros分布式通信
1、分别找出主机和树莓派的ip地址
2、在主机和树莓派中分别输入sudo vi /etc/hosts,并分别修改主机和树莓的hosts
3、主机中加入树莓派IP+raspberrypi,树莓派端加入主机IP+hcx-pc
4、测试是否能够进行通信,分别输入ping rasberrypi和ping hcx-pc
5、在树莓派端输入vi .bashrc并在最后一行加入
export ROS_MASTER_URI=http://hcx-pc:11311
6、在本地端输入
export ROS_MASTER_URI=http://localhost:11311
7、在本地输入rosrun turtlesim turtlesim_node **
8、在树莓派端输入rostopic list**和