gazebo simulation

The premise is that ros has been installed

URDF robot modeling

Create feature pack

#进入工作空间
cd ~/catkin_ws/src/
#创建功能包
catkin_create_pkg mbot_description urdf xacro

Create the required files in the function package directory

#进入功能包目录
cd ./catkin_ws/src/mbot_description
#存放机器人模型的URDF或xacro文件
mkdir urdf
#放置URDF中引用的模型渲染文件,机器人外观纹理
mkdir meshes
#保存相关启动文件
mkdir launch
#保存rviz的配置文件、功能包的配置文件
mkdir config

Edit the launch file

cd ~/catkin_ws/src/mbot_description/launch
sudo gedit display_mbot_base_urdf.launch

document content

<launch>
   <!-- 加载的参数名字叫robot_description,具体内容是urdf相关模型的路径 -->
	<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可视化界面,保存每次打开之后的相关插件,保存到config文件夹下面 -->
	<node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_urdf.rviz" required="true" />
</launch>

Create urdf model
Create trolley chassis

cd ~/catkin_ws/src/mbot_description/urdf
sudo gedit mbot_base.urdf

document content

<?xml version="1.0" ?>
<robot name="mbot">
    <link name="base_link">
        <visual>
            <origin xyz=" 0 0 0" rpy="0 0 0" />
            <!-- link坐标位置,放在最中央 ,xyz单位是米,rpy单位是弧度-->
            <geometry>
                <cylinder length="0.16" radius="0.20"/>
            </geometry>
            <!-- 机器人的外观效果,使用圆柱体,高0.16,半径0.20 -->
            <material name="yellow">
                <color rgba="1 0.4 0 1"/>
            </material>
             <!--  通过rgba来描述颜色,颜色命名为yellow,a为1是不透明-->
        </visual>
        <!--visual指的是一些物理属性的标签 -->
    </link>
</robot>

display effect

roslaunch mbot_description display_mbot_base_urdf.launch

Encounter problems

Insert picture description here

Solution
Note: I ubantu18.04, using melodic, if other versions modify the corresponding ros version

 sudo apt-get install ros-melodic-joint-state-publisher-gui

Then launch the file joint_state_publisherby joint_state_publisher_guireplacing all

Problem The
model is not displayed after opening rviz.
Solution
Click add to add RobotModel, and change the option behind Fixed Frame to base_link to
Insert picture description here
create the left wheel
. Add to the above file

sudo gedit mbot_base.urdf

    <joint name="left_wheel_joint" type="continuous">
    <!--   joint名字为left_wheel_joint,属性为continuous,即无限旋转-->
        <origin xyz="0 0.19 -0.05" rpy="0 0 0"/>
        <!--  坐标位置,在base_link基础上,Y偏移0.19,z偏移-0.05-->
        <parent link="base_link"/>
        <child link="left_wheel_link"/>
        <!--  主关节:base_link,上面的圆柱形车体-->
        <!--  子关节:left_wheel_link,左轮-->
        <!--  主关节最后是一个,本代码是base_link-->
        <axis xyz="0 1 0"/>
        <!--left_wheel_link绕某一个轴做旋转,指定为Y轴  -->
    </joint>
     <!--joint用来连接两个link-->
    <link name="left_wheel_link">
        <visual>
            <origin xyz="0 0 0" rpy="1.5707 0 0" />
            <geometry>
                <cylinder radius="0.06" length = "0.025"/>
            </geometry>
            <material name="white">
                <color rgba="1 1 1 0.9"/>
            </material>
        </visual>
    </link>
  <!--左轮信息-->

Right wheel

    <joint name="right_wheel_joint" type="continuous">
        <origin xyz="0 -0.19 -0.05" rpy="0 0 0"/>
        <!--  坐标位置,在base_link基础上,Y偏移-0.19,z偏移-0.05,与左轮正好相反-->
        <parent link="base_link"/>
        <child link="right_wheel_link"/>
        <axis xyz="0 1 0"/>
    </joint>
    <link name="right_wheel_link">
        <visual>
            <origin xyz="0 0 0" rpy="1.5707 0 0" />
            <geometry>
                <cylinder radius="0.06" length = "0.025"/>
            </geometry>
            <material name="white">
                <color rgba="1 1 1 0.9"/>
            </material>
        </visual>
    </link>

Front and rear support wheels

    <joint name="front_caster_joint" type="continuous">
        <origin xyz="0.18 0 -0.095" rpy="0 0 0"/>
        <parent link="base_link"/>
        <child link="front_caster_link"/>
        <axis xyz="0 1 0"/>
    </joint>

    <link name="front_caster_link">
        <visual>
            <origin xyz="0 0 0" rpy="0 0 0"/>
            <geometry>
                <sphere radius="0.015" />
                  <!--用圆形轮子代替  -->
            </geometry>
            <material name="black">
                <color rgba="0 0 0 0.95"/>
            </material>
        </visual>
    </link>

    <joint name="back_caster_joint" type="continuous">
        <origin xyz="-0.18 0 -0.095" rpy="0 0 0"/>
        <parent link="base_link"/>
        <child link="back_caster_link"/>
        <axis xyz="0 1 0"/>
    </joint>

    <link name="back_caster_link">
        <visual>
            <origin xyz="0 0 0" rpy="0 0 0"/>
            <geometry>
                <sphere radius="0.015" />
            </geometry>
            <material name="black">
                <color rgba="0 0 0 0.95"/>
            </material>
        </visual>
    </link>


Check the display

roslaunch mbot_description display_mbot_base_urdf.launch

Insert picture description here

Add sensor

Add camera

cd ~/catkin_ws/src/mbot_description/urdf
sudo gedit mbot_base.urdf

mbot_with_camera.urdf

 <joint name="camera_joint" type="fixed">
        <origin xyz="0.17 0 0.10" rpy="0 0 0"/>
        <parent link="base_link"/>
        <child link="camera_link"/>
    </joint>
 <link name="camera_link">
        <visual>
            <origin xyz=" 0 0 0 " rpy="0 0 0" />
            <geometry>
            
                <box size="0.03 0.04 0.04" />
                   <!--外观是个盒子模拟成摄像头,长宽高分别是0.03 0.04 0.04-->
            </geometry>
            <material name="black">
                <color rgba="0 0 0 0.95"/>
            </material>
        </visual>
    </link>

display effect

roslaunch mbot_description display_mbot_base_urdf.launch

Insert picture description here
Join Lidar

cd ~/catkin_ws/src/mbot_description/urdf
sudo gedit mbot_base.urdf

Add to

    <!--激光雷达配置内容-->
 <joint name="laser_joint" type="fixed">
        <origin xyz="0 0 0.105" rpy="0 0 0"/>
        <parent link="base_link"/>
        <child link="laser_link"/>
    </joint>
    <link name="laser_link">
		<visual>
			<origin xyz=" 0 0 0 " rpy="0 0 0" />
			<geometry>
				<cylinder length="0.05" radius="0.05"/>
			</geometry>
			<material name="black"/>
		</visual>
    </link>

Join Kinect

cd ~/catkin_ws/src/mbot_description/urdf
sudo gedit mbot_base.urdf

content

    <!--Kinect配置-->
        <joint name="laser_joint" type="fixed">
        <origin xyz="0.15 0 0.11" rpy="0 0 0"/>
        <parent link="base_link"/>
        <child link="kinect_link"/>
    </joint>
    <link name="kinect_link">
        <visual>
            <origin xyz="0 0 0" rpy="0 0 1.5708"/>
            <geometry>
                <mesh filename="package://mbot_description/meshes/kinect.dae" />
                 <!--直接加载Kinect的外观纹理描述文件-->
            </geometry>
        </visual>
    </link>

Note: Adding code in this way may cause errors, overlaps and other errors. It is best to delete the code part of the previous sensor when adding another sensor after adding another sensor. It should have better results.


Execute urdf_to_graphiz+urdf file to be checked under the model check urdf folder

urdf_to_graphiz mbot_base.urdf

effect
Insert picture description here

Guess you like

Origin blog.csdn.net/xianyudewo/article/details/115033699