Week Four: Robots Learn to Not Hit Themselves
Collision detection arrives, commands become interruptible GenServers, IK solvers reject self-collisions, and Livebook gets a Parameters widget.
The headline this week: your robot can now check whether it's about to punch itself in the face. Progress!
Development has been slower than I'd hoped - turns out New Year's celebrations and summer holidays here in New Zealand aren't particularly conducive to writing code. Who knew? Still, we've got some solid updates.
Real Hardware, Real Motion
The WidowX 200 is alive and moving. Commands execute, the DLS IK solver works, and I've had the end effector tracing circles in space. It's one thing to watch simulated joint positions update in Livebook - it's quite another to hear servos whine and watch an actual robot arm follow your commands.
More videos and documentation coming once I've cleaned up the example code.
Collision Detection
BB v0.11 adds a proper two-phase collision detection system:
- Broad phase: Fast AABB (axis-aligned bounding box) overlap tests to quickly eliminate non-colliding pairs
- Narrow phase: Precise intersection tests for spheres, capsules, cylinders, and boxes
- Mesh support: Load STL files with automatic bounding computation
# Will the robot collide with itself at these joint positions?
BB.Collision.self_collision?(robot, positions)
# Check with a safety margin (catches near-misses)
BB.Collision.detect_self_collisions(robot, positions, margin: 0.01)
# Environment obstacles too
obstacles = [BB.Collision.obstacle(:sphere, centre, radius)]
BB.Collision.collides_with?(robot, positions, obstacles)
The system automatically excludes adjacent links from self-collision checks (your elbow is supposed to touch your shoulder). And yes, you can define collision volumes using a new capsule DSL entity.
IK Solvers: "Actually, No"
The DLS solver now integrates with collision detection:
# Reject solutions that would cause self-collision
DLS.solve(robot, positions, :tip, target, check_collisions: true)
# With a safety margin
DLS.solve(robot, positions, :tip, target,
check_collisions: true,
collision_margin: 0.01
)
When a solution would cause a collision, you get a proper structured error:
This is the kind of thing you want to know before you command the motion, not after.
Commands Get Interruptible
BB v0.12 converts commands from Tasks to GenServers. Why does this matter? Because now commands can respond to events during execution.
The big win: if you hit the E-stop while a MoveTo is in progress, the command actually stops. Previously it would run to completion regardless (the actuators would ignore commands while disarmed, but the command itself kept chugging along).
Commands now implement a proper behaviour with callbacks:
handle_command/3- Do the work (signature changed significantly)result/1- Extract result from statehandle_safety_state_change/2- React when safety state changeshandle_options/2- React when parameters change at runtime
Breaking change: If you've written custom commands, they need updating. The handle_command callback works differently now. Check the commands tutorial for the new pattern.
Parameters Widget for Livebook
BB Kino v0.3 adds a BB.Kino.Parameters widget. View and edit your robot's parameters directly in Livebook:
- Tab-based UI groups parameters logically
- Remote bridge parameters get their own tabs
- Input controls match parameter types (toggles for booleans, sliders for bounded numbers, etc.)
- Real-time updates via PubSub
- Validation feedback when setting invalid values
The widget slots in at the bottom of the "Manage robot" Smart Cell, full-width.
The Robotis Situation
Good news! The upstream robotis v0.2.0 landed on Hex on New Year's Eve. This includes our contributed XM430 support, table parameterisation, and raw read/write API.
Bad news: I haven't had time to cut the bb_servo_robotis release yet. The driver is ready, tested, and waiting. Just needs someone (me) to push the button. It's on the list.
All The Releases
Since December 29:
| Package | Version | What changed |
|---|---|---|
| bb | v0.12.0 | Interruptible commands (GenServer-based) |
| bb | v0.11.0 | Collision detection system |
| bb_ik_dls | v0.3.1 | Update for bb 0.12 command API |
| bb_ik_dls | v0.3.0 | Self-collision checking in IK solver |
| bb_ik_fabrik | v0.3.1 | Update for bb 0.12 command API |
| bb_kino | v0.3.0 | Parameters widget, bb 0.12 compatibility |
| robotis | v0.2.0 | (upstream) XM430 support, raw API |
What's Next
Parts for an SO-101 are on their way from AliExpress. Designed by TheRobotStudio, it's a capable, affordable arm that should make a good reference platform for folks who want to try Beam Bots without dropping serious cash on Dynamixel servos.
In the meantime: more IK work, better joint limit enforcement, and getting bb_servo_robotis onto Hex.
Links
- bb on Hex (v0.12.0)
- bb_ik_dls on Hex (v0.3.1)
- bb_ik_fabrik on Hex (v0.3.1)
- bb_kino on Hex (v0.3.0)
- bb_liveview on Hex (v0.2.0)
- bb_servo_pca9685 on Hex (v0.4.0)
- bb_servo_pigpio on Hex (v0.4.0)
- bb_servo_robotis on GitHub (Hex release imminent)
- robotis on Hex (v0.2.0)
- Discord