20191015继续TurtleBot机器人的Rviz仿真

20191013-跟着做简单的TurtleBot机器人仿真
上面这篇文章中最后是对pi_robot机器人进行了仿真。
20191013-对TurtleBot机器人仿真的进化
这篇文章分析了fake_pi_robot.launch文件。

所以在分析fake_turtlebot.launch文件的基础上,今天

首先按同样的过程测试了一下TurtleBot机器人

运行ROS:

roscore

新终端运行:

roslaunch rbx1_bringup fake_turtlebot.launch

在执行时,出现了一下错误:

XML parsing error: unbound prefix: line 4, column 2
when processing file: /home/dubq/rbx/src/rbx1/rbx1_description/urdf/turtlebot_calibration.xacro
included from: /home/dubq/rbx/src/rbx1/rbx1_description/urdf/turtlebot.urdf.xacro

Check that:
 - Your XML is well-formed
 - You have the xacro xmlns declaration: xmlns:xacro="http://www.ros.org/wiki/xacro"
Invalid <param> tag: Cannot load command parameter [robot_description]: command [/opt/ros/kinetic/share/xacro/xacro.py '/home/dubq/rbx/src/rbx1/rbx1_description/urdf/turtlebot.urdf.xacro'] returned with code [2]. 

Param xml is <param command="$(arg urdf_file)" name="robot_description"/>
The traceback for the exception was written to the log file

原因在于turtlebot.urdf.xacro调用的turtlebot_calibration.xacro文件,里面的robot标签后面忘记加下面这句

name="turtlebot_hardware" xmlns:xacro="http://ros.org/wiki/xacro"

同时我还查了一下其它的xacro文件,发现同样的情况也出现在turtlebot_hardware.xacro文件中,修改为:
在这里插入图片描述
新终端运行:

rosrun rviz rviz -d rospack find rbx1_nav/sim.rviz

发布消息才能让它动起来。

rostopic pub -r 10 /cmd_vel geometry_msgs/Twist '{linear: {x: 0.2, y: 0, z: 0}, angular: {x: 0, y: 0, z: 0.5}}'

最后可以看到TurtleBot机器人按照指令中给定的速度及角速度运动起来。
在这里插入图片描述

通过matlab远程控制TurtleBot机器人的运动

暂时没有做太复杂,只是想测试一下20191013-跟着做简单的TurtleBot机器人仿真最后提出的想法是否可行,结果证明了这一点。
在这里插入图片描述
图中数字2对应的按钮Circle Motion对应的程序:

robot = rospublisher(teleopTopicName,'geometry_msgs/Twist');
velmsg = rosmessage(robot);
velmsg.Angular.Z = 0.5;
velmsg.Linear.X = 0.2;
send(robot,velmsg);
latchpub = rospublisher(teleopTopicName, 'IsLatching', true);

图中数字3对应的按钮Stop对应的程序:

velmsg.Angular.X = 0;velmsg.Angular.Y = 0;velmsg.Angular.Z = 0;
velmsg.Linear.X = 0;velmsg.Linear.Y = 0;velmsg.Linear.Z = 0;
send(robot,velmsg);
latchpub = rospublisher(teleopTopicName, 'IsLatching', true);

其实就是将角速度和线速度分别定义为0,即可令机器人停止运动。

关于这个geometry_msgs/Twist信息尝试了一会儿改写成别的样子,毕竟上面X、Y、Z一个一个定义太傻了,但最后还是逼着我去看matlab文档了。
matlab关于Work with Basic ROS Messages的文档

关于geometry_msgs/Twist类型的消息

posesub = rossubscriber('/pose')
posesub = 
  Subscriber with properties:

        TopicName: '/pose'
      MessageType: 'geometry_msgs/Twist'
    LatestMessage: [0x1 Twist]
       BufferSize: 1
    NewMessageFcn: []
posedata = receive(posesub, 10)
posedata = 
  ROS Twist message with properties:

    MessageType: 'geometry_msgs/Twist'
         Linear: [1x1 Vector3]
        Angular: [1x1 Vector3]

There are two other properties in the message: Linear and Angular.
而关于geometry_msgs/Vector3类型的消息

posedata.Linear
ROS Vector3 message with properties:

    MessageType: 'geometry_msgs/Vector3'
              X: 0.0413
              Y: 0.0132
              Z: -0.0402

geometry_msgs/Twist is a composite message made up of two geometry_msgs/Vector3 messages.
Access the X component of the Linear message using this command:

xpos = posedata.Linear.X
xpos = 0.0315

If you want a quick summary of all the data contained in a message, call the showdetails function. showdetails works on messages of any type and recursively displays all the message data properties.

showdetails(posedata)
  Linear     
    X :  0.03147236863931789
    Y :  0.04057919370756193
    Z :  -0.03730131837064939
  Angular    
    X :  0.04133758561390194
    Y :  0.01323592462254095
    Z :  -0.04024595950005905
showdetails helps you during debugging and when you want to quickly explore the contents of a message.

而关于消息数据的传送
Create a message with type geometry_msgs/Twist.

twist = rosmessage('geometry_msgs/Twist')
twist = 
  ROS Twist message with properties:

    MessageType: 'geometry_msgs/Twist'
         Linear: [1x1 Vector3]
        Angular: [1x1 Vector3]

  Use showdetails to show the contents of the message

The numeric properties of this message are initialized to 0 by default. You can modify any of the properties of this message. Set the Linear.Y entry equal to 5.

twist.Linear.Y = 5;

View the message data to make sure that your change took effect.

twist.Linear
ans = 
  ROS Vector3 message with properties:

    MessageType: 'geometry_msgs/Vector3'
              X: 0
              Y: 5
              Z: 0

  Use showdetails to show the contents of the message

所以从上面的官方文档中没有找到更便捷一些的设置方式,其实看过另外一些C++的例程,其中关于这个消息的定制也是一个一个单独定义的。

twistCopyRef = twist
twistCopyDeep = copy(twist)

以上两条语句都可以完成对twist消息的复制,分别得到一个的消息:twistCopyReftwistCopyDeep,其数据内容也与twist一样。但是区别在于:
如果后续修改twistCopyRef消息内容的话,twist消息内容也会随之改变,故称之为:reference copy
而后续修改twistCopyDeep消息内容的话,twist消息内容不会随之改变,故称之为:deep copy

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值