From b63983ef5cdfddfa51b4710eff61cd557fa8aaf2 Mon Sep 17 00:00:00 2001 From: PAJohnson Date: Wed, 29 Jul 2020 20:46:26 -0400 Subject: [PATCH] Fixed units for can_simple protocol and updated can HWIL test --- Firmware/communication/can_simple.cpp | 12 ++++++------ docs/can-protocol.md | 6 +++--- tools/odrive/tests/can_test.py | 24 ++++++++++++------------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Firmware/communication/can_simple.cpp b/Firmware/communication/can_simple.cpp index 027bfbea..77e8f416 100644 --- a/Firmware/communication/can_simple.cpp +++ b/Firmware/communication/can_simple.cpp @@ -279,19 +279,19 @@ void CANSimple::get_encoder_count_callback(Axis* axis, can_Message_t& msg) { } void CANSimple::set_input_pos_callback(Axis* axis, can_Message_t& msg) { - axis->controller_.input_pos_ = can_getSignal(msg, 0, 32, true); - axis->controller_.input_vel_ = can_getSignal(msg, 32, 16, true, 0.1f, 0); - axis->controller_.input_torque_ = can_getSignal(msg, 48, 16, true, 0.01f, 0); + axis->controller_.input_pos_ = can_getSignal(msg, 0, 32, true); + axis->controller_.input_vel_ = can_getSignal(msg, 32, 16, true, 0.001f, 0); + axis->controller_.input_torque_ = can_getSignal(msg, 48, 16, true, 0.001f, 0); axis->controller_.input_pos_updated(); } void CANSimple::set_input_vel_callback(Axis* axis, can_Message_t& msg) { - axis->controller_.input_vel_ = can_getSignal(msg, 0, 32, true, 0.01f, 0.0f); - axis->controller_.input_torque_ = can_getSignal(msg, 32, 16, true, 0.01f, 0.0f); + axis->controller_.input_vel_ = can_getSignal(msg, 0, 32, true); + axis->controller_.input_torque_ = can_getSignal(msg, 32, 32, true); } void CANSimple::set_input_torque_callback(Axis* axis, can_Message_t& msg) { - axis->controller_.input_torque_ = can_getSignal(msg, 0, 32, true, 0.01f, 0); + axis->controller_.input_torque_ = can_getSignal(msg, 0, 32, true); } void CANSimple::set_controller_modes_callback(Axis* axis, can_Message_t& msg) { diff --git a/docs/can-protocol.md b/docs/can-protocol.md index 8368625a..0b3f0c84 100644 --- a/docs/can-protocol.md +++ b/docs/can-protocol.md @@ -47,9 +47,9 @@ CMD ID | Name | Sender | Signals | Start byte | Signal Type | Bits | Factor | Of 0x009 | Get Encoder Estimates\* | Master | Encoder Pos Estimate
Encoder Vel Estimate | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
32 | 1
1 | 0
0 | Intel
Intel 0x00A | Get Encoder Count\* | Master | Encoder Shadow Count
Encoder Count in CPR | 0
4 | Signed Int
Signed Int | 32
32 | 1
1 | 0
0 | Intel
Intel 0x00B | Set Controller Modes | Master | Control Mode
Input Mode | 0
4 | Signed Int
Signed Int | 32
32 | 1
1 | 0
0 | Intel
Intel -0x00C | Set Input Pos | Master | Input Pos
Vel FF
Current FF | 0
4
6 | Signed Int
Signed Int
Signed Int | 32
16
16 | 1
0.1
0.01 | 0
0
0 | Intel
Intel
Intel -0x00D | Set Input Vel | Master | Input Vel
Current FF | 0
4 | Signed Int
Signed Int | 32
32 | 0.01
0.01 | 0
0 | Intel
Intel -0x00E | Set Input Current | Master | Input Current | 0 | Signed Int | 32 | 0.01 | 0 | Intel +0x00C | Set Input Pos | Master | Input Pos
Vel FF
Torque FF | 0
4
6 | IEEE 754 Float
Signed Int
Signed Int | 32
16
16 | 1
0.001
0.001 | 0
0
0 | Intel
Intel
Intel +0x00D | Set Input Vel | Master | Input Vel
Torque FF | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
32 | 1
1 | 0
0 | Intel
Intel +0x00E | Set Input Torque | Master | Input Torque | 0 | IEEE 754 Float | 32 | 1 | 0 | Intel 0x00F | Set Velocity Limit | Master | Velocity Limit | 0 | IEEE 754 Float | 32 | 1 | 0 | Intel 0x010 | Start Anticogging | Master | - | - | - | - | - | - | - 0x011 | Set Traj Vel Limit | Master | Traj Vel Limit | 0 | IEEE 754 Float | 32 | 1 | 0 | Intel diff --git a/tools/odrive/tests/can_test.py b/tools/odrive/tests/can_test.py index 512076e8..863eaff1 100644 --- a/tools/odrive/tests/can_test.py +++ b/tools/odrive/tests/can_test.py @@ -25,9 +25,9 @@ command_set = { 'get_encoder_estimates': (0x009, [('encoder_pos_estimate', 'f', 1), ('encoder_vel_estimate', 'f', 1)]), # partially tested 'get_encoder_count': (0x00a, [('encoder_shadow_count', 'i', 1), ('encoder_count', 'i', 1)]), # partially tested 'set_controller_modes': (0x00b, [('control_mode', 'i', 1), ('input_mode', 'i', 1)]), # tested - 'set_input_pos': (0x00c, [('input_pos', 'i', 1), ('vel_ff', 'h', 0.1), ('cur_ff', 'h', 0.01)]), # tested - 'set_input_vel': (0x00d, [('input_vel', 'i', 0.01), ('cur_ff', 'h', 0.01)]), # tested - 'set_input_torque': (0x00e, [('input_torque', 'i', 0.01)]), # tested + 'set_input_pos': (0x00c, [('input_pos', 'f', 1), ('vel_ff', 'h', 0.001), ('torque_ff', 'h', 0.001)]), # tested + 'set_input_vel': (0x00d, [('input_vel', 'f', 1), ('torque_ff', 'f', 1)]), # tested + 'set_input_torque': (0x00e, [('input_torque', 'f', 1)]), # tested 'set_velocity_limit': (0x00f, [('velocity_limit', 'f', 1)]), # tested 'start_anticogging': (0x010, []), # untested 'set_traj_vel_limit': (0x011, [('traj_vel_limit', 'f', 1)]), # tested @@ -176,26 +176,26 @@ class TestSimpleCAN(): axis.controller.input_pos = 1234 axis.controller.input_vel = 1234 axis.controller.input_torque = 1234 - my_cmd('set_input_pos', input_pos=1, vel_ff=2, cur_ff=3) + my_cmd('set_input_pos', input_pos=1.23, vel_ff=1.2, torque_ff=3.4) fence() - test_assert_eq(axis.controller.input_pos, 1.0, range=0.1) - test_assert_eq(axis.controller.input_vel, 2.0, range=0.01) - test_assert_eq(axis.controller.input_torque, 3.0, range=0.001) + test_assert_eq(axis.controller.input_pos, 1.23, range=0.1) + test_assert_eq(axis.controller.input_vel, 1.2, range=0.01) + test_assert_eq(axis.controller.input_torque, 3.4, range=0.001) axis.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL - my_cmd('set_input_vel', input_vel=-10.0, cur_ff=30.1234) + my_cmd('set_input_vel', input_vel=-10.5, torque_ff=0.1234) fence() - test_assert_eq(axis.controller.input_vel, -10.0, range=0.01) - test_assert_eq(axis.controller.input_torque, 30.1234, range=0.01) + test_assert_eq(axis.controller.input_vel, -10.5, range=0.01) + test_assert_eq(axis.controller.input_torque, 0.1234, range=0.01) axis.controller.config.control_mode = CONTROL_MODE_TORQUE_CONTROL my_cmd('set_input_torque', input_torque=0.1) fence() test_assert_eq(axis.controller.input_torque, 0.1, range=0.01) - my_cmd('set_velocity_limit', velocity_limit=23456.78) + my_cmd('set_velocity_limit', velocity_limit=2.345678) fence() - test_assert_eq(axis.controller.config.vel_limit, 23456.78, range=0.001) + test_assert_eq(axis.controller.config.vel_limit, 2.345678, range=0.001) my_cmd('set_traj_vel_limit', traj_vel_limit=123.456) fence()