创建工作空间

cd ~
mkdir helloworld
touch goforward.py

python脚本

#!/usr/bin/env python'''
Copyright (c) 2015, Mark Silliman
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''# A very basic TurtleBot script that moves TurtleBot forward indefinitely. Press CTRL + C to stop.  To run:
# On TurtleBot:
# roslaunch turtlebot_bringup minimal.launch
# On work station:
# python goforward.pyimport rospy
from geometry_msgs.msg import Twistclass GoForward():def __init__(self):# initiliazerospy.init_node('GoForward', anonymous=False)# tell user how to stop TurtleBotrospy.loginfo("To stop TurtleBot CTRL + C")# What function to call when you ctrl + c    rospy.on_shutdown(self.shutdown)# Create a publisher which can "talk" to TurtleBot and tell it to move# Tip: You may need to change cmd_vel_mux/input/navi to /cmd_vel if you're not using TurtleBot2self.cmd_vel = rospy.Publisher('cmd_vel_mux/input/navi', Twist, queue_size=10)#TurtleBot will stop if we don't keep telling it to move.  How often should we tell it to move? 10 HZr = rospy.Rate(10);# Twist is a datatype for velocitymove_cmd = Twist()# let's go forward at 0.2 m/smove_cmd.linear.x = 0.2# let's turn at 0 radians/smove_cmd.angular.z = 0# as long as you haven't ctrl + c keeping doing...while not rospy.is_shutdown():# publish the velocityself.cmd_vel.publish(move_cmd)# wait for 0.1 seconds (10 HZ) and publish againr.sleep()def shutdown(self):# stop turtlebotrospy.loginfo("Stop TurtleBot")# a default Twist has linear.x of 0 and angular.z of 0.  So it'll stop TurtleBotself.cmd_vel.publish(Twist())# sleep just makes sure TurtleBot receives the stop command prior to shutting down the scriptrospy.sleep(1)if __name__ == '__main__':try:GoForward()except:rospy.loginfo("GoForward node terminated.")

启动脚本

打开一个终端

roscore

打开另一个终端

cd ~/helloworld
python goforward.py

查看cmd_vel话题内容

rostopic echo cmd_vel

参考资料

https://github.com/markwsilliman/turtlebot/blob/master/goforward.py

ROS学习笔记-用脚本发布cmd_vel话题相关推荐

  1. 【ROS学习笔记】(五)话题消息的定义与使用

    一.目的 在ROS Master中,可以发布与订阅已经定义好的消息,比如海龟的运动.位姿等信息.但有时我们需要自己定义消息的类型. 本节主要目的为定义一个Person个人信息,Publisher发布个 ...

  2. ROS学习笔记-ROS订阅和发布节点

    一个简单的ROS包,一个发布者,一个订阅者 刚开始学习ROS,参考网上的资料完成了测试节点的编写,记录一下. 个人习惯在home/Develop目录中做开发,于是在Develop目录下面创建了一个RO ...

  3. ROS学习笔记九:用C++编写ROS发布与订阅

    ROS学习笔记九:用C++编写ROS发布与订阅 本节主要介绍如何用C++编写一个简单的ROS发布与订阅. 编写发布节点 在之前创建的例子beginner_tutorials软件包中,在其目录下的src ...

  4. ros学习笔记12——python实现发布和接收ros topic

    ros学习笔记12--python实现发布和接收ros topic 一.简单demo 1.工作空间是存放工程开发的相关文件的文件夹 2.创作工作空间指令 3 .创建功能包 4. 创建Topic的订阅发 ...

  5. ROS学习笔记-roslaunch文件的编写用sh脚本控制launch文件启动顺序

    转载自:https://mp.weixin.qq.com/s?__biz=MzUyMTkxODQyOQ==&mid=2247484719&idx=1&sn=27b3a01c29 ...

  6. ROS学习笔记(八): ROS通信架构

    ROS学习笔记(八): ROS通信架构 文章目录 01 Node & Master 1.1 Node 1.2 Master 1.3 启动master和node 1.4 rosrun和rosno ...

  7. ROS学习笔记基础2(基础知识和ROS架构)

    ROS学习笔记1(基础知识和ROS架构) 文章目录 ROS学习笔记1(基础知识和ROS架构) 1. 什么是ROS 2. ROS和其他机器人平台有什么不同 3. ROS架构组成 3.1 文件系统级别 3 ...

  8. 【ROS学习笔记】(三)发布者Publisher的实现

    一.目标功能 ROS Master内有两个节点,一个是Subscriber(turtlesim),一个是Publisher,发布者通过程序实现发布Message,Message的内容包括线速度.角度, ...

  9. ROS学习笔记之小乌龟跟随

    ROS学习笔记之小乌龟跟随 说明:整个案例是跟着赵虚左老师的视频和文档资料学习的,特此感谢赵虚左老师和Autolabor官方 文档地址 视频地址 学习案例之前的预备知识:TF坐标变换 大体实现流程: ...

最新文章

  1. 可重构人工智能设备展现出智能化前景
  2. delphi xe2学习笔记(1)
  3. C语言指针函数MFC版Demo
  4. (四)JS学习笔记 - 模式 - 观察者模式
  5. 恐怖与暴力美学 + 妖魔化:《人皮客栈》观看笔记
  6. android apk如何入门
  7. oracle日志文件大小规则,在线重做Oracle日志文件大小
  8. 多云和混合云_多云互操作性!=云服务聚合
  9. 微信小程序跳转页面后onload中获取到的参数值和跳转页面时传的参数不一样
  10. 也谈跨域数据交互解决方案
  11. 2018年春季软件工程教学设计(初稿)
  12. 网络请求statusCode(状态码) 200、300、400、500序列
  13. Python密码存储器
  14. android碎片按钮,Android 碎片学习 之 如何在碎片调用Activity中的方法来进行赋值操作...
  15. 苹果支付2500万美元和解专利侵权诉讼 获技术授权
  16. 移动前端开发与WEB前端开发有什么联系与区别?
  17. 圆角正方形 html,ps正方形角怎么变圆角 ps怎么在原来的矩形中改成圆角
  18. 最新win10重装系统官方纯净版——2022家庭版多图详细
  19. 设备无法使用、驱动载入异常(39){无法取得路径} 路径 %hs 不存在
  20. Et aliquam sunt quasi harum unde.Deserunt impediSofort wohnen früh aus t quidem vel dolorum ducimus.

热门文章

  1. Pandas基础入门(一)
  2. 网页版怎么连接tcp服务器,请教怎么做一个tcp客户端访问网页
  3. 史上最短命!由于BUG微软撤回Win10更新
  4. 用通俗易懂的大白话彻底搞明白mysql的数据类型以及mysql中的int(11),这个11到底是啥?
  5. MATLAB笔记:打开数据文件的三种方法+读取数据文件的两种方法+保存数据文件的两种方法
  6. ★☆★新书已经到手《Java程序员,上班那点事儿》正式销售纪念帖★☆★
  7. Matlab 导入并显示png格式的透明图片
  8. 公钥基础设施 PKI 技术与应用发展
  9. 如何锻炼自己的逻辑思维
  10. 全球顶级的14位程序员大神!