1. 创建功能包
catkin_create_pkg marm_description urdf xacro
2. 增加launch启动文件
<launch>
<!-- 设置机器人模型路径参数 -->
<param name="robot_description" textfile="$(find marm_description)/urdf/marm.urdf" />
<!-- 运行joint_state_publisher节点,发布机器人的关节状态 -->
<node name="joint_state_publisher_gui" pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" />
<!-- 运行robot_state_publisher节点,发布tf -->
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />
<!-- 运行rviz可视化界面 -->
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find marm_description)/config/marm_urdf.rviz" required="true" />
</launch>
3. 编写urdf文件
<?xml version="1.0" ?>
<robot name="marm">
<!-- 颜色 -->
<material name="Black">
<color rgba="0 0 0 1"/>
</material>
<material name="White">
<color rgba="1 1 1 1"/>
</material>
<material name="Blue">
<color rgba="0 0 1 1"/>
</material>
<material name="Red">
<color rgba="1 0 0 1"/>
</material>
<!-- base_link -->
<link name="base_link">
<visual>
<origin rpy="0 0 0" xyz="0 0 0"/>
<geometry>
<cylinder length="0.04" radius="0.05"/>
</geometry>
<material name="White"/>
</visual>
</link>
<!-- Link1 -->
<link name="link1">
<visual>
<origin rpy="0 0 0" xyz="0 0 0.05"/>
<geometry>
<cylinder length="0.1" radius="0.03"/>
</geometry>
<material name="Blue"/>
</visual>
</link>
<joint name="joint1" type="revolute"> <!-- 有上下限位的旋转关节 -->
<parent link="base_link"/>
<child link="link1"/>
<origin rpy="0 0 0" xyz="0 0 0.02"/>
<axis xyz="0 0 1"/>
<limit effort="300" lower="-3.14159" upper="3.14159" velocity="1"/> <!-- 力矩、下位、上位、速度 -->
</joint>
<!-- Link2 -->
<link name="link2">
<visual>
<origin rpy="0 0 0" xyz="0 0 0.07"/>
<geometry>
<cylinder length="0.14" radius="0.03"/>
</geometry>
<material name="White"/>
</visual>
</link>
<joint name="joint2" type="revolute">
<parent link="link1"/>
<child link="link2"/>
<origin rpy="0 0 0" xyz="0 0 0.1"/>
<axis xyz="0 1 0"/>
<limit effort="300" lower="-3.14159" upper="3.14159" velocity="1"/>
</joint>
<!-- Link3 -->
<link name="link3">
<visual>
<origin rpy="0 0 0" xyz="0 0 0.075"/>
<geometry>
<cylinder length="0.15" radius="0.03"/>
</geometry>
<material name="Blue"/>
</visual>
</link>
<joint name="joint3" type="revolute">
<parent link="link2"/>
<child link="link3"/>
<origin rpy="0 0 0" xyz="0 0 0.14"/>
<axis xyz="0 1 0"/>
<limit effort="300" lower="-3.14159" upper="3.14159" velocity="1"/>
</joint>
<!-- Link4 -->
<link name="link4">
<visual>
<origin rpy="0 0 0" xyz="0 0 0.03"/>
<geometry>
<cylinder length="0.06" radius="0.025"/>
</geometry>
<material name="Black"/>
</visual>
</link>
<joint name="joint4" type="revolute">
<parent link="link3"/>
<child link="link4"/>
<origin rpy="0 0 0" xyz="0 0 0.15"/>
<axis xyz="0 1 0"/>
<limit effort="300" lower="-3.14159" upper="3.14159" velocity="1"/>
</joint>
<!-- Link5 -->
<link name="link5">
<visual>
<origin rpy="0 0 0" xyz="0 0 0.03"/>
<geometry>
<cylinder length="0.06" radius="0.03"/>
</geometry>
<material name="White"/>
</visual>
</link>
<joint name="joint5" type="revolute">
<parent link="link4"/>
<child link="link5"/>
<origin rpy="0 0 0" xyz="0 0 0.06"/>
<axis xyz="0 1 0"/>
<limit effort="300" lower="-3.14159" upper="3.14159" velocity="1"/>
</joint>
<!-- Link6 -->
<link name="link6">
<visual>
<origin rpy="0 0 0" xyz="0 0 0.01"/>
<geometry>
<cylinder length="0.02" radius="0.04"/>
</geometry>
<material name="White"/>
</visual>
</link>
<joint name="joint6" type="revolute">
<parent link="link5"/>
<child link="link6"/>
<origin rpy="0 0 0" xyz="0 0 0.06"/>
<axis xyz="0 0 1"/>
<limit effort="300" lower="-3.14159" upper="3.14159" velocity="1"/>
</joint>
<!-- 夹爪 -->
<link name="gripper_finger_link1">
<visual>
<origin rpy="0 0 0" xyz="0 0 0.03"/>
<geometry>
<box size="0.03 0.01 0.06"/>
</geometry>
<material name="White"/>
</visual>
</link>
<link name="gripper_finger_link2">
<visual>
<origin rpy="0 0 0" xyz="0 0 0.03"/>
<geometry>
<box size="0.03 0.01 0.06"/>
</geometry>
<material name="White"/>
</visual>
</link>
<joint name="finger_joint1" type="prismatic">
<parent link="link6"/>
<child link="gripper_finger_link1"/>
<origin rpy="0 0 0" xyz="0 -0.03 0.02"/>
<axis xyz="0 1 0"/>
<limit effort="100" lower="0" upper="0.06" velocity="0.02"/>
</joint>
<joint name="finger_joint2" type="fixed">
<parent link="link6"/>
<child link="gripper_finger_link2"/>
<origin rpy="0 0 0" xyz="0 0.03 0.02"/>
</joint>
<!-- 法兰盘 -->
<link name="grasping_frame"/>
<joint name="grasping_frame_joint" type="fixed">
<parent link="link6"/>
<child link="grasping_frame"/>
<origin rpy="0 0 0" xyz="0.06 0 0"/>
</joint>
</robot>
4. 检查urdf文件的完整性
urdf_to_graphiz mbot.urdf
5. 仿真
roscore
source ./devel/setup.bash
roslaunch marm_description display_marm_urdf.launch
标签:仿真,文件,12,description,launch,marm,urdf,URDF
From: https://blog.csdn.net/m0_62236205/article/details/142437225