Commit 21902bf
authored
Add geometry-based robot class generator (#642)
* Add geometry-based robot class generator without LLM
Add robot_class_generator.py that generates Python robot classes
from URDF geometry without requiring LLM or API keys.
Key features:
- Automatic kinematic chain detection using NetworkX graph analysis
- Geometry-based limb type detection (arm, leg, head, torso)
- TCP estimation from gripper fingertip midpoint or mesh extent
- Tool frame and hand link detection from link structure
- Support for single-arm and dual-arm robots
* Add generate-robot-class to skr CLI
Move robot class generator from examples to skr CLI command.
Update README.md and docs/source/cli.rst with usage documentation.
* Support ROS package:// path in generate_robot_class
Automatically detect if URDF is inside a ROS package and generate
default_urdf_path with package:// format instead of absolute path.
* Support package:// URLs in URDF.load
Resolve package:// URLs using resolve_filepath before loading URDF.
This allows generated robot classes with package:// default_urdf_path
to work correctly when loaded from within a ROS package directory.
* Improve gripper detection with geometric symmetry
- Remove 'gripper_link' from tool_frame patterns (was too broad)
- Add _find_symmetric_gripper_midpoint() for geometry-based detection
- Detect gripper fingers by finding symmetric child links (same parent,
opposite x/y coordinates) instead of relying on naming patterns
- Support package:// URLs in URDF.load
* Use mesh-based fingertip positions for gripper midpoint
- Calculate gripper midpoint using _get_fingertip_position() instead
of link.worldpos() for more accurate TCP estimation
- Skip _calculate_gripper_tcp_offset if offset already set by
symmetric gripper detection to avoid overwriting correct values
* Use link origins for symmetric gripper midpoint
Mesh-based fingertip detection doesn't work well for grippers with
opposing fingers (different directions). Use link origin midpoint
instead for symmetric gripper pairs.
* Fix package:// path double conversion
Skip _convert_to_ros_package_path if input is already a package:// URL
to avoid corrupting the path.
* Add gripper orientation calculation to robot class generator
Calculate end_coords orientation for symmetric gripper links so that:
- x-axis points in gripper forward direction (from parent to midpoint)
- y-axis points in gripper opening direction (between fingers)
- z-axis is computed as x cross y
The rotation is output as RPY angles in radians in the generated
CascadedCoords initialization.
* Externalize patterns and improve robot class generator
Based on feedback, this commit makes the following improvements:
1. Add PatternConfig class for externalizing all "magic words"
- Users can customize patterns for non-standard naming conventions
- Patterns can be extended or overridden via constructor
- force_groups option to bypass auto-detection for specific groups
2. Use pre-compiled regex for pattern matching
- Improves performance by compiling patterns once
- All pattern matching now uses PatternConfig.matches()
3. Switch mesh priority for TCP estimation
- Visual mesh now preferred over collision mesh
- Visual meshes have more accurate vertex positions for fingertips
- Collision meshes may be simplified convex hulls
4. Add documentation about geometric detection limitations
- Y-coordinate based left/right detection assumes T-pose
- Notes added to docstrings about potential failure cases
Example usage:
config = PatternConfig(
patterns={'right_arm': ['RA_', 'right_arm_j']},
force_groups={'head': ['neck_link', 'head_link']}
)
generate_robot_class_from_geometry(robot, config=config)
* Fix non-deterministic Y-axis direction in gripper orientation
The Y-axis direction was dependent on the iteration order of child
links, which is non-deterministic. This caused the gripper orientation
to be inconsistent between runs.
Fix: Ensure Y-axis always points toward the positive direction of the
axis with the largest absolute component. This makes the orientation
calculation deterministic regardless of iteration order.
* Fix gripper orientation when finger origins are at parent origin
When finger link origins are located at the parent origin (like Fetch),
use fingertip mesh positions to determine the approach direction instead
of falling back to an arbitrary axis.
This fixes incorrect gripper orientations for robots like Fetch where
the finger links' origins are at [0, ±y, 0] relative to gripper_link,
resulting in a midpoint at the origin.
* Delete generate-robot-class command
* Extract magic numbers as named constants for better maintainability
- Add module-level constants for geometric detection thresholds
- Remove unused center calculation in _estimate_tcp_from_mesh
- Replace hardcoded values with descriptive constants:
- SYMMETRY_POSITION_TOLERANCE, MIN_POSITION_OFFSET, Z_SIMILARITY_TOLERANCE
- MAX_SEARCH_DEPTH, POSITION_EPSILON, FINGERTIP_RATIO, ASYMMETRY_RATIO
- Y_THRESHOLD_WEAK, Y_THRESHOLD_STRONG, MIN_ARM_JOINTS1 parent a3fb53f commit 21902bf
File tree
7 files changed
+1840
-0
lines changed- docs/source
- skrobot
- apps
- urdf
- utils
7 files changed
+1840
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
70 | 73 | | |
71 | 74 | | |
72 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
112 | 135 | | |
113 | 136 | | |
114 | 137 | | |
| |||
124 | 147 | | |
125 | 148 | | |
126 | 149 | | |
| 150 | + | |
127 | 151 | | |
128 | 152 | | |
129 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| 28 | + | |
| 29 | + | |
26 | 30 | | |
0 commit comments