Skip to content

Commit

Permalink
Bump the ABI version to 0x0107
Browse files Browse the repository at this point in the history
This is necessary because old servos with

motor_position.output.sign == -1

had a workaround in moteus_tool that is no longer necessary.  This way
moteus_tool can identify which version of firmware it is dealing with
and do the right thing (if there is really a right thing for the old
version) for both versions.
  • Loading branch information
jpieper committed May 20, 2024
1 parent 0e85e45 commit f8c517f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 7 additions & 1 deletion fw/moteus_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,14 @@ MoteusHwPins FindHardwarePins(FamilyAndVersion);
// * Switched aux?.sources.x.i2c.poll_ms to poll_rate_us to match UART
// and give more resolution.

// # 0x0107 #
//
// * Fixed motor_position.output.sign == -1 so that DQ commands for
// voltage or current are inverted, so that positive Q axis voltage
// or current results in positive speed

#define MOTEUS_MODEL_NUMBER 0x0000
#define MOTEUS_FIRMWARE_VERSION 0x000106
#define MOTEUS_FIRMWARE_VERSION 0x000107

extern MoteusHwPins g_hw_pins;

Expand Down
24 changes: 21 additions & 3 deletions lib/python/moteus/moteus_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, old, new):
self.old = old
self.new = new

SUPPORTED_ABI_VERSION = 0x0106
SUPPORTED_ABI_VERSION = 0x0107

if new > SUPPORTED_ABI_VERSION:
raise RuntimeError(f"\nmoteus_tool needs to be upgraded to support this firmware\n\n (likely 'python -m pip install --upgrade moteus')\n\nThe provided firmare is ABI version 0x{new:04x} but this moteus_tool only supports up to 0x{SUPPORTED_ABI_VERSION:04x}")
Expand All @@ -63,6 +63,13 @@ def fix_config(self, old_config):
lines = old_config.split(b'\n')
items = dict([line.split(b' ') for line in lines if b' ' in line])

if self.new <= 0x0106 and self.old >= 0x0107:
# motor_position.output.sign was broken in older versions.
if int(items[b'motor_position.output.sign']) != 1:
print("WARNING: motor_position.output.sign==-1 is broken in order versions, disabling")
items[b'motor_position.output.sign'] = '1'
pass

if self.new <= 0x0105 and self.old >= 0x0106:
# Downgrade the I2C polling rate.
for aux in [1, 2]:
Expand Down Expand Up @@ -279,6 +286,13 @@ def fix_config(self, old_config):
items[poll_rate_us_key] = str(int(poll_ms) * 1000).encode('utf8')
print("Upgrading I2C rates for version 0x0106")

if self.new >= 0x0107 and self.old <= 0x0106:
if int(items.get(b'motor_position.output.sign', 1)) == -1:
print("Upgrading from motor_position.output.sign == -1, " +
"this was broken before, behavior will change")

# No actual configuration updating is required here.
pass

lines = [key + b' ' + value for key, value in items.items()]
return b'\n'.join(lines)
Expand Down Expand Up @@ -798,6 +812,8 @@ async def find_resistance_cal_voltage(self, input_V):
return cal_voltage

async def do_calibrate(self):
self.firmware = await self.read_data("firmware")

# Determine what our calibration parameters are.
self.calculate_calibration_parameters()

Expand Down Expand Up @@ -1417,8 +1433,10 @@ async def calibrate_kv_rating(self, input_V, unwrapped_position_scale,
geared_v_per_hz = 1.0 / _calculate_slope(voltages, speed_hzs)

v_per_hz = (geared_v_per_hz *
unwrapped_position_scale *
motor_output_sign)
unwrapped_position_scale)
if self.firmware.version <= 0x0106:
v_per_hz *= motor_output_sign

print(f"v_per_hz (pre-gearbox)={v_per_hz}")

await self.command(f"conf set servopos.position_min {original_position_min}")
Expand Down

0 comments on commit f8c517f

Please sign in to comment.