Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates console initialization and safety polling behavior in motion_connector.py, focusing on safer mutex handling, improved status propagation, and gating safety-clear logic on TEC status.
Changes:
- Wraps laser-power I2C initialization in a
try/finallyto guarantee console mutex unlock. - Propagates TEC status “ok” from
tec_status()and uses it in the console status thread’s safety gating logic. - Adjusts DRIVE CL user-config override calculation logic.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def _write_drive_cl(ch: int, thresh, gain: float, label: str) -> bool: | ||
| if thresh is None: | ||
| return True | ||
| set_value = thresh | ||
| gain_f = float(gain) if gain is not None else 0.0 | ||
| if gain_f != 0.0: | ||
| set_value = thresh/gain_f | ||
| raw = max(0, min(0xFFFF, int(round(set_value)))) # uint16 raw value | ||
| data = bytearray([raw & 0xFF, (raw >> 8) & 0xFF]) # LSB first |
There was a problem hiding this comment.
In _write_drive_cl, the raw uint16 written to DRIVE CL is currently computed as round(thresh / gain) only when gain != 0, and otherwise uses thresh directly. Given DRIVE CL’s default scale is 1.86 mA/LSB (see FpgaModel), a missing/0 gain should still apply the default scale; otherwise a user-config threshold in mA will be written ~1.86× too high. Consider computing an effective_scale = gain_f if gain_f > 0 else 1.86 and always converting raw = round(thresh / effective_scale) (and update the comment that currently says thresh is already a raw register value). Also, since cfg_obj.json_data may hold strings, cast thresh (and optionally gain) to float with validation before arithmetic to avoid TypeError/ValueError at startup.
No description provided.