环境配置

在安装完ROS后,便可以进行以下操作了。若操作不成功,欢迎留言,共同讨论。

  • 工作区创建

    #为方便区分 将catkin_ws文件夹称为工作区
    #将src文件夹称为工作空间
    #工作空间下又有功能包
    #以上是我自己瞎叫的 对不对就不知道了 反正照这个语句运行最终能实现将urdf显示到rviz
    
    mkdir ~/catkin_ws/src  #同时创建工作区目标catkin_ws和工作空间目录src
    cd ~/catkin_ws/src
    catkin_init_workspace #初始化工作空间src
    catkin_create_pkg robot_function_pkg urdf xacro #在src目录下创建功能包robot_function_pkg并导入依赖项urdf xacro
    cd ~/catkin_ws       #切换到工作区目录下
    catkin_make          #编译工作区
    echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc  #将工作空间启动加入到ubuntu的启动文件
    cd ~/catkin_ws/src/robot_function_pkg #切换到功能包内
    mkdir -p urdf/urdf urdf/xacro config launch meshes #创建urdf config launch meshes文件夹 其中urdf下又创建了urdf和xacro文件夹
    
  • 创建urdf文件

    cd ~/catkin_ws/src/robot_function_pkg/urdf/urdf
    sudo gedit test_robot.urdf
    

    将以下代码复制粘贴到test_robot.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文件

    cd ~/catkin_ws/src/robot_function_pkg/launch
    sudo gedit test_robot.launch
    

    将以下代码复制粘贴到test_robot.launch文件

    <launch>
        <arg name="model" />
        <arg name="gui" default="False" />
        <param name="robot_description" textfile="$(find robot_function_pkg)/urdf/urdf/test_robot.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="robot_state_publisher" />
    </launch>
    
  • 新建一个终端运行launch文件

    roslaunch robot_function_pkg test_robot.launch

  • 再新建一个终端运行以下语句

    rviz

玩得开心!


版权声明:本文为qq_34775654原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_34775654/article/details/119673857