栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

ros学习(2)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ros学习(2)

整个ROS包括的packages如下: 

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也是不可以的。)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/339526.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号