Migrating from TMotorCANControl¶
The APIs are different so a couple of things are needed for a code migration between the two libraries.
Setup¶
TMotorCANControl |
cubemarsPyCAN |
|---|---|
|
|
implicit |
you bring the interface up; |
hard-coded |
any |
process-wide singleton |
one |
Control loop¶
# before
with TMotorManager_mit_can(motor_type="AK80-9", motor_ID=3) as dev:
dev.set_impedance_gains_real_unit(K=10, B=0.5)
for t in loop:
dev.update()
dev.position = 1.0
# after
m = MitMotor(bus, motor_id=3, spec=SPECS["AK80-9"])
with m.control():
for t in loop:
state = m.update(position=1.0, kp=10.0, kd=0.5)
update() both sends and returns state, and the state it returns is the snapshot taken at
the top of the call — it predates the frame that call sends. The old library’s own
demos were inconsistent about this ordering: its MIT demos called update() before
setting position, its servo demos after.
Why setpoints are not attributes¶
dev.position = x is gone. MIT packs five coupled fields into one frame, so three
assignments produce two intermediate inconsistent commands; a property setter can only
clamp silently or raise from an assignment; and m.position reading feedback while
m.position = x writes a setpoint means the value you read is never the value you
wrote. Servo’s six commands are mutually exclusive, which a kwargs setter cannot express —
they are separate types here.
Things that changed because they were wrong¶
Old behaviour |
Now |
|---|---|
|
works |
|
|
servo position scaled by |
degrees × π/180, and |
|
1e4, per the manual |
|
applied |
faults raised inside the receive thread, where they vanish |
latched, raised on your thread after a safe stop |
acceleration sign inverted ( |
not derived at all; differentiate yourself if you need it |
|
±45, per the manual |
|
64 |
fault code 6 labelled “phase current unbalance” |
MOSFET over-temperature; code 7 (stall) added |
|
|
|
per-variant datasheet values, or |
a |
gone; |
NumPy 2 raised |
no NumPy dependency at all |