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
消息的复制,分别得到一个的消息:twistCopyRef
和twistCopyDeep
,其数据内容也与twist
一样。但是区别在于:
如果后续修改twistCopyRef
消息内容的话,twist
消息内容也会随之改变,故称之为:reference copy
;
而后续修改twistCopyDeep
消息内容的话,twist
消息内容不会随之改变,故称之为:deep copy
;