Result of building and launching a robot by a SDF (Simulation description format) file for a simple differential drive robot
SDF (Simulation Description Format) is a file format for simulators, like Gazebo, that describes the simulator environment, models (including its links, connections, and physics simulator metadata), and appropriate plugins.
[sudo apt install ros-<ros2-distro>-sdformat-urdf] . I am using Ros Jazzy so the ros-distro here is jazzy. The correct statement is [sudo apt install ros-jazzy-sdformat-urdf]
Default model path to a URDF (Unified Robot Description Format) file
A create new SDF (Simulation Description Format) file at src\description with it's contain look like
<?xml version="1.0" ?>
<sdf version="1.8" xmlns:xacro="http://ros.org/wiki/xacro">
<model name='thomas_bot' canonical_link='base_link'>
<!-- Define robot constants -->
<xacro:property name="base_width" value="0.31"/>
<xacro:property name="base_length" value="0.42"/>
<xacro:property name="base_height" value="0.18"/>
<xacro:property name="wheel_radius" value="0.10"/>
<xacro:property name="wheel_width" value="0.04"/>
<xacro:property name="wheel_ygap" value="0.025"/>
<xacro:property name="wheel_zoff" value="0.05"/>
<xacro:property name="wheel_xoff" value="0.12"/>
<xacro:property name="caster_xoff" value="0.14"/>
<!-- Define some commonly used inertial properties -->
<xacro:macro name="box_inertia" params="m w h d">
<inertial>
<pose>0 0 0 ${pi/2} 0 ${pi/2}</pose>
<mass>${m}</mass>
<inertia>
<ixx>${(m/12) * (h*h + d*d)}</ixx>
<ixy>0.0</ixy>
<ixz>0.0</ixz>
<iyy>${(m/12) * (w*w + d*d)}</iyy>
<iyz>0.0</iyz>
<izz>${(m/12) * (w*w + h*h)}</izz>
</inertia>
</inertial>
</xacro:macro>
<xacro:macro name="cylinder_inertia" params="m r h">
<inertial>
<pose>0 0 0 ${pi/2} 0 0</pose>
<mass>${m}</mass>
<inertia>
<ixx>${(m/12) * (3*r*r + h*h)}</ixx>
<ixy>0.0</ixy>
<ixz>0.0</ixz>
<iyy>${(m/12) * (3*r*r + h*h)}</iyy>
<iyz>0.0</iyz>
<izz>${(m/2) * (r*r)}</izz>
</inertia>
</inertial>
</xacro:macro>
<xacro:macro name="sphere_inertia" params="m r">
<inertial>
<mass>${m}</mass>
<inertia>
<ixx>${(2/5) * m * (r*r)}</ixx>
<ixy>0.0</ixy>
<ixz>0.0</ixz>
<iyy>${(2/5) * m * (r*r)}</iyy>
<iyz>0.0</iyz>
<izz>${(2/5) * m * (r*r)}</izz>
</inertia>
</inertial>
</xacro:macro>
<!-- Robot Base -->
<link name='base_link'>
<must_be_base_link>true</must_be_base_link>
<visual name="base_link_visual">
<geometry>
<box><size>
${base_length} ${base_width} ${base_height}
</size></box>
</geometry>
<material>
<ambient>0 1 1 1</ambient>
<diffuse>0 1 1 1</diffuse>
</material>
</visual>
<collision name="base_link_collision">
<geometry>
<box><size>
${base_length} ${base_width} ${base_height}
</size></box>
</geometry>
</collision>
</link>
<!-- Robot Footprint -->
<link name='base_footprint'>
<pose relative_to="base_joint"/>
<xacro:box_inertia m="15" w="${base_width}" d="${base_length}" h="${base_height}"/>
</link>
<joint name='base_joint' type='fixed'>
<parent>base_link</parent>
<child>base_footprint</child>
<pose relative_to="base_link">0.0 0.0 ${-(wheel_radius+wheel_zoff)} 0 0 0</pose>
</joint>
<!-- Wheels -->
<xacro:macro name="wheel" params="prefix x_reflect y_reflect">
<link name="${prefix}_link">
<pose relative_to="${prefix}_joint"/>
<visual name="${prefix}_link_visual">
<pose relative_to="${prefix}_link">0 0 0 ${pi/2} 0 0</pose>
<geometry>
<cylinder>
<radius>${wheel_radius}</radius>
<length>${wheel_width}</length>
</cylinder>
</geometry>
<material>
<ambient>0.3 0.3 0.3 1.0</ambient>
<diffuse>0.7 0.7 0.7 1.0</diffuse>
</material>
</visual>
<collision name="${prefix}_link_collision">
<pose relative_to="${prefix}_link">0 0 0 ${pi/2} 0 0</pose>
<geometry>
<cylinder>
<radius>${wheel_radius}</radius>
<length>${wheel_width}</length>
</cylinder>
</geometry>
</collision>
<xacro:cylinder_inertia m="0.5" r="${wheel_radius}" h="${wheel_width}"/>
</link>
<joint name="${prefix}_joint" type="revolute">
<parent>base_link</parent>
<child>${prefix}_link</child>
<pose relative_to="base_link">${x_reflect*wheel_xoff} ${y_reflect*(base_width/2+wheel_ygap)} ${-wheel_zoff} 0 0 0</pose>
<axis>
<xyz>0 1 0</xyz>
<limit>
<lower>-inf</lower>
<upper>inf</upper>
</limit>
</axis>
</joint>
</xacro:macro>
<xacro:wheel prefix="drivewhl_l" x_reflect="-1" y_reflect="1" />
<xacro:wheel prefix="drivewhl_r" x_reflect="-1" y_reflect="-1" />
<link name="front_caster">
<pose relative_to="caster_joint"/>
<visual name="front_caster_visual">
<geometry>
<sphere>
<radius>${(wheel_radius+wheel_zoff-(base_height/2))}</radius>
</sphere>
</geometry>
<material>
<ambient>0 1 1 1</ambient>
<diffuse>0 1 1 1</diffuse>
</material>
</visual>
<collision name="front_caster_collision">
<geometry>
<sphere>
<radius>${(wheel_radius+wheel_zoff-(base_height/2))}</radius>
</sphere>
</geometry>
</collision>
<xacro:sphere_inertia m="0.5" r="${(wheel_radius+wheel_zoff-(base_height/2))}"/>
</link>
<joint name="caster_joint" type="fixed">
<parent>base_link</parent>
<child>front_caster</child>
<pose relative_to="base_link">${caster_xoff} 0.0 ${-(base_height/2)} 0 0 0</pose>
</joint>
</model>
</sdf>
Use thomas_bot_description sdf file as a default model path
default_model_path = os.path.join(pkg_share, 'src', 'description', 'thomas_bot_description.sdf')
Clip - Build and launch robot by the SDF (Simulation Description Format) file
Generative AI, Robot Operating System (ROS 2), Computer Vision, Natural Language Processing service, Generative AI Chatbot, Machine Learning, Mobile App, Web App? Yes, I do provide!
Call me: (+84) 0854147015
WhatsApp: +601151992689
Viber: +84854147015https://amatasiam.web.app
Email: ThomasTrungVo@Gmail.Com
Facebook: https://www.facebook.com/voduytrung
X: https://x.com/ThomasTrung
No comments:
Post a Comment