Skip to content

Commit f859b47

Browse files
docs(examples): flatten and enrich xacro examples with a modular diff-drive robot
- Flattened examples/xacro directory structure by removing redundant subfolders. - Added a comprehensive, modular diff_drive_robot.xacro example. - Fixed material tags in materials.xacro for standard compliance. - Updated examples README with accurate API usage and directory structure. - Verified xacro parsing via URDFParser.parse_xacro. Signed-off-by: arounamounchili <patouossa.mounchili@gmail.com>
1 parent 91bbd81 commit f859b47

4 files changed

Lines changed: 110 additions & 6 deletions

File tree

examples/README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ This directory contains example URDF and Xacro files to demonstrate the capabili
66

77
- **urdf/**: Standalone URDF XML models of various robots (mobile bases, quadrupeds).
88
- **xacro/**: Modular models using Xacro macros and property evaluation.
9-
- **macros/**: Reusable kinematic and inertial macros.
10-
- **imports/**: Shared materials and global properties.
9+
- `diff_drive_robot.xacro`: Main entry point for a modular mobile robot.
10+
- `inertials.xacro`: Reusable kinematic and inertial macros.
11+
- `materials.xacro`: Shared materials and global properties.
1112

1213
## Usage
1314

@@ -20,3 +21,17 @@ parser = URDFParser()
2021
robot = parser.parse("examples/urdf/diff_drive_robot.urdf")
2122
print(robot.summary())
2223
```
24+
25+
### Xacro Support
26+
27+
LinkForge also supports Xacro files by automatically evaluating macros and properties during parsing:
28+
29+
```python
30+
from pathlib import Path
31+
from linkforge_core.parsers.urdf_parser import URDFParser
32+
33+
parser = URDFParser()
34+
# Resolve Xacro then parse into a Robot model
35+
robot = parser.parse_xacro(Path("examples/xacro/diff_drive_robot.xacro"))
36+
print(robot.summary())
37+
```
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0"?>
2+
<robot name="diff_drive_robot" xmlns:xacro="http://www.ros.org/wiki/xacro">
3+
4+
<!-- Include modular components -->
5+
<xacro:include filename="materials.xacro" />
6+
<xacro:include filename="inertials.xacro" />
7+
8+
<!-- Properties -->
9+
<xacro:property name="chassis_length" value="0.5" />
10+
<xacro:property name="chassis_width" value="0.3" />
11+
<xacro:property name="chassis_height" value="0.15" />
12+
<xacro:property name="wheel_radius" value="0.1" />
13+
<xacro:property name="wheel_width" value="0.04" />
14+
<xacro:property name="wheel_ygap" value="0.01" />
15+
<xacro:property name="wheel_zoff" value="0.05" />
16+
<xacro:property name="wheel_xoff" value="0.12" />
17+
18+
<!-- Base Link -->
19+
<link name="base_link">
20+
<visual>
21+
<geometry>
22+
<box size="${chassis_length} ${chassis_width} ${chassis_height}"/>
23+
</geometry>
24+
<material name="silver"/>
25+
</visual>
26+
<collision>
27+
<geometry>
28+
<box size="${chassis_length} ${chassis_width} ${chassis_height}"/>
29+
</geometry>
30+
</collision>
31+
<xacro:box_inertia m="15.0" w="${chassis_width}" h="${chassis_height}" d="${chassis_length}"/>
32+
</link>
33+
34+
<!-- Wheel Macro -->
35+
<xacro:macro name="wheel" params="prefix x_reflect y_reflect">
36+
<link name="${prefix}_link">
37+
<visual>
38+
<origin xyz="0 0 0" rpy="${pi/2} 0 0"/>
39+
<geometry>
40+
<cylinder radius="${wheel_radius}" length="${wheel_width}"/>
41+
</geometry>
42+
<material name="black"/>
43+
</visual>
44+
<collision>
45+
<origin xyz="0 0 0" rpy="${pi/2} 0 0"/>
46+
<geometry>
47+
<cylinder radius="${wheel_radius}" length="${wheel_width}"/>
48+
</geometry>
49+
</collision>
50+
<xacro:cylinder_inertia m="0.5" r="${wheel_radius}" h="${wheel_width}"/>
51+
</link>
52+
53+
<joint name="${prefix}_joint" type="continuous">
54+
<parent link="base_link"/>
55+
<child link="${prefix}_link"/>
56+
<origin xyz="${x_reflect*wheel_xoff} ${y_reflect*(chassis_width/2+wheel_ygap)} ${-wheel_zoff}" rpy="0 0 0"/>
57+
<axis xyz="0 1 0"/>
58+
</joint>
59+
</xacro:macro>
60+
61+
<xacro:wheel prefix="drivewhl_l" x_reflect="-1" y_reflect="1" />
62+
<xacro:wheel prefix="drivewhl_r" x_reflect="-1" y_reflect="-1" />
63+
64+
<!-- Caster Wheel -->
65+
<link name="front_caster">
66+
<visual>
67+
<geometry>
68+
<sphere radius="${(wheel_radius+wheel_zoff)/2}"/>
69+
</geometry>
70+
<material name="black"/>
71+
</visual>
72+
<collision>
73+
<geometry>
74+
<sphere radius="${(wheel_radius+wheel_zoff)/2}"/>
75+
</geometry>
76+
</collision>
77+
<inertial>
78+
<mass value="0.1"/>
79+
<inertia ixx="0.0001" ixy="0.0" ixz="0.0" iyy="0.0001" iyz="0.0" izz="0.0001"/>
80+
</inertial>
81+
</link>
82+
83+
<joint name="caster_joint" type="fixed">
84+
<parent link="base_link"/>
85+
<child link="front_caster"/>
86+
<origin xyz="${wheel_xoff} 0 ${-(wheel_radius+wheel_zoff)/2}" rpy="0 0 0"/>
87+
</joint>
88+
89+
</robot>
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0"?>
22
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
3-
<xacro:material name="silver">
3+
<material name="silver">
44
<color rgba="0.75 0.75 0.75 1.0"/>
5-
</xacro:material>
5+
</material>
66

7-
<xacro:material name="black">
7+
<material name="black">
88
<color rgba="0.0 0.0 0.0 1.0"/>
9-
</xacro:material>
9+
</material>
1010
</robot>

0 commit comments

Comments
 (0)