rebot_control.servo

Servo loop: streams MIT frames to the motors at servo_hz (150 Hz by default).

Every tick (ServoLoop.tick()):

  1. read the latest feedback (replies to the previous tick’s frames);

  2. safety: motor temperature (warn / torque off);

  3. compute the frame for the current mode:

    • PASSIVE: zero-gain frames (no output torque; keeps feedback flowing);

    • HOLD: position target interpolated linearly from the previous target to the newest one over one control period (evaluated half a servo period ahead, see ServoLoop.tick()), with the matching velocity as feedforward (the motor’s kd term then damps deviations only, it does not brake the motion), the target clamped to measured +- max_error (torque cap = kp * max_error), and the feedforward gravity * gravity_scale + friction(dq_target) * friction_scale (clipped);

    • GRAVITY: kp = 0, small kd, gravity (+ friction) feedforward only: the arm floats and can be guided by hand.

  4. gains and feedforward ramp in over ramp_s after a mode change from PASSIVE (no torque step at enable).

The loop never switches torque off on its own except for an over-temperature stop with safety.on_overtemp: disable. When it has to stop (an error in the thread), it first holds the measured pose (ServoLoop.freeze()): the motors then keep executing that frame, see docs/user/safety.md.

On the real arm a background thread calls tick (start()); in simulation the caller steps it (rebot_control.arm.Arm.sleep()), so both run the same code.

Module Contents

Classes

Data

API

rebot_control.servo.log = 'getLogger(...)'
rebot_control.servo.FREEZE_KEEP = 'radians(...)'
rebot_control.servo.ADOPT_MAX_OFFSET = 'radians(...)'
class rebot_control.servo.ServoMode(*args, **kwds)

Bases: enum.Enum

PASSIVE = 'passive'
HOLD = 'hold'
GRAVITY = 'gravity'
class rebot_control.servo.ServoLoop(backend: rebot_control.backends.base.Backend, model: rebot_control.model.RobotModel, cfg: rebot_control.config.ArmConfig)

Initialization

set_target(q: numpy.ndarray, t: float, step: bool = False) → None

New position target: interpolated from where the last frame was to q over one control period.

step=True jumps to q at the next frame (step-response tests only; still capped by max_error).

set_mode(mode: rebot_control.servo.ServoMode, t: float) → None

Switch mode. Entering HOLD from another mode holds the measured pose (no jump towards an old target).

hold_measured(t: float) → None

Replace the target by the measured pose (HOLD mode only; no gain ramp, no passive frame).

adopt(q: numpy.ndarray, t: float) → None

Enter HOLD at q with full gains at once (no ramp): for motors that are already enabled and holding there, as found at connect, or to stop where the arm is from any mode.

freeze(t: float) → None

Stop and hold from now on, whatever the mode was, with zero target velocity.

A joint that is following its target (within FREEZE_KEEP of it) keeps the target it had: re-targeting to the measured angle would move the equilibrium by the joint’s steady-state error every time. A joint far from its target (blocked, or no target at all in gravity mode) holds its measured angle.

adopt_running(st: rebot_control.backends.base.JointState, t: float) → None

Take over motors that are already holding the arm at st.q (found enabled at connect).

The target is placed so that this controller asks for the torque the motors report right now, kp (q* - q) + ff(q) = tau: the equilibrium stays where it is although the gravity model here may differ from what the previous frame used. A plain “hold the measured angle” would shift the arm by its steady-state error at every take-over.

send_hold(q: numpy.ndarray) → None

One full-gain frame that holds q (target velocity zero, gravity feedforward at q).

Sent once at connect, before it is known whether the motors are enabled: an enabled motor that sits at q keeps holding, a disabled motor ignores it. Both answer with their state.

set_gains(kp: numpy.ndarray | None = None, kd: numpy.ndarray | None = None) → None
target() → numpy.ndarray | None
feedforward(q: numpy.ndarray, dq_des: numpy.ndarray) → numpy.ndarray
tick(t: float) → rebot_control.backends.base.JointState
start_recording() → None
stop_recording() → dict[str, numpy.ndarray]

Samples since start_recording(): t, q, dq, tau, temp, q_cmd, dq_cmd, kp, kd, tau_ff (one row per tick).

start() → None
stop() → None
property running: bool