rebot_control.calib.gains

MIT gain (kp / kd) checks and tuning from small step responses.

Background (docs/user/gains.md): the motor runs tau = kp (q* - q) + kd (dq* - dq) + tau_ff internally, so the joint behaves like a mass-spring-damper with stiffness kp, damping kd (plus friction) and inertia J = M(q)_jj + rotor inertia:

omega_n = sqrt(kp / J),    zeta = kd / (2 sqrt(kp J))

kp and kd cannot be raised freely: delay (CAN round trip, 150 Hz frames), encoder quantisation and velocity noise make the loop ring, buzz or squeal above some limit. The procedure here:

  1. step_response(): a small target step (default 2 deg) on one joint while the others hold; metrics: overshoot, rise / settling time, steady-state error, residual velocity (limit cycle) and torque ripple (buzz).

  2. find_kp_max(): raise kp geometrically (kd follows the damping-ratio rule) until a limit criterion trips or the safety cap is reached. The last passing kp is kp_max.

  3. Recommended working gains: kp = margin * kp_max (default 0.6) and kd for zeta (default 0.8), both capped; verified with one more step.

Every step is small and the torque stays capped by safety.max_error; a step that moves the joint by more than three times the amplitude aborts.

Module Contents

Classes

Functions

effective_inertia

analyze_step

step_response

Step joint by +amplitude and back with the given gains (others unchanged); returns both responses.

failed

kd_for

find_kp_max

Raise kp from the configured value until a limit trips or kp_cap; recommend margin * kp_max.

API

class rebot_control.calib.gains.StepMetrics
joint: int = None
kp: float = None
kd: float = None
amplitude_deg: float = None
overshoot: float = None
rise_s: float = None
settle_s: float = None
ss_error_deg: float = None
residual_vel_deg_s: float = None
torque_ripple: float = None
zeta_est: float = None
zeta_model: float = None
omega_n: float = None
line() → str
rebot_control.calib.gains.effective_inertia(arm, q: numpy.ndarray, joint: int) → float
rebot_control.calib.gains.analyze_step(t: numpy.ndarray, qj: numpy.ndarray, dqj: numpy.ndarray, tauj: numpy.ndarray, q_start: float, amplitude: float) → dict[str, float]
rebot_control.calib.gains.step_response(arm, joint: int, kp: float | None = None, kd: float | None = None, amplitude: float = math.radians(2.0), duration: float = 0.8) → list[rebot_control.calib.gains.StepMetrics]

Step joint by +amplitude and back with the given gains (others unchanged); returns both responses.

class rebot_control.calib.gains.Limits
max_overshoot: float = 0.3
max_residual_vel_deg_s: float = 1.0
max_ripple_frac: float = 0.01
max_settle_s: float = 0.6
rebot_control.calib.gains.failed(m: rebot_control.calib.gains.StepMetrics, lim: rebot_control.calib.gains.Limits, effort: float) → str | None
rebot_control.calib.gains.kd_for(kp: float, J: float, zeta: float) → float
class rebot_control.calib.gains.TuneResult
joint: int = None
kp_max: float = None
stop_reason: str = None
kp: float = None
kd: float = None
trials: list[dict] = None
check: list[dict] = None
rebot_control.calib.gains.find_kp_max(arm, joint: int, kp_cap: float, kd_cap: float, zeta: float = 0.8, factor: float = 1.25, margin: float = 0.6, limits: rebot_control.calib.gains.Limits | None = None, amplitude: float = math.radians(2.0), progress: collections.abc.Callable[[str], None] = print) → rebot_control.calib.gains.TuneResult

Raise kp from the configured value until a limit trips or kp_cap; recommend margin * kp_max.