步骤
1.建立工作空间
mkdir -p ~/smartcar/src
cd ~/smartcar/src
catkin_init_workspace
cd ~/smartcar/
catkin_make
source devel/setup.bash
注:解决编译后一直要source问题:
gedit ~/.bashrc
在文件末尾添加 : source ~/smartcar/devel/setup.bash
2.创建ROS小车描述包
cd ~/smartcar/src
roscreate-pkg smartcar_description urdf
3.urdf文件的编写
1.在smartcar_description文件夹下创建文件夹:urdf,并在urdf文件夹里创建smart.urdf文件
cd ~/smartcar/src/smartcar_description/
mkdir urdf
cd ~/smartcar/src/smartcar_description/urdf/
touch smartcar.urdf
2.在描述文件smartcar.urdf,写入下述代码:
<?xml version="1.0"?>
<robot name="smartcar">
<link name="base_link"> <!-- 连杆名为base_link-->
<visual> <!--visual设置连杆的可视化信息-->
<geometry> <!--geometry输入模型的形状-->
<box size="0.25 .16 .05"/> <!--为"box"类型,长宽高分别为0.25,0.16,0.05-->
</geometry>
<origin rpy="0 0 1.57075" xyz="0 0 0"/> <!--origin设置相对于连杆相对坐标系的移动和旋转-->
<material name="blue"> <!--material设置连杆的颜色和纹理-->
<color rgba="0 .5 .8 1"/>
</material>
</visual>
</link>
<link name="right_front_wheel"> <!--设置右前轮连杆信息-->
<visual>
<geometry>
<cylinder length=".02" radius="0.025"/>
</geometry>
<material name="black">
<color rgba="0 0 0 1"/>
</material>
</visual>
</link>
<joint name="right_front_wheel_joint" type="continuous"> <!--设置关节信息 type="continuous"表示旋转关节,可以绕单轴无线旋转-->
<axis xyz="0 0 1"/> <!--axis设置旋转轴-->
<parent link="base_link"/> <!--parent关节的父连杆-->
<child link="right_front_wheel"/> <!--child关节的子连杆-->
<origin rpy="0 1.57075 0" xyz="0.08 0.1 -0.03"/> <!--origin将父连杆坐标系转换为子连杆坐标系-->
<limit effort="100" velocity="100"/> <!--limit 设置关节的速度、力和半径(仅当关节是revolute或prismatic时)-->
<joint_properties damping="0.0" friction="0.0"/> <!--joint_properties设置一些属性 阻尼系数 摩擦系数-->
</joint>
<link name="right_back_wheel">
<visual>
<geometry>
<cylinder length=".02" radius="0.025"/>
</geometry>
<material name="black">
<color rgba="0 0 0 1"/>
</material>
</visual>
</link>
<joint name="right_back_wheel_joint" type="continuous">
<axis xyz="0 0 1"/>
<parent link="base_link"/>
<child link="right_back_wheel"/>
<origin rpy="0 1.57075 0" xyz="0.08 -0.1 -0.03"/>
<limit effort="100" velocity="100"/>
<joint_properties damping="0.0" friction="0.0"/>
</joint>
<link name="left_front_wheel">
<visual>
<geometry>
<cylinder length=".02" radius="0.025"/>
</geometry>
<material name="black">
<color rgba="0 0 0 1"/>
</material>
</visual>
</link>
<joint name="left_front_wheel_joint" type="continuous">
<axis xyz="0 0 1"/>
<parent link="base_link"/>
<child link="left_front_wheel"/>
<origin rpy="0 1.57075 0" xyz="-0.08 0.1 -0.03"/>
<limit effort="100" velocity="100"/>
<joint_properties damping="0.0" friction="0.0"/>
</joint>
<link name="left_back_wheel">
<visual>
<geometry>
<cylinder length=".02" radius="0.025"/>
</geometry>
<material name="black">
<color rgba="0 0 0 1"/>
</material>
</visual>
</link>
<joint name="left_back_wheel_joint" type="continuous">
<axis xyz="0 0 1"/>
<parent link="base_link"/>
<child link="left_back_wheel"/>
<origin rpy="0 1.57075 0" xyz="-0.08 -0.1 -0.03"/>
<limit effort="100" velocity="100"/>
<joint_properties damping="0.0" friction="0.0"/>
</joint>
<link name="head">
<visual>
<geometry>
<box size=".02 .03 .03"/>
</geometry>
<material name="white">
<color rgba="1 1 1 1"/>
</material>
</visual>
</link>
<joint name="tobox" type="fixed">
<parent link="base_link"/>
<child link="head"/> <!--将子link(right_front_wheel)连接到父link(base_link)上-->
<origin xyz="0 0.08 0.025"/>
</joint>
</robot>
注:
1…urdf文件主要有两部分构成:和,其中…主要描述模型硬件结构的属性信息,里面对轮子的形状、颜色、质量、惯性等信息进行了语言描述;…可以理解为两个…之间的连接间,如图中蓝色框所示,主要描述两个…之间的位置等固定连接信息。
2.而轮子和小车主体连接是通过中的与建立桥梁的。
3.在正式的往smarter.launch里面写代码时不要有中文注释,否则无法读取内容
4. launch文件的编写
在/smartcar_description文件夹下建立launch文件夹,并创建智能车的launch文件 display.launch
<launch>
<arg name="model" />
<arg name="gui" default="False" />
<param name="robot_description" textfile="$(find smartcar_description)/urdf/smartcar.urdf" />
<param name="use_gui" value="$(arg gui)"/>
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node>
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find urdf_tutorial)/urdf.rviz" />
</launch>
5. rviz模型展示
运行display.launch文件
roslaunch smartcar_description display.launch
6.rviz中一些参数的设置
1.添加Displays
a.点击左下角的Add添加显示内容到Display
b.选择RobotModel,并点击确认添加到Display
2.修改Fixed Frame选项参数
修改Fixed Frame为base_link即可正常显示,如下图: