rviz显示urdf文件

环境配置

在安装完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

玩得开心!

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是在ROS中使用RViz打开urdf文件模型的具体详细步骤: 1. 首先,确保你已经安装了ROS和RViz,并且已经成功创建了一个ROS工作空间。 2. 在你的ROS工作空间中创建一个新的包,用于存放你的URDF文件RViz配置文件。可以使用以下命令创建一个新的包: ``` catkin_create_pkg my_robot_description urdf rviz ``` 3. 在urdf文件夹中创建一个新的URDF文件,命名为my_robot.urdf,将你的机器人模型描述放在这个文件中。 4. 编写一个launch文件,用于启动RViz并加载你的机器人模型。创建一个名为my_robot_rviz.launch的文件,并将以下内容复制粘贴到文件中: ``` <launch> <!-- Start RViz --> <node name="rviz" pkg="rviz" type="rviz" args="-d $(find my_robot_description)/rviz/my_robot.rviz"/> <!-- Load URDF into parameter server --> <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find my_robot_description)/urdf/my_robot.urdf'"/> <!-- Start robot_state_publisher --> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"/> </launch> ``` 5. 在rviz文件夹中创建一个名为my_robot.rvizRViz配置文件,用于配置RViz显示。在这个文件中,你可以设置机器人的颜色、材质、关节控制器等信息。 6. 打开一个终端窗口,运行以下命令启动RViz: ``` roslaunch my_robot_description my_robot_rviz.launch ``` 7. RViz将启动并加载你的机器人模型。你可以通过拖动、缩放、旋转等方式来查看和操作机器人模型。 希望这些步骤能够帮助你成功地在RViz中打开你的URDF文件模型!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值