Architecture¶
user code / CLI (cli.py) / calibration tools (calib/)
| joint targets, TCP targets, mode changes caller thread, control_hz (30 Hz)
v
Arm (arm.py) ----------- CartesianController (cartesian.py) -- DiffIK (ik.py)
| command_joint(q)
v
JointTargetFilter (joint_filter.py): soft limits -> jump guard -> rate limit -> low-pass
| servo.set_target(q, t)
v
ServoLoop (servo.py): interpolation, torque cap, feedforward (model.py), gain ramp, servo thread (real) or
temperature guard, recording stepped by Arm.sleep (sim),
| send_mit(q, dq, kp, kd, tau) / read() servo_hz (150 Hz)
v
Backend (backends/): RobStrideBackend (motorbridge, SocketCAN) | SimBackend (MuJoCo, physics_hz 1050 Hz)
RobotModel (model.py) is the Pinocchio model of arm + tool. It provides FK, Jacobians, gravity, the mass matrix
and the regressor. It is shared by the servo loop (feedforward), the IK and the calibration tools. Each thread uses
its own pin.Data (model.new_data()).
Modules¶
Module |
Responsibility |
|---|---|
|
dataclasses for arm / tool / calibration YAML; degree -> radian conversion at load |
|
rotation helpers (pure numpy) |
|
Pinocchio model, TCP frame, payload, identified link parameters |
|
damped least-squares IK with a null-space posture term |
|
conditioning of joint targets at the control rate |
|
MIT frame generation at the servo rate; modes PASSIVE / HOLD / GRAVITY |
|
backend interface, |
|
real arm |
|
MuJoCo arm built from the same model |
|
facade: life cycle, modes, moves, stall check, recording |
|
Cartesian limits and the streaming controller |
|
poses, gravity / payload, friction, torque ripple, TCP pivot, gains |
|
|
|
exception types: |
Threads and locks¶
Real arm.
ServoLoop._runruns in a daemon thread. It holdsServoLoop._lock(an RLock) while it computes and sends a frame. Commands from the caller (set_target,set_mode,set_gains, tool swaps) take the same lock.RobStrideBackend._lockserialises every bus access (servo frames,enable,disable,close).Simulation. There are no threads.
Arm.sleepcallsservo.tickandbackend.advance(servo.period)servo_hz / control_hztimes. Simulation time is the clock (backend.now()).ServoLoop.stateis replaced atomically each tick (a freshJointState). Readers copy it.
Life cycle¶
connect(): bus open. Read the joint angles without a command frame (Backend.read_positions), send one full-gain frame holding those angles, read the replies. Motors enabled: HOLD at the measured pose with full gains (taken_over). All disabled: PASSIVE (zero-gain frames, feedback only). Zero-gain frames are never sent before this is known.enable(): the backend enables the motors. The servo switches to HOLD at the measured pose with the gain ramp.Commands (
command_joint,move_*,cartesian()),gravity_mode()/hold().close()(clean exit): fold in stages, disable, PASSIVE, stop the thread, close the bus. An arm that was found enabled and never commanded is left as found.detach()(exception, Ctrl-C): HOLD at the measured pose, one last frame, stop the thread, close the bus without disabling. The motors keep executing that frame.
Errors¶
Error |
Meaning |
|---|---|
|
one command refused; nothing changed |
|
stall (the arm holds; torque off with |
|
bus, CAN or motor problems |
Errors raised in the servo thread are stored in servo.error and re-raised by Arm.check(), which runs at the start
of every command and every sleep().