Robotics building blocks
Build hobby and education robots from the parts you would actually buy or
print: SG90 / MG996R / STS3215 servos, horns, servo brackets, TT and N20 gear
motors, wheels, ball casters, hole-grid chassis plates, leg links, an HC-SR04
and camera modules. Parts snap together through typed interfaces, and every
servo output and motor shaft is a joint you pose by angle. This is the
cadbuildr-robotics library, built on Foundation and the standard library.
Prerequisites: pip install cadbuildr-robotics (it installs
cadbuildr-foundation and cadbuildr-stdlib; add cadbuildr-electronics
for controller boards).
A pan-tilt head in one line
from cadbuildr.foundation import show
from cadbuildr.robotics import PanTilt
show(PanTilt(model="SG90", pan=40, tilt=20, head="HC-SR04"))In the Prototype app, pan and tilt appear in the configuration bar:
change them and the head turns. The named configurations (Centre, Look
left, Look up right, Scan down) are poses.
Build a servo chain yourself
Three calls make every servo mechanism: seat the servo, drive a horn, attach a link.
from cadbuildr.foundation import Assembly, show
from cadbuildr.robotics import (
HobbyServo, ServoHorn, ServoMountPlate, ServoLink, mount_servo, drive, attach,
)
asm = Assembly()
plate = ServoMountPlate(model="SG90")
asm.ground(plate)
servo = HobbyServo(model="SG90")
mount_servo(asm, servo, plate.interface("servo")) # ears on the plate
horn = ServoHorn(style="double", spline="21T")
arm = drive(asm, servo, horn, angle_deg=30) # a revolute joint, +/-90 deg
attach(asm, ServoLink(model="SG90", end="tip"), horn)
arm.set(-45) # the link follows
show(asm)drive returns a servo joint limited to the servo’s travel: arm.set(120)
on an SG90 raises ServoTravelError instead of placing anything. An SG90 in
an MG996R pocket, or a 21T horn on a 25T output, raises
IncompatibleInterfaces.
Ready-made mechanisms
| Assembly | What it is | Pose inputs |
|---|---|---|
PanTilt | base plate, two servos, cradle, L head, optional HC-SR04 | pan, tilt |
Leg2DoF | hip servo, femur link, knee servo, tibia | hip, knee |
Leg3DoF | coxa servo, cradle, femur and tibia stages | coxa, femur, tibia |
RobotCar | hole-grid plate, two TT motors, wheels, ball caster, HC-SR04, ESP32 | wheel_angle |
ClawGripper | palm with a fixed jaw, servo, horn jaw | opening |
Each has named poses: leg.set_pose("stand"), or a mapping
leg.set_pose({"hip": -30, "knee": 70}).
A robot on a deck
ChassisPlate.site(name, x, y) turns any spot of the plate into a mounting
face you can connect a bracket to:
from cadbuildr.foundation import Assembly, show
from cadbuildr.robotics import ChassisPlate, SensorMountBracket, HCSR04, mount_board
from cadbuildr.electronics.boards import ESP32DevKit
robot = Assembly()
plate = ChassisPlate(length=150, width=110)
robot.ground(plate)
bumper = SensorMountBracket(model="HC-SR04")
robot.connect(bumper.interface("base"), plate.site("bumper", 72.5, 0))
robot.connect(HCSR04().interface("face"), bumper.interface("sensor"))
mount_board(robot, ESP32DevKit(), plate.site("board", -30, 0))
print([i for i in robot.check() if i["severity"] != "info"]) # [] — all connected
show(robot)Catalog
| Group | Parts |
|---|---|
| Servos | HobbyServo (SG90, MG90S, MG996R, DS3218), BusServo (STS3215), ServoHorn |
| Brackets | ServoMountPlate, ServoBracket, HornBracket, UBracket |
| Links | ServoLink, FemurLink, CurvedFootLink |
| Drive | TTMotor, N20Motor, MotorMountBracket, Wheel, OmniWheel, MecanumWheel, CasterBall |
| Chassis | ChassisPlate |
| Sensors | HCSR04, CameraModule, SensorMountBracket |
Dimensions come from public datasheets and are kept in tables
(SERVOS, WHEELS, CASTER_BALLS, CAMERAS): add a model as a table row.