其他分享
首页 > 其他分享> > ROS小车打造(十)--模型urdf与xacro的搭建

ROS小车打造(十)--模型urdf与xacro的搭建

作者:互联网

 

 

 

1 创建机器人描述功能包

cd ~/catkin_ws/src/
catkin_create_pkg SMCar_description urdf xacro
cd SMCar_description/
mkdir urdf launch config

2.编写urdf并编译包

先编写smcar.urdf 与 display_smcar_urdf.launch,结构如下图

smcar.urdf 代码如下

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

    <link name="base_link">
        <visual>
            <origin xyz=" 0 0 0" rpy="0 0 0" />
            <geometry>
                <box size="0.5 0.3 0.2"/>
            </geometry>
            <material name="black">
                <color rgba="0 0 0 1"/>
            </material>
        </visual>
    </link>

    <joint name="left_wheel_joint" type="continuous">
        <origin xyz="-0.15 0.14 -0.1" rpy="0 0 0"/>
        <parent link="base_link"/>
        <child link="left_wheel_link"/>
        <axis xyz="0 1 0"/>
    </joint>

    <link name="left_wheel_link">
        <visual>
            <origin xyz="0 0 0" rpy="1.5707 0 0" />
            <geometry>
                <cylinder radius="0.08" length = "0.05"/>
            </geometry>
            <material name="white">
                <color rgba="1 1 1 0.9"/>
            </material>
        </visual>
    </link>

    <joint name="right_wheel_joint" type="continuous">
        <origin xyz="-0.15 -0.14 -0.1" rpy="0 0 0"/>
        <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.08" length = "0.05"/>
            </geometry>
            <material name="white">
                <color rgba="1 1 1 0.9"/>
            </material>
        </visual>
    </link>

    <joint name="front_left_joint" type="continuous">
        <origin xyz="0.18 0.14 -0.14" rpy="0 0 0"/>
        <parent link="base_link"/>
        <child link="front_left_link"/>
        <axis xyz="0 1 0"/>
    </joint>

    <link name="front_left_link">
        <visual>
            <origin xyz="0 0 0" rpy="0 0 0"/>
            <geometry>
                <sphere radius="0.04" />
            </geometry>
            <material name="white">
                <color rgba="1 1 1 0.95"/>
            </material>
        </visual>
    </link>

    <joint name="front_right_joint" type="continuous">
        <origin xyz="0.18 -0.14 -0.14" rpy="0 0 0"/>
        <parent link="base_link"/>
        <child link="front_right_link"/>
        <axis xyz="0 1 0"/>
    </joint>

    <link name="front_right_link">
        <visual>
            <origin xyz="0 0 0" rpy="0 0 0"/>
            <geometry>
                <sphere radius="0.04" />
            </geometry>
            <material name="white">
                <color rgba="1 1 1 0.95"/>
            </material>
        </visual>
    </link>

</robot>

display_smcar_urdf.launch代码如下:

<launch>
	<param name="robot_description" textfile="$(find SMCar_description)/urdf/smcar.urdf" />

	<!-- 设置GUI参数,显示关节控制插件 -->
	<param name="use_gui" value="true"/>
	
	<!-- 运行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 SMCar_description)/config/smcar.rviz" required="true" /> -->
</launch>

安装依赖并编译

sudo apt-get install ros-kinetic-joint-state-publisher-gui
cd ~/catkin_ws/
catkin_make

3.运行launch,保存rviz配置文件

roscore
roslaunch SMCar_description display_smcar_urdf.launch
rosrun rviz rviz

点Add RobotModel

 Fixed Frame选base_link

 

 保存rviz配置文件到包的config文件夹

 4.修改launch文件,重新运行

去掉注释

 

 

标签:smcar,xacro,rviz,launch,--,urdf,SMCar,catkin,ROS
来源: https://blog.csdn.net/leoFY123/article/details/122668933