Add firmware and extension catalogues, configuration transactions, sample review and QML diagnostics. Preserve explicit authority, bounded retries and stop recovery in motor transport.
20 lines
1.0 KiB
Python
20 lines
1.0 KiB
Python
"""Read-only operating-current projection; never a configuration writer."""
|
|
import math
|
|
import time
|
|
|
|
def publish(device, motor):
|
|
fields = ("l_current_max", "l_current_min", "l_current_max_scale", "l_current_min_scale")
|
|
if any(type(motor.get(k)) not in (int, float) or not math.isfinite(motor[k]) for k in fields):
|
|
raise ValueError("Invalid motor current configuration")
|
|
if not (motor["l_current_min"] < 0 < motor["l_current_max"] and
|
|
0 < motor["l_current_max_scale"] <= 1 and 0 < motor["l_current_min_scale"] <= 1):
|
|
raise ValueError("Invalid motor current scales")
|
|
device.drive_limits = {"session_id": device.session, "sampled_at": time.monotonic(),
|
|
"motor_a": motor["l_current_max"] * motor["l_current_max_scale"],
|
|
"brake_a": -motor["l_current_min"] * motor["l_current_min_scale"]}
|
|
|
|
def projection(device):
|
|
limits = device.get("drive_limits")
|
|
if not limits or limits["session_id"] != device["session"]: return None
|
|
return {k: limits[k] for k in ("motor_a", "brake_a")}
|