6.7.1 机器人运动控制以及里程计信息显示
本节介绍的重点是,将三者结合通过gazebo模拟机器人的传感器,然后在rviz中显示这些传感器感知到的数据,主要包括:
- 运动控制以及里程计信息显示
- 雷达信息仿真以及显示
- 摄像头信息仿真以及显示
- kinect信息仿真以及显示(带有深度信息的摄象头)
参考信息:http://gazebosim.org/tutoriais?tut=ros_gzplugins
机器人运动控制以及里程计信息显示
使用到ros中组件:ros_control
为保证ros程序的可移植性(仿真平台,实物平台),ros内置的解决方案是ros_control;ros_control是一组软件包,它包含了控制器接口,控制器管理器,传输和硬件接口。ros_control是一套机器人控制的中间件,是一套规范,不同的机器人平台使用该套规范,就能保证tos程序兼容。通过这套规范,实现了一种可插拔的架构设计,大大提高了程序设计的效率和灵活性;
运动控制实现流程
1.已经创建完毕的机器人模型,编写一个单独xacro文件,为机器人模型添加传动装置以及控制器
创建urdf_gazebo/xacro/gazebo/action.xacro
2.将此文件集成进xacro文件
将action.xacro
文件包含进 my_car.urdf.xacro
中
编写action.xacro
文件—参考的是gazebo/tutorial 中的different drive
文件
<!--differential drive 适合两轮底盘-->
<!--skid steering drive 适合四轮底盘-->
<robot name="my_car_move" xmlns:xacro="http://wiki.ros.org/xacro">
<!--传动实现:用于连接控制器与关节-->
<xacro:macro name="joint_trans" params="joint_name" >
<!--transmission is important to link the joints and the controller-->
<transmission name="${joint_name}_trans">
<type>transmission_interface/SimpleTransmission</type>
<joint name="${joint_name}">
<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
</joint>
<actuator name="${joint_name}_motor">
<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
<mechanicalReduction>1</mechanicalReduction>
</actuator>
</transmission>
</xacro:macro>
<!--left, right_wheel都需要配置传动装置-->
<xacro:joint_trans joint_name="left_wheel_to_base" />
<xacro:joint_trans joint_name="right_wheel_to_base" />
<!--控制器-->
<gazebo>
<plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
<rosDebugLevel>Debug</rosDebugLevel>
<publishWheelTF>true</publishWheelTF>
<robotNamespace>/</robotNamespace>
<!-- <publishTf>1</publishFf> -->
<publishWheelJointState>true</publishWheelJointState>
<alwaysOn>true</alwaysOn>
<updateRate>10.0</updateRate> <!-- Plugin update rate in Hz -->
<legacyMode>true</legacyMode> <!-- Set to true to swap right and left wheels, defaults to true -->
<leftJoint>left_wheel_to_base</leftJoint> <!-- Name of left joint, defaults to `left_joint` -->
<rightJoint>right_wheel_to_base</rightJoint> <!-- Name of right joint, defaults to `right_joint` -->
<wheelSeparation>${base_radius*2}</wheelSeparation>
<wheelDiameter>${wheel_radius*2}</wheelDiameter>
<broadcastTF>1</broadcastTF>
<wheelTorque>30</wheelTorque> <!-- Maximum torque which the wheels can produce, in Nm, defaults to 5 Nm -->
<wheelAcceleration>1.0</wheelAcceleration> <!-- Wheel acceleration, in rad/s^2, defaults to 0.0 rad/s^2 -->
<commandTopic>cmd_vel</commandTopic> <!-- Topic to receive geometry_msgs/Twist message commands, defaults to `cmd_vel` 运动控制话题-->
<odometryTopic>odom</odometryTopic> <!-- Topic to publish nav_msgs/Odometry messages, defaults to `odom` 里程计话题-->
<odometryFrame>odom</odometryFrame> <!-- Odometry frame, defaults to `odom` -->
<robotBaseFrame>base_footprint</robotBaseFrame> <!-- Robot frame to calculate odometry from, defaults to `base_footprint` -->
<odometrySource>1</odometrySource> <!--Odometry source, 0 for ENCODER, 1 for WORLD, defaults to WORLD-->
<publishOdom>true</publishOdom> <!--Set to true to publish transforms for the odometry, defaults to true-->
</plugin>
</gazebo>
</robot>
3.启动gazebo并发布/cmd_vel 消息控制机器人运动
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
启动雷达小车的控制节点,然后就可根据键盘控制小车运动(这个功能包 可能需要另外使用sudo apt-get install ros-noetic-teleop-twist-keyboard
安装)
查看里程计信息只能在rviz中实现
新建launch文件:launch/demo03_odom.launch
<launch>
<node pkg="rviz" type="rviz" name="rviz" args="-d $(find urdf_rviz)/config/show_urdf1.rviz" />
<node pkg="joint_state_publisher" type="joint_state_publisher" name="joint_state" />
<node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state" />
</launch>
1.在启动完demo02文件后,再启动demo03文件,并在rviz的UI中设置fixed frame为odom,并且添加add/odometry,在odometry标签下设置topic为/odom
2.启动 rosrun teleop_twist_keyboard teleop_twist_keyboard.py
小车运动控制节点,然后就可以在rviz中看到小车速度箭头变化的动画