前面我們使用的是已有的機器人模型進行模擬,這一節我們將建立一個簡單的智能車機器人smartcar,為後面建立複雜機器人打下基礎。
一、建立硬體描述包
roscreat-pkg smartcar_description urdf
二、智能車尺寸資料 因為建立的是一個非常簡單的機器人,所以我們盡量使用簡單的元素:使用長方體代替車模,使用圓柱代替車輪,具體尺寸如下:
三、建立urdf檔案 在smartcar_description檔案夾下建立urdf檔案夾,建立智能車的描述檔案smartcar.urdf,描述代碼如下:
<?xml version="1.0"?><robot name="smartcar"> <link name="base_link"> <visual> <geometry> <box size="0.25 .16 .05"/></geometry><origin rpy="0 0 1.57075" xyz="0 0 0"/> <material name="blue"><color rgba="0 0 .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"> <axis xyz="0 0 1"/> <parent link="base_link"/> <child link="right_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="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"/> <origin xyz="0 0.08 0.025"/> </joint></robot>
四、建立launch命令檔案 在smartcar_description檔案夾下建立launch檔案夾,建立智能車的描述檔案 base.urdf.rviz.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.vcg" /></launch>
五、效果示範 在終端中輸入顯示命令:
roslaunch smartcar_description base.urdf.rviz.launch gui:=true
顯示效果如所示,使用gui中的控制bar可以控制四個輪子單獨旋轉。
----------------------------------------------------------------
歡迎大家轉載我的文章。
轉載請註明:轉自古-月
http://blog.csdn.net/hcx25909
歡迎繼續關注我的部落格