Skip to content

Commit

Permalink
Properly handle disjoint QueryResolution._extra ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
jpieper committed Jun 30, 2022
1 parent 4c0e1c4 commit 1c078d8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/python/moteus/moteus.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,13 @@ def _make_query_data(self):
c3.maybe_write()

if len(qr._extra):
min_val = int(min(qr._extra.keys()))
max_val = int(max(qr._extra.keys()))
c4 = mp.WriteCombiner(
writer, 0x10, int(min(qr._extra.keys())),
[qr._extra[y] for y in
sorted(list([int(x) for x in qr._extra.keys()]))])
for _ in qr._extra.keys():
writer, 0x10, min_val,
[qr._extra.get(i, mp.IGNORE)
for i in range(min_val, max_val +1)])
for _ in range(min_val, max_val + 1):
c4.maybe_write()

return buf.getvalue()
Expand Down
22 changes: 22 additions & 0 deletions lib/python/moteus/test/moteus_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,28 @@ def test_make_read_gpio(self):
result.data,
bytes([0x12, 0x5e]))

def test_query_extra_disjoint(self):
qr = mot.QueryResolution()
qr._extra = {
0x030 : mot.mp.F32,
0x031 : mot.mp.F32,
0x033 : mot.mp.F32,
0x034 : mot.mp.F32,
0x035 : mot.mp.F32,
0x036 : mot.mp.F32,
}

dut = mot.Controller(query_resolution=qr)
result = dut.make_query()
self.assertEqual(
result.data,
bytes([
0x11, 0x00,
0x1f, 0x01,
0x13, 0x0d,
0x1e, 0x30,
0x1c, 0x04, 0x33, ]))


if __name__ == '__main__':
unittest.main()

0 comments on commit 1c078d8

Please sign in to comment.