CAN interface reads position estimate from "own" encoder
To Reproduce
Use secondary encoder input with an incremental encoder and use as position/velocity feedback (use hall sensors on primary input) odrv.axis0.controller.config.load_encoder_axis = 1. Home the axis and move to position 0. Motor will move since odrv.axis1.encoder did not reset.
Query the position over CAN and you'll notice an offset when reaching position due to a lower resolution of the hall sensors
Solution
I found a solution but I'm not sure it's the right way to do it. Basically during homing, reset the loaded encoder if it's different from self.
1 file changed, 6 insertions(+)
diff --git a/Firmware/MotorControl/axis.cpp b/Firmware/MotorControl/axis.cpp
index 0f834d0b..2a9336a9 100644
--- a/Firmware/MotorControl/axis.cpp
+++ b/Firmware/MotorControl/axis.cpp
@@ -438,6 +438,12 @@ bool Axis::run_homing() {
// Set the current position to 0.
encoder_.set_linear_count(0);
+ // Set loaded encoder position to 0 if used
+ if (controller_.config_.load_encoder_axis != axis_num_ && controller_.config_.load_encoder_axis < AXIS_COUNT)
+ {
+ Axis* ax = &axes[controller_.config_.load_encoder_axis];
+ ax->encoder_.set_linear_count(0);
+ }
controller_.input_pos_ = 0;
controller_.input_pos_updated();
Use InputPort from the controller instead of the OutputPort from the encoder
Describe the bug
To Reproduce
odrv.axis0.controller.config.load_encoder_axis = 1
. Home the axis and move to position 0. Motor will move sinceodrv.axis1.encoder
did not reset.Solution I found a solution but I'm not sure it's the right way to do it. Basically during homing, reset the loaded encoder if it's different from self.
Use
InputPort
from the controller instead of theOutputPort
from the encoderHappy to send a PR if you're happy with the proposals