编写第一个脚本
在本课中,你将学习如何启动,创建和修改脚本。
我们将推出的Python脚本,如果你不知道这种语言也不重要。
打开一个新的终端。
启动空世界:
roslaunch turtlebot_gazebo turtlebot_world.launch world_file:=/opt/ros/indigo/share/turtlebot_gazebo/worlds/empty.world
启动脚本
你应该一步一步做这些说明:
创建一个新目录。
mkdir ~/helloworld
改变目录。
cd ~/helloworld/
下载源码
git clone https://github.com/markwsilliman/turtlebot/
注意:你需要有Github帐号来做这一步。
改变目录.
cd turtlebot
运行脚本
python goforward.py
turtlebot在Gazebo前进。
按
Ctrl+C
的终端停止turtlebot。
创建和修改脚本
现在,您将修改现有的脚本。
turtlebot将围绕它的轴。
改变目录。
cd ~/helloworld/turtlebot/
创建一个副本goforward.py。
cp goforward.py goincircles.py
编辑goincircles.py。
emacs -nw goincircles.py
注意:你可以使用你喜欢的编辑器。
修改线性的
linear.x
从0.2到0和角度angular.z
从0到0.5。
注:turtlebot只使用线性的。
linear.x
和angular.z
值的角,因为它在一个平面作品(2D)世界和它有一个不同的驱动系统,不能横向移动。
按
Ctrl+X
,然后按Ctrl + S
保存更改。保存后完成,你会看到这样的一个信息:
Wrote /home/<user_name>/helloworld/turtlebot/goincircles.py
按
Ctrl + X
,然后按Ctrl + C
退出Emacs。启动脚本。
python goincircles.py
turtlebot围绕其轴线。
按
Ctrl + C
的终端停止turtlebot。
启动另一个脚本
改变目录。
cd ~/helloworld/turtlebot/
启动脚本。
python draw_a_square.py
turtlebot绘制正方形。
按
Ctrl + C
的终端停止turtlebot。
打开的文件goforward.py
和draw_a_square.py
尝试了解命令,阅读注释的意义。
你可以了解更多关于Python在这本书中找到基本的在线教程。
- 本文固定链接: http://www.rosrobot.cn/?id=183
- 转载请注明: znjrobot 于 北京智能佳科技有限公司 发表
《本文》有 0 条评论