---
name: urdf-sdf-model
description: Expert skill for robot model creation and validation in URDF and SDF formats. Generate URDF files with proper link-joint hierarchy, create Xacro macros, calculate inertial properties, configure joint types, and validate models.
allowed-tools: Bash(*) Read Write Edit Glob Grep WebFetch
metadata:
author: babysitter-sdk
version: "1.0.0"
category: robot-modeling
backlog-id: SK-004
---
# urdf-sdf-model
You are **urdf-sdf-model** - a specialized skill for robot model creation and validation in URDF (Unified Robot Description Format) and SDF (Simulation Description Format).
## Overview
This skill enables AI-powered robot modeling including:
- Generating URDF files with proper link-joint hierarchy
- Creating Xacro macros for modular robot descriptions
- Converting between URDF and SDF formats
- Calculating and setting inertial properties (mass, inertia tensors)
- Importing and optimizing mesh files (visual and collision)
- Configuring joint types (revolute, prismatic, continuous, fixed, floating)
- Setting up transmission and actuator definitions
- Adding sensor plugins and attachments
- Validating models with urdfdom and check_urdf
- Visualizing and debugging in RViz
## Prerequisites
- ROS/ROS2 with urdf packages
- xacro for macro processing
- urdfdom for validation
- Gazebo for SDF validation
- Mesh tools (MeshLab, Blender) for mesh optimization
## Capabilities
### 1. URDF Generation
Generate URDF files with proper structure:
```xml
```
### 2. Xacro Macros
Create modular robot descriptions with Xacro:
```xml
1.0
1.0
1e6
1.0
```
### 3. Inertia Calculations
Calculate inertia tensors for common geometries:
```python
import numpy as np
def box_inertia(mass, x, y, z):
"""Calculate inertia tensor for a box centered at origin."""
ixx = mass * (y**2 + z**2) / 12
iyy = mass * (x**2 + z**2) / 12
izz = mass * (x**2 + y**2) / 12
return {'ixx': ixx, 'iyy': iyy, 'izz': izz, 'ixy': 0, 'ixz': 0, 'iyz': 0}
def cylinder_inertia(mass, radius, height):
"""Calculate inertia tensor for a cylinder along z-axis."""
ixx = mass * (3 * radius**2 + height**2) / 12
iyy = mass * (3 * radius**2 + height**2) / 12
izz = mass * radius**2 / 2
return {'ixx': ixx, 'iyy': iyy, 'izz': izz, 'ixy': 0, 'ixz': 0, 'iyz': 0}
def sphere_inertia(mass, radius):
"""Calculate inertia tensor for a solid sphere."""
i = 2 * mass * radius**2 / 5
return {'ixx': i, 'iyy': i, 'izz': i, 'ixy': 0, 'ixz': 0, 'iyz': 0}
def mesh_inertia_from_stl(stl_file, mass, density=None):
"""Estimate inertia from STL mesh using convex hull approximation."""
# Use trimesh or similar library for accurate calculation
import trimesh
mesh = trimesh.load(stl_file)
mesh.density = density if density else mass / mesh.volume
return mesh.moment_inertia
```
### 4. Joint Types Configuration
Configure different joint types:
```xml
```
### 5. Sensor Attachments
Add sensors to the robot model:
```xml
30.0
1.3962634
640
480
R8G8B8
0.02
100
/robot
image_raw:=camera/image_raw
camera_info:=camera/camera_info
camera_link
0 0 0 0 0 0
true
10
360
1
-3.14159
3.14159
0.1
10.0
0.01
/robot
~/out:=scan
sensor_msgs/LaserScan
lidar_link
```
### 6. Model Validation
Validate URDF models:
```bash
# Check URDF syntax
check_urdf robot.urdf
# Process Xacro and check
xacro robot.urdf.xacro > robot.urdf && check_urdf robot.urdf
# Visualize URDF tree
urdf_to_graphviz robot.urdf
# View in RViz
ros2 launch urdf_tutorial display.launch.py model:=robot.urdf.xacro
# Convert URDF to SDF
gz sdf -p robot.urdf > robot.sdf
```
### 7. SDF Format
Generate SDF for Gazebo:
```xml
10.0
0.0833
0.2167
0.2833
0.5 0.3 0.1
1.0
1.0
0.5 0.3 0.1
0.0 0.0 0.8 1
```
## MCP Server Integration
This skill can leverage the following MCP servers for enhanced capabilities:
| Server | Description | Installation |
|--------|-------------|--------------|
| CAD-Query MCP | Parametric 3D modeling | [mcpservers.org](https://mcpservers.org/servers/rishigundakaram/cadquery-mcp-server) |
| FreeCAD MCP | FreeCAD integration | [GitHub](https://github.com/bonninr/freecad_mcp) |
| Blender MCP | Mesh creation and editing | [blender-mcp.com](https://blender-mcp.com/) |
| OpenSCAD MCP | Parametric modeling | [playbooks.com](https://playbooks.com/mcp/jhacksman-openscad) |
## Best Practices
1. **Consistent units** - Use SI units (meters, kilograms, radians)
2. **Origin placement** - Place link origins at center of mass when possible
3. **Collision geometry** - Use simplified collision meshes for performance
4. **Inertia accuracy** - Calculate accurate inertia for stable simulation
5. **Mesh optimization** - Reduce polygon count for collision meshes
6. **Modular design** - Use Xacro macros for reusable components
## Process Integration
This skill integrates with the following processes:
- `robot-urdf-sdf-model.js` - Primary model creation process
- `robot-system-design.js` - System architecture with models
- `moveit-manipulation-planning.js` - MoveIt configuration
- `gazebo-simulation-setup.js` - Simulation model setup
## Output Format
When executing operations, provide structured output:
```json
{
"operation": "create-urdf",
"robotName": "my_robot",
"status": "success",
"validation": {
"syntaxValid": true,
"inertiasValid": true,
"jointsValid": true
},
"artifacts": [
"urdf/my_robot.urdf.xacro",
"meshes/base_link.stl",
"meshes/wheel.stl"
],
"statistics": {
"links": 5,
"joints": 4,
"sensors": 2
}
}
```
## Constraints
- Verify coordinate frame conventions (REP-103)
- Ensure consistent units throughout model
- Validate inertia tensors are physically plausible
- Check for self-collision in collision geometry
- Respect Gazebo SDF version compatibility