ROS URDF adds sensor model
Add sensor model
Add camera
The corresponding model file is camera.xacro, which reads as follows
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="camera">
<xacro:macro name="usb_camera" params="prefix:=camera">
<link name="${prefix}_link">
<inertial>
<mass value="0.1" />
<origin xyz="0 0 0" />
<inertia ixx="0.01" ixy="0.0" ixz="0.0"
iyy="0.01" iyz="0.0"
izz="0.01" />
</inertial>
<visual>
<origin xyz=" 0 0 0 " rpy="0 0 0" />
<geometry>
<box size="0.01 0.04 0.04" />
</geometry>
<material name="black"/>
</visual>
<collision>
<origin xyz="0.0 0.0 0.0" rpy="0 0 0" />
<geometry>
<box size="0.01 0.04 0.04" />
</geometry>
</collision>
</link>
</xacro:macro>
</robot>
The above code USES a macro called USB_camera to describe the camera, and the input parameter is the name of the camera.
Create a top-level XACro file that splicing together the robot and camera modules. The contents of the top-level file mrobot_with_camera.urdf.xacro are as follows, where the contents of the robot ontology description file mrobot_body.urdf.xacro can be found in the previous blog.
<?xml version="1.0"?>
<robot name="mrobot" xmlns:xacro="http://www.ros.org/wiki/xacro">
<xacro:include filename="$(find mrobot_description)/urdf/mrobot_body.urdf.xacro" />
<xacro:include filename="$(find mrobot_description)/urdf/camera.xacro" />
<xacro:property name="camera_offset_x" value="0.1" />
<xacro:property name="camera_offset_y" value="0" />
<xacro:property name="camera_offset_z" value="0.02" />
<!-- MRobot Robotics Platform-->
<mrobot_body/>
<!-- Camera -->
<joint name="camera_joint" type="fixed">
<origin xyz="${camera_offset_x} ${camera_offset_y} ${camera_offset_z}" rpy="0 0 0" />
<parent link="plate_2_link"/>
<child link="camera_link"/>
</joint>
<xacro:usb_camera prefix="camera"/>
</robot>
Display the model in RVIz, as shown in the figure below
roslaunch mrobot_description display_mrobot_with_camera_xacro.launch
Add it
Kinect is a commonly used RGB-D camera, and the XACro file is shown below
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="kinect_camera">
<xacro:macro name="kinect_camera" params="prefix:=camera">
<link name="${prefix}_link">
<origin xyz="0 0 0" rpy="0 0 0"/>
<visual>
<origin xyz="0 0 0" rpy="0 0 ${M_PI/2}"/>
<geometry>
<mesh filename="package://mrobot_description/meshes/kinect.dae" />
</geometry>
</visual>
<collision>
<geometry>
<box size="0.07 0.3 0.09"/>
</geometry>
</collision>
</link>
<joint name="${prefix}_optical_joint" type="fixed">
<origin xyz="0 0 0" rpy="-1.5708 0 -1.5708"/>
<parent link="${prefix}_link"/>
<child link="${prefix}_frame_optical"/>
</joint>
<link name="${prefix}_frame_optical"/>
</xacro:macro>
</robot>
You can import the mesh file of the model by setting the label in visualization. And then the Kinect and the robot were put together. The top-level Xacro file, mrobot_with_kinet.urdf.xacro, has the following contents
<?xml version="1.0"?>
<robot name="mrobot" xmlns:xacro="http://www.ros.org/wiki/xacro">
<xacro:include filename="$(find mrobot_description)/urdf/mrobot_body.urdf.xacro" />
<xacro:include filename="$(find mrobot_description)/urdf/kinect.xacro" />
<xacro:property name="kinect_offset_x" value="-0.06" />
<xacro:property name="kinect_offset_y" value="0" />
<xacro:property name="kinect_offset_z" value="0.035" />
<!-- MRobot Robotics Platform-->
<mrobot_body/>
<!-- Kinect -->
<joint name="kinect_frame_joint" type="fixed">
<origin xyz="${kinect_offset_x} ${kinect_offset_y} ${kinect_offset_z}" rpy="0 0 0" />
<parent link="plate_2_link"/>
<child link="camera_link"/>
</joint>
<xacro:kinect_camera prefix="camera"/>
</robot>
The results displayed in RVIz are shown below
other sensors can be modeled in a similar way.
Read More:
- Error: error from slirp4netns while setting up port redirection: map[desc:bad request: add_hostfwd:
- Linux: How to Fix undefined reference to `itoa’
- [Solved] Cmake: symbol lookup error: cmake: undefined symbol: archive_write_add_filter_zstd
- How to Solve labelme Install Error in Ubuntu
- How to Solve Ubuntu “Failed to fetch” Error
- How to Export All data in DataGridView to Local Excel
- How to fix the ERROR: Failed to build gem native extension in Centos 8
- How to Solve Error: “Hdaudio hdaudioc0d2: unable to bind codec”
- How to Use Apt get Command Under Mac OSX
- How to Solve Error vim :call CompileRunGcc()
- How to Create Threads in Linux
- C# WPF Framework: How to Build Caliburn.Micro Quickly
- C#: How to Use Itextsharp to Manipulate PDF Files
- How to Use Annotations in Flutter & Dart
- How to set fixed IP address for Raspberry Pie
- Latex: How to enter an underline
- How to Solve C++ Error: “no matching function for call to ‘atoi/atof’”
- How to Solve NPM Error 426 Upgrade Required
- Android: How to Start App Automatically
- How to Solve A-LOAM Ceres Version Error