赞
踩
小白一枚,毕设突发奇想加入了ROS的内容,不知道自己还能不能毕业。以下均为通过看视频,翻博客等整理而成的笔记,并非我的原创。可能会出现一些报错的修改或者简单的代码是我自己做的。哈哈。
Gazebo是一款3D动态模拟器,用于显示机器人模型并创建仿真环境,能够在复杂的室内和室外环境中准确有效地模拟机器人。与游戏引擎提供高保真度的视觉模拟类似,Gazebo提供高保真度的物理模拟,其提供一整套传感器模型,以及对用户和程序非常友好的交互方式。
这篇主要学习:
如果 gazebo没有安装,请自行安装:
1.添加源:
- sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main"
- >
- /etc/apt/sources.list.d/gazebo-stable.list'
wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
2.安装:
sudo apt update
- sudo apt install gazebo11
- sudo apt install libgazebo11-dev
URDF 与 Gazebo 集成流程与 Rviz 实现类似,主要步骤如下:
创建功能包,导入依赖项
编写 URDF 或 Xacro 文件
启动 Gazebo 并显示机器人模型
接下来我们以创建盒状机器人显示在gazebo中为例,学习一下URDF集成gazebo。
在工作空间的src文件夹下打开终端进行以下操作,新建功能包urdf02_gazebo,并且导入依赖包: urdf、xacro、gazebo_ros、gazebo_ros_control、gazebo_plugins
catkin_create_pkg urdf02_gazebo urdf xacro gazebo_ros gazebo_ros_control gazebo_plugins
在urdf02_gazebo文件夹下新建urdf文件夹,在此文件夹下新建demo01_helloworld.urdf:
接下来编写urdf文件,完整的文件内容:
- <robot name="mycar">
- <link name="base_link">
- <visual>
- <geometry>
- <box size="0.5 0.2 0.1" />
- </geometry>
- <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
- <material name="yellow">
- <color rgba="0.5 0.3 0.0 1" />
- </material>
- </visual>
-
- <collision>
- <geometry>
- <box size="0.5 0.2 0.1" />
- </geometry>
- <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
- </collision>
- <inertial>
- <origin xyz="0 0 0" />
- <mass value="6" />
- <inertia ixx="1" ixy="0" ixz="0" iyy="1" iyz="0" izz="1" />
- </inertial>
- </link>
- <gazebo reference="base_link">
- <material>Gazebo/Black</material>
- </gazebo>
-
- </robot>
接下来对上面的文件内容进行解释:
机器人的可视化部分visual:
盒装机器人,所以几何形状geometry选择为box,它在xyz上的尺寸分别是:0.5 ,0.2,0.1
颜色color为黄色,rgba为0.5 0.3 0,透明度为1
- <visual>
- <geometry>
- <box size="0.5 0.2 0.1" />
- </geometry>
- <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
- <material name="yellow">
- <color rgba="0.5 0.3 0.0 1" />
- </material>
- </visual>
连杆碰撞参数collision:碰撞参数用于检测机器人是否与外界环境发生碰撞。
如果是标准几何体,直接复制visual的geometry和origin即可。
- <collision>
- <geometry>
- <box size="0.5 0.2 0.1" />
- </geometry>
- <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
- </collision>
连杆惯性矩阵inertial:小车起步和刹车受到惯性影响,所以要设置一下惯性矩阵。
origin用于设置重心偏移量,如果连杆质量均匀,设置为0 0 0。
mass质量设置为 6 kg
inertial是在不同维度上的坐标值,实际应用时要根据情况进行计算来防止机器人打滑和翻车等,在这里我们先随意设置。
-
- <inertial>
- <origin xyz="0 0 0" />
- <mass value="6" />
- <inertia ixx="1" ixy="0" ixz="0" iyy="1" iyz="0" izz="1" />
- </inertial>
gazebo自己的颜色设置:
- <gazebo reference="base_link">
- <material>Gazebo/Black</material>
- </gazebo>
在/DEMO05_WS/src/urdf02_gazebo目录下新建launch文件夹,在launch文件夹下新建demo01_helloworld.launch
我们要:
launch文件内容:
- <launch>
-
- <param name="robot_description" textfile="$(find urdf02_gazebo)/urdf/helloworld.urdf" />
-
- <include file="$(find gazebo_ros)/launch/empty_world.launch" />
-
- <node pkg="gazebo_ros" type="spawn_model" name="model" args="-urdf -model mycar -param robot_description" />
- </launch>
运行一下launch文件:
milk@milk:~/DEMO05_WS$ roslaunch urdf02_gazebo demo01_helloworld.launch
可以看到gazebo中显示的盒装机器人:
(不知道为什么我第一次不显示机器人模型,等我放弃了关机之后,再开机启动launch文件就显示出来了……)
需求描述:将之前的机器人模型(xacro版)显示在 gazebo 中
结果演示:
实现流程:
需要编写封装惯性矩阵算法的 xacro 文件:我们的车轮、雷达等都要涉及到惯性矩阵的计算。
为机器人模型中的每一个 link 添加 collision 和 inertial 标签,并且重置颜色属性
在 launch 文件中启动 gazebo 并添加机器人模型
在/DEMO05_WS/src/urdf02_gazebo/urdf目录下新建用于封装惯性矩阵算法的文件:head.xacro
这个比较复杂,在这里直接复制文件内容:
- <robot name="base" xmlns:xacro="http://wiki.ros.org/xacro">
- <!-- Macro for inertia matrix -->
- <xacro:macro name="sphere_inertial_matrix" params="m r">
- <inertial>
- <mass value="${m}" />
- <inertia ixx="${2*m*r*r/5}" ixy="0" ixz="0"
- iyy="${2*m*r*r/5}" iyz="0"
- izz="${2*m*r*r/5}" />
- </inertial>
- </xacro:macro>
-
- <xacro:macro name="cylinder_inertial_matrix" params="m r h">
- <inertial>
- <mass value="${m}" />
- <inertia ixx="${m*(3*r*r+h*h)/12}" ixy = "0" ixz = "0"
- iyy="${m*(3*r*r+h*h)/12}" iyz = "0"
- izz="${m*r*r/2}" />
- </inertial>
- </xacro:macro>
-
- <xacro:macro name="Box_inertial_matrix" params="m l w h">
- <inertial>
- <mass value="${m}" />
- <inertia ixx="${m*(h*h + l*l)/12}" ixy = "0" ixz = "0"
- iyy="${m*(w*w + l*l)/12}" iyz= "0"
- izz="${m*(w*w + h*h)/12}" />
- </inertial>
- </xacro:macro>
- </robot>
接下来把之前编写过的小车底盘、雷达、摄像头、汇总文件的xacro文件复制过来:
并且在car.urdf.xacro中包含惯性矩阵文件:<xacro:include filename="head.xacro" />
- <robot name="mycar" xmlns:xacro="http://wiki.ros.org/xacro">
-
- <xacro:include filename="head.xacro" />
-
- <xacro:include filename="demo05_car_base.urdf.xacro" />
- <xacro:include filename="demo06_car_camera.urdf.xacro" />
- <xacro:include filename="demo07_car_laser.urdf.xacro" />
- </robot>
编写launch文件:在/DEMO05_WS/src/urdf02_gazebo/launch目录下新建car.launch
- <launch>
-
- <param name="robot_description" command="$(find xacro)/xacro $(find urdf02_gazebo)/urdf/car.urdf.xacro "/>
-
-
- <include file="$(find gazebo_ros)/launch/empty_world.launch" />
-
- <node pkg="gazebo_ros" type="spawn_model" name="model" args="-urdf -model mycar -param robot_description" />
- </launch>
在demo05_car_base.urdf.xacro中
设置底盘相关参数:
连杆:找到连杆相关代码
- <link name="base_link">
- <visual>
- <geometry>
- <cylinder radius="${base_link_radius}" length="${base_link_length}" />
- </geometry>
- <origin xyz="0 0 0" rpy="0 0 0" />
- <material name="yellow">
- <color rgba="0.5 0.3 0.0 0.5" />
- </material>
- </visual>
- </link>
添加collision:只要是规则的立方体,collision都和visual中的geometry和origin一样,直接复制。
添加interial:我们前面已经把interial封装成专门的宏。打开head.xacro,由于底盘是圆柱体,我们找到圆柱体的interial宏:cylinder_inertial_matrix
添加颜色
修改完成后的小车主体部分代码如下:
-
- <link name="base_link">
- <visual>
- <geometry>
- <cylinder radius="${base_link_radius}" length="${base_link_length}" />
- </geometry>
- <origin xyz="0 0 0" rpy="0 0 0" />
- <material name="yellow">
- <color rgba="0.5 0.3 0.0 0.5" />
- </material>
- </visual>
-
- <collision>
- <geometry>
- <cylinder radius="${base_link_radius}" length="${base_link_length}" />
- </geometry>
- <origin xyz="0 0 0" rpy="0 0 0" />
- </collision>
-
- <xacro:cylinder_inertial_matrix m= "${base_link_mass}" r= "${base_link_radius}" h = "${base_link_length}" />
- </link>
-
- <gazebo reference = "base_link">
- <material>Gazebo/Yellow</material>
- </gazebo>
保存之后,执行一下代码看一下gazebo中的机器人模型:
- milk@milk:~/DEMO05_WS$ source ./devel/setup.bash
- milk@milk:~/DEMO05_WS$ roslaunch urdf02_gazebo demo02_car.launch
驱动轮:
- <!-- qudonglun -->
- <xacro:property name="wheel_radius" value="0.0325" />
- <xacro:property name="wheel_length" value="0.015" />
- <xacro:property name="wheel_mass" value="0.05" />
- <xacro:macro name="add_wheels" params="name flag">
- <link name="${name}_wheel">
- <visual>
- <geometry>
- <cylinder radius="${wheel_radius}" length="${wheel_length}" />
- </geometry>
- <origin xyz="0.0 0.0 0.0" rpy="${PI / 2} 0.0 0.0" />
- <material name="black" />
- </visual>
- <collosion>
- <geometry>
- <cylinder radius="${wheel_radius}" length="${wheel_length}" />
- </geometry>
- <origin xyz="0.0 0.0 0.0" rpy="${PI / 2} 0.0 0.0" />
- </collosion>
- <xacro:cylinder_inertial_matrix m= "${wheel_mass}" r= "${wheel_radius}" h = "${wheel_length}" />
- </link>
- <gazebo reference = "${name}_wheel">
- <material>Gazebo/Red</material>
- </gazebo>
支撑轮
- <link name="${name}_wheel">
- <visual>
- <geometry>
- <sphere radius="${support_wheel_radius}" />
- </geometry>
- <origin xyz="0 0 0" rpy="0 0 0" />
- <material name="black" />
- </visual>
-
- <collision>
- <geometry>
- <sphere radius="${support_wheel_radius}" />
- </geometry>
- <origin xyz="0 0 0" rpy="0 0 0" />
- </collision>
-
- <xacro:sphere_inertial_matrix m = "${support_wheel_mass}" r = "${support_wheel_radius}" />
- </link>
-
- <gazebo reference="${name}_wheel">
- <material>Gazebo/Black</material>
- </gazebo>
demo05_car_base.urdf.xacro整体代码:
- <robot name="my_base" xmlns:xacro="http://www.ros.org/wiki/xacro">
-
- <xacro:property name="PI" value="3.1415926"/>
-
- <material name="black">
- <color rgba="0.0 0.0 0.0 1.0" />
- </material>
-
- <xacro:property name="base_footprint_radius" value="0.001" /> <!-- base_footprint -->
- <xacro:property name="base_link_radius" value="0.1" /> <!-- base_link -->
- <xacro:property name="base_link_length" value="0.08" /> <!-- base_link -->
- <xacro:property name="base_link_mass" value="2" /> <!-- base_link -->
- <xacro:property name="earth_space" value="0.015" /> <!-- lidijianju -->
-
- <!-- dipan -->
- <link name="base_footprint">
- <visual>
- <geometry>
- <sphere radius="${base_footprint_radius}" />
- </geometry>
- </visual>
- </link>
-
- <link name="base_link">
- <visual>
- <geometry>
- <cylinder radius="${base_link_radius}" length="${base_link_length}" />
- </geometry>
- <origin xyz="0 0 0" rpy="0 0 0" />
- <material name="yellow">
- <color rgba="0.5 0.3 0.0 0.5" />
- </material>
- </visual>
-
- <collision>
- <geometry>
- <cylinder radius="${base_link_radius}" length="${base_link_length}" />
- </geometry>
- <origin xyz="0 0 0" rpy="0 0 0" />
- </collision>
-
- <xacro:cylinder_inertial_matrix m= "${base_link_mass}" r= "${base_link_radius}" h = "${base_link_length}" />
- </link>
-
- <gazebo reference = "base_link">
- <material>Gazebo/Yellow</material>
- </gazebo>
-
- <joint name="base_link2base_footprint" type="fixed">
- <parent link="base_footprint" />
- <child link="base_link" />
- <origin xyz="0 0 ${earth_space + base_link_length / 2 }" />
- </joint>
-
- <!-- qudonglun -->
- <xacro:property name="wheel_radius" value="0.0325" />
- <xacro:property name="wheel_length" value="0.015" />
- <xacro:property name="wheel_mass" value="0.05" />
- <xacro:macro name="add_wheels" params="name flag">
- <link name="${name}_wheel">
- <visual>
- <geometry>
- <cylinder radius="${wheel_radius}" length="${wheel_length}" />
- </geometry>
- <origin xyz="0.0 0.0 0.0" rpy="${PI / 2} 0.0 0.0" />
- <material name="black" />
- </visual>
- <collosion>
- <geometry>
- <cylinder radius="${wheel_radius}" length="${wheel_length}" />
- </geometry>
- <origin xyz="0.0 0.0 0.0" rpy="${PI / 2} 0.0 0.0" />
- </collosion>
- <xacro:cylinder_inertial_matrix m= "${wheel_mass}" r= "${wheel_radius}" h = "${wheel_length}" />
- </link>
- <gazebo reference = "${name}_wheel">
- <material>Gazebo/Red</material>
- </gazebo>
-
- <joint name="${name}_wheel2base_link" type="continuous">
- <parent link="base_link" />
- <child link="${name}_wheel" />
- <origin xyz="0 ${flag * base_link_radius} ${-(earth_space + base_link_length / 2 - wheel_radius) }" />
- <axis xyz="0 1 0" />
- </joint>
- </xacro:macro>
- <xacro:add_wheels name="left" flag="1" />
- <xacro:add_wheels name="right" flag="-1" />
- <!-- zhichenglun -->
- <xacro:property name="support_wheel_radius" value="0.0075" />
- <xacro:property name="support_wheel_mass" value="0.0100" />
- <xacro:macro name="add_support_wheel" params="name flag" >
- <link name="${name}_wheel">
- <visual>
- <geometry>
- <sphere radius="${support_wheel_radius}" />
- </geometry>
- <origin xyz="0 0 0" rpy="0 0 0" />
- <material name="black" />
- </visual>
-
- <collision>
- <geometry>
- <sphere radius="${support_wheel_radius}" />
- </geometry>
- <origin xyz="0 0 0" rpy="0 0 0" />
- </collision>
-
- <xacro:sphere_inertial_matrix m = "${support_wheel_mass}" r = "${support_wheel_radius}" />
- </link>
-
- <gazebo reference="${name}_wheel">
- <material>Gazebo/Black</material>
- </gazebo>
-
- <joint name="${name}_wheel2base_link" type="continuous">
- <parent link="base_link" />
- <child link="${name}_wheel" />
- <origin xyz="${flag * (base_link_radius - support_wheel_radius)} 0 ${-(base_link_length / 2 + earth_space / 2)}" />
- <axis xyz="1 1 1" />
- </joint>
- </xacro:macro>
-
- <xacro:add_support_wheel name="front" flag="1" />
- <xacro:add_support_wheel name="back" flag="-1" />
-
- </robot>
gazebo:
设置摄像头相关参数:demo06_car_camera.urdf.xacro
- <robot name="mycar" xmlns:xacro="http://wiki.ros.org/xacro">
-
- <xacro:property name = "camera_length" value = "0.02" />
- <xacro:property name = "camera_width" value = "0.05" />
- <xacro:property name = "camera_height" value = "0.05" />
- <xacro:property name = "camera_mass" value = "0.01" />
- <xacro:property name = "joint_camera_x" value = "0.08" />
- <xacro:property name = "joint_camera_y" value = "0" />
- <xacro:property name = "joint_camera_z" value = "${base_link_length / 2 + camera_height / 2}" />
- <link name = "camera">
- <visual>
- <geometry>
- <box size = "${camera_length} ${ camera_width} ${camera_height}" />
- </geometry>
-
- <material name = "black ">
- <color rgba = "0 0 0 0.8" />
- </material>
- </visual>
- <collision>
- <geometry>
- <box size = "${camera_length} ${ camera_width} ${camera_height}" />
- </geometry>
- </collision>
- <xacro:Box_inertial_matrix m = "${camera_mass}" l = "${camera_length}" w = "${camera_width}" h = "${camera_height}" />
- </link>
- <gazebo reference = "camera">
- <material>Gazebo/Blue</material>
- </gazebo>
-
- <joint name = "camera2base" type = "fixed">
- <parent link = "base_link" />
- <child link = "camera" />
- <origin xyz ="${joint_camera_x} ${joint_camera_y} ${joint_camera_z}" rpy= "0 0 0" />
- </joint>
- </robot>
-
设置雷达相关参数:demo07_car_laser.urdf.xacro
- <robot name="mycar" xmlns:xacro="http://wiki.ros.org/xacro">
- <xacro:property name = "support_radius" value = "0.01" />
- <xacro:property name = "support_length" value = "0.15" />
- <xacro:property name = "support_mass" value = "0.1" />
- <xacro:property name = "laser_radius" value = "0.03" />
- <xacro:property name = "laser_length" value = "0.05" />
- <xacro:property name = "laser_mass" value = "0.02" />
-
- <xacro:property name = "joint_support_x" value = "0" />
- <xacro:property name = "joint_support_y" value = "0" />
- <xacro:property name = "joint_support_z" value = "${base_link_length / 2 +support_length / 2}" />
-
- <xacro:property name = "joint_laser_x" value = "0" />
- <xacro:property name = "joint_laser_y" value = "0" />
- <xacro:property name = "joint_laser_z" value = "${support_length / 2 + laser_length / 2}" />
-
- <link name ="support">
- <visual>
- <geometry>
- <cylinder radius = "${support_radius}" length = "${support_length}"/>
- </geometry>
- <material name = "yellow">
- <color rgba = "0.8 0.5 0.0 0.5" />
- </material>
- </visual>
- <collision>
- <geometry>
- <cylinder radius = "${support_radius}" length = "${support_length}"/>
- </geometry>
- </collision>
- <xacro:cylinder_inertial_matrix m = "${support_mass}" r ="${support_radius}" h = "${support_length}" />
- </link>
-
- <gazebo reference = "support">
- <material>Gazebo/Gray</material>
- </gazebo>
-
- <joint name = "support2base" type = "fixed">
- <parent link ="base_link" />
- <child link = "support"/>
- <origin xyz = "${joint_support_x} ${joint_support_y} ${joint_support_z}" rpy ="0 0 0" />
- </joint>
-
- <link name ="laser">
- <visual>
- <geometry>
- <cylinder radius = "${laser_radius}" length = "${laser_length}"/>
- </geometry>
- <material name = "black">
- <color rgba = "0.0 0.0 0.0 0.5" />
- </material>
- </visual>
- <collision>
- <geometry>
- <cylinder radius = "${laser_radius}" length = "${laser_length}"/>
- </geometry>
- </collision>
- <xacro:cylinder_inertial_matrix m="${laser_mass}" r="${laser_radius}" h="${laser_length}" />
- </link>
- <gazebo reference = "laser">
- <material>Gazebo/Black</material>
- </gazebo>
-
- <joint name = "laser2support" type = "fixed">
- <parent link ="support" />
- <child link = "laser"/>
- <origin xyz = "${joint_laser_x} ${joint_laser_y} ${joint_laser_z}" rpy ="0 0 0" />
- </joint>
- </robot>
-
gazebo:
到目前为止,我们已经可以将机器人模型显示在 Gazebo 之中了,但是当前默认情况下,在 Gazebo 中机器人模型是在 empty world 中,并没有类似于房间、家具、道路、树木... 之类的仿真物,如何在 Gazebo 中创建仿真环境呢?
Gazebo 中创建仿真实现方式有两种:
方式1: 直接添加内置组件创建仿真环境
方式2: 手动绘制仿真环境(更为灵活)
也还可以直接下载使用官方或第三方提高的仿真环境插件。
首先打开新终端,启动roscore
$roscore
然后启动gazebo
$rosrun gazebo_ros gazebo
点击上边栏的立方体添加
启动 gazebo ,打开构建面板,绘制仿真环境
保存构建的环境
点击: 左上角 file ---> Save (保存路径功能包下的: models)
然后 file ---> Exit Building Editor
保存为 world 文件
可以像方式1一样再添加一些插件,然后保存为 world 文件(保存路径功能包下的: worlds)
还可以下载官方提供的插件,下载地址:
https://github.com/osrf/gazebo_models
解压后的文件中有大量的模型:
这些模型占用空间太大了,我下载后只留下了几个自己需要的模型。
两轮差速配置
- <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>
-
- <!-- 每一个驱动轮都需要配置传动装置 -->
- <xacro:joint_trans joint_name="left_wheel2base_link" />
- <xacro:joint_trans joint_name="right_wheel2base_link" />
-
- <!-- 控制器 -->
- <gazebo>
- <plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
- <rosDebugLevel>Debug</rosDebugLevel>
- <publishWheelTF>true</publishWheelTF>
- <robotNamespace>/</robotNamespace>
- <publishTf>1</publishTf>
- <publishWheelJointState>true</publishWheelJointState>
- <alwaysOn>true</alwaysOn>
- <updateRate>100.0</updateRate>
- <legacyMode>true</legacyMode>
- <leftJoint>left_wheel2base_link</leftJoint> <!-- 左轮 -->
- <rightJoint>right_wheel2base_link</rightJoint> <!-- 右轮 -->
- <wheelSeparation>${base_link_radius * 2}</wheelSeparation> <!-- 车轮间距 -->
- <wheelDiameter>${wheel_radius * 2}</wheelDiameter> <!-- 车轮直径 -->
- <broadcastTF>1</broadcastTF>
- <wheelTorque>30</wheelTorque>
- <wheelAcceleration>1.8</wheelAcceleration>
- <commandTopic>cmd_vel</commandTopic> <!-- 运动控制话题 -->
- <odometryFrame>odom</odometryFrame>
- <odometryTopic>odom</odometryTopic> <!-- 里程计话题 -->
- <robotBaseFrame>base_footprint</robotBaseFrame> <!-- 根坐标系 -->
- </plugin>
- </gazebo>
-
- </robot>
最后还需要将上述 xacro 文件集成进总的机器人模型文件,代码示例如下:
- <!-- 组合小车底盘与摄像头 -->
- <robot name="my_car_camera" xmlns:xacro="http://wiki.ros.org/xacro">
- <xacro:include filename="my_head.urdf.xacro" />
- <xacro:include filename="my_base.urdf.xacro" />
- <xacro:include filename="my_camera.urdf.xacro" />
- <xacro:include filename="my_laser.urdf.xacro" />
- <xacro:include filename="move.urdf.xacro" />
- </robot>
- <launch>
- <!--1.需要在参数服务器中载入 urdf -->
- <param name="robot_description" command="$(find xacro)/xacro $(find urdf02_gazebo)/urdf/car.urdf.xacro" />
- <!--2.启动 Gazebo 仿真环境 -->
- <include file="$(find gazebo_ros)/launch/empty_world.launch" >
- <arg name="world_name" value="$(find urdf02_gazebo)/worlds/my_world/model.world" />
- </include>
- <!--3.在 Gazebo 中添加机器人模型 -->
- <node pkg="gazebo_ros" type="spawn_model" name="spawn_model" args="-urdf -model car -param robot_description" />
- </launch>
-
- $ source ./devel/setup.bash
- $ roslaunch urdf02_gazebo demo03_env.launch
使用 topic list 查看话题列表:
$ rostopic list
会发现多了 /cmd_vel 然后发布 vmd_vel 消息控制即可
使用命令控制(或者可以编写单独的节点控制)
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}}'
机器人开始做圆周运动。
launch文件:demo04_sensor.launch
- <launch>
- <!-- 启动 rviz -->
- <node pkg="rviz" type="rviz" name="rviz" />
-
- <!-- 关节以及机器人状态发布节点 -->
- <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
- <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />
-
- </launch>
$ roslaunch urdf02_gazebo demo04_sensor.launch
添加robotmodel和odometry组件
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。