Skip to content

Conversation

@jimsynz
Copy link
Contributor

@jimsynz jimsynz commented Dec 29, 2025

Summary

Adds a two-phase collision detection system for BB robots:

  • Broad phase (BB.Collision.BroadPhase): Fast AABB overlap tests to eliminate non-colliding pairs
  • Narrow phase (BB.Collision.Primitives): Precise primitive intersection tests (sphere, capsule, box)
  • Mesh support (BB.Collision.Mesh): STL file loading with automatic bounding sphere/AABB computation

Features

  • Self-collision detection between non-adjacent robot links
  • Environment collision detection against obstacle primitives
  • Configurable safety margins for near-miss detection
  • Support for sphere, capsule, cylinder, box, and mesh collision geometries
  • New capsule DSL entity for collision volumes

API

# Self-collision checks
BB.Collision.self_collision?(robot, positions)
BB.Collision.detect_self_collisions(robot, positions, margin: 0.01)

# Environment collision checks
obstacles = [BB.Collision.obstacle(:sphere, centre, radius)]
BB.Collision.collides_with?(robot, positions, obstacles)
BB.Collision.detect_collisions(robot, positions, obstacles)

Test plan

  • Broad phase AABB tests (overlap, compute, expand, merge)
  • Narrow phase primitive tests (sphere-sphere, capsule-capsule, box-box, mixed)
  • Mesh loading and bounds computation
  • Self-collision detection with adjacency exclusion
  • Environment collision detection
  • All checks pass (mix check --no-retry)

Add a comprehensive collision detection system for BB robots:

- Add capsule geometry type to DSL (cylinder with hemispherical caps)
- Implement collision primitives: sphere-sphere, capsule-capsule,
  sphere-capsule, sphere-box, capsule-box, box-box (OBB with SAT)
- Add broad phase AABB culling for fast collision pair elimination
- Add STL mesh parsing with bounding geometry computation and caching
- Implement self-collision detection with adjacent link exclusion
- Implement environment collision detection with obstacle API

Public API:
- `BB.Collision.self_collision?/3` - check for self-collision
- `BB.Collision.detect_self_collisions/3` - get collision details
- `BB.Collision.collides_with?/4` - check against obstacles
- `BB.Collision.detect_collisions/4` - get obstacle collision details
- `BB.Collision.obstacle/3,4` - create sphere/capsule/box obstacles

All functions support an optional margin parameter for safety buffers.
- Fix alias ordering to be alphabetical in collision modules
- Add explicit alias for `BB.Collision.Mesh` instead of inline references
- Replace `length/1` assertions with pattern matching in tests
- Extract helper functions to reduce cyclomatic complexity in `closest_points_segments`
- Extract `check_box_axis/7` to reduce nesting depth in `box_box`
- Update formatter config and documentation
@jimsynz jimsynz merged commit 5791881 into main Dec 30, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants