Robot Modeling and Simulation (2)——Robot URDF Model Simulation

Robot Modeling and Simulation (2)——Robot URDF Model Simulation

Overview

In ROS, the robot model is generally placed under the RobotName_description function package.

1. Create a robot description function package

catkin_create_pkg mbot_description urdf xacro

The robot model and description file are in ROS, usually with the robot name _description, and need to rely on the urdf function package, analytical model and xacro (used to optimize urdf) ​​dependencies.
Create several folders with different functions under the RobotName_description function package, including four folders: urdf, meshes, launch and config.

  • urdf: store the URDF or xacro file of the robot model
  • meshes: place the model rendering files referenced in the URDF, the robot appearance texture, make the appearance more similar to the reality, export it through the 3D design software, and place it in this folder
  • launch: save related startup files
  • config: save the configuration file of rviz, the configuration file of the function package

Second, create a URDF model

After understanding the commonly used tags and syntax in the URDF model, use these basic syntax to create a robot chassis model.
This robot chassis model has 7 links and 6 joints. The 7 links include 1 robot base plate, 2 motors, 2 drive wheels and 2 universal wheels; 6 joints are responsible for installing the drive wheels, universal wheels, and motors on the base plate, and set the corresponding connection methods.

<?xml version="1.0" ?>
<robot name="mrobot_chassis">

    //robot name 标签用于定义所描述机器人的名称

    <link name="base_link">  
        <visual>  //
            <origin xyz=" 0.1 0.1 0.1" rpy="0 0 0" />                                 
            <geometry>
                <cylinder length="0.005" radius="0.13"/>
            </geometry>
            <material name="yellow">  
                <color rgba="1 0.4 0 1"/>
            </material>
        </visual>
    </link>

    //link标签描述了机器人某个刚体部分的外观和物理属性,包括尺寸,颜色,形状惯性和碰撞参数等,visual...../visual 标签描述机器人某个部件的外观参数等。origin 标签描述了所绘制外观geometry的坐标起点,一般对于规则形状的外观坐标起点位于规则形状的重心位置, cylinder 标签描述了这个圆柱体的尺寸,material 标签用于描述外观的颜色等信息

    <joint name="base_left_motor_joint" type="fixed"> //joint...../joint标签用于描述机器人关节的运动学和动力属性
        <origin xyz="0.1 0.1 0.1" rpy="0 0 0" />        
        <parent link="base_link"/>
        <child link="left_motor" />
    </joint>

   //上述joint...../joint标签中一般描述origin parent child等参数,origin描述了joint连接点基于parent link="base_link"
     坐标的偏移量,一般在rviz仿真中左上角Fixed Frame 的map选项设置成base_link,则base_link在rviz中为坐标原点,那么        origin所描述的joint为基于坐标原点的偏移量,parent为jiont的支撑连接部件,child为子部件,joint就为子部件和支撑连接部件     的关节

    <link name="left_motor">
        <visual>
            <origin xyz="0.2 0.2 0.2" rpy="0 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>
   //link name="left_motor"标签为base_left_motor_joint连接件的子部件,其中origin描述了该部件基于base_left_motor_joint关节
     坐标的偏移点,base_left_motor_joint关节的坐标原点为origin xyz="0.1 0.1 0.1",若left_motor部件的origin xyz="0.2 0.2 0.2"
     则表示left_motor所描述部件基于base_left_motor_joint关节坐标xyz="0.1 0.1 0.1"的偏移量为xyz="0.2 0.2 0.2"

    <joint name="left_wheel_joint" type="continuous">
        <origin xyz="0.5 0.0485 0" rpy="0 0 0"/>
        <parent link="left_motor"/>
        <child link="left_wheel_link"/>
        <axis xyz="0 1 0"/>
    </joint>

   //连接关节joint name="left_wheel_joint" 为left_motor和left_wheel_link关节点,left_wheel_link为left_motor的子部件,其中
     left_wheel_joint的基础坐标是基于parent link="left_motor"的关节joint name="base_left_motor_joint" 的基础坐标偏移量
     而非left_motor的origin偏移量

.......

..........

</robot>

URDF provides some command-line tools that can help us check and sort out model files, which need to be installed independently in the terminal:

sudo apt-get install liburdfdom-tools

Then use the check_urdf command to check the description of the robot file:

check_urdf #<机器人描述名称>.urdf

The check_urdf command will parse the URDF file and display the errors found during the parsing process. If everything is normal, there will be no error output in the terminal.
You can also use the urdf_to_graphiz command to view the overall structure of the URDF model:

urdf_to_graphiz #<机器人描述名称>.urdf

After executing the urdf_to_graphiz command, a pdf file will be generated in the current directory. Open the file and you can see the overall structure diagram of the model.

Three, URDF model analysis

Four, display the model in rviz

After completing the design of the URDF model, you can use rviz to visualize the model to check whether it meets the design goals.
Edit the launch file

<launch>
    <!-- param是要加载ros的一个参数:robot_description (描述机器人的具体模型)-->
	<param name="robot_description" textfile="$(find mbot_description)/urdf/mbot_base.urdf" />

	<!-- 设置GUI参数,显示关节控制插件 -->
	<param name="use_gui" value="true"/>
	
	<!-- 运行joint_state_publisher节点,发布机器人的关节状态  -->
	<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
	
	<!-- 运行robot_state_publisher节点,发布tf  -->
	<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
	
	<!-- 运行rviz可视化界面 -->
	<node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_urdf.rviz" required="true" />
</launch>
  • joint_state_publisher: publish the state of each joint (except the fixed type), and the joint can be controlled through the UI interface
  • robot_state_publisher: Organize the relationship between the links and joints of the robot into a three-dimensional posture information release in the form of TF.
    Open the terminal and run the launch file. If everything is normal, you can see the robot model in the opened rviz.

Five, improve the URDF model

1. Add physical and collision attributes
2. Use xacro to optimize URDF
(1) Use constant definitions
(2) Call mathematical formulas
(3) Use macro definitions
3. Xacro file references
4. Display optimized models
(1) Convert xacro files To URDF file
(2) directly call xacro file parser

Six, add sensor model

1. Add camera
2. Add Kinect
3. Add lidar

7. Emulator based on ArbotiX and rviz

1. Install ArbotiX
2. Configure ArbotiX controller
<1> Create launch file
<2> Create configuration file
3. Run simulation environment

Guess you like

Origin blog.csdn.net/weixin_45661757/article/details/113250487