目录
1创建功能包:
catkin_create_pkg robot_description urdf xacro
2.编写urdf模型文件:
该模型具有6个link,5个joint。需要注意的是,电机的坐标是相对joint的。
<robot name="my robot">
<link name="base_link">
<visual>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
<geometry>
<cylinder radius="0.13" length="0.005"/>
</geometry>
<material name="yellow">
<color rgba="1 0.4 0 1"/>
</material>
</visual>
</link>
<joint name="left_motor_joint" type="fixed">
<origin xyz="-0.055 0.075 0" rpy="0 0 0"/>
<parent link="base_link"/>
<child link="left_motor"/>
</joint>
<link name="left_motor">
<visual>
<origin xyz="0 0 0" rpy="1.5707 0 0"/>
<geometry>
<cylinder radius="0.02" length="0.08"/>
</geometry>
<material name="gray">
<color rgba="0.75 0.75 0.75 1 "/>
</material>
</visual>
</link>
<joint name="left_wheel_joint" type="continuous">
<origin xyz="0 0.0485 0" rpy="0 0 0"/>
<parent link="left_motor"/>
<child link="left_wheel"/>
<axis xyz="0.0 1.0 0.0"/>
</joint>
<link name="left_wheel">
<visual>
<origin xyz="0 0 0" rpy="1.5707 0 0"/>
<geometry>
<cylinder radius="0.033" length="0.017"/>
</geometry>
<material name="white">
<color rgba="1 1 1 0.9 "/>
</material>
</visual>
</link>
<joint name="right_motor_joint" type="fixed">
<origin xyz="-0.055 -0.075 0" rpy="0 0 0"/>
<parent link="base_link"/>
<child link="right_motor"/>
</joint>
<link name="right_motor">
<visual>
<origin xyz="0 0 0" rpy="1.5707 0 0"/>
<geometry>
<cylinder radius="0.02" length="0.08"/>
</geometry>
<material name="white">
<color rgba="0.75 0.75 0.75 1 "/>
</material>
</visual>
</link>
<joint name="right_wheel_joint" type="continuous">
<origin xyz="0 -0.0485 0" rpy="0 0 0"/>
<parent link="right_motor"/>
<child link="right_wheel"/>
<axis xyz="0 1 0"/>
</joint>
<link name="right_wheel">
<visual>
<origin xyz="0 0 0" rpy="1.5707 0 0"/>
<geometry>
<cylinder radius="0.033" length="0.017"/>
</geometry>
<material name="white">
<color rgba="1 1 1 0.9 "/>
</material>
</visual>
</link>
<joint name="front_castor_joint" type="fixed">
<origin xyz="0.1135 0 -0.0165" rpy="0 0 0"/>
<parent link="base_link"/>
<child link="front_castor"/>
<axis xyz="0 1 0"/>
</joint>
<link name="front_castor">
<visual>
<origin xyz="0 0 0" rpy="1.5707 0 0"/>
<geometry>
<sphere radius="0.0165"/>
</geometry>
<material name="black">
<color rgba="0 0 0 0.95"/>
</material>
</visual>
</link>
</robot>
3.检查urdf文件
sudo apt-get install liburdfdom-tools
check_urdf +urdf文件
4.launch文件编写
<?xml version="1.0"?>
<launch>
<param name="robot_description" textfile="$(find robot_description)/urdf/robot_chassis.urdf"/>
<param name="use_gui" value="true"/>
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher"/>
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher"/>
</launch>
5.启动launch文件并打开rviz。
点击ADD添加Robotmodel,fixedframe选择base_link即可看到模型。
然后点击File,保存现在的rviz配置文件。存入功能包目录下的config文件夹,保存为myrobot.rviz。
另外,在我们启动launch文件时,会有以下警告:
这个不用着急。输入以下指令即可:
sudo apt-get install ros-melodic-joint-state-publisher-gui
然后对launch文件进行更改。
<?xml version="1.0"?>
<launch>
<param name="robot_description" textfile="$(find robot_description)/urdf/robot_chassis.urdf"/>
<param name="use_gui" value="true"/>
<node name="joint_state_publisher_gui" pkg="joint_state_publisher_gui" type="joint_state_publisher_gui"/>
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"/>
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find robot_description)/config/myrobot.rviz" required="true"/>
</launch>
就不会出现警告了,到此,完成。