Hi Wetmelon,
Unfortunately, no. It seems to make no difference.
Liveplotter trace: (turning motor steadily by hand anticlockwise)
This is my full diff from latest devel:
diff --git a/Firmware/MotorControl/encoder.cpp b/Firmware/MotorControl/encoder.cpp
index 2dcb70ba..95dd122b 100644
--- a/Firmware/MotorControl/encoder.cpp
+++ b/Firmware/MotorControl/encoder.cpp
@@ -563,7 +563,7 @@ void Encoder::abs_spi_cb(bool success) {
case MODE_SPI_ABS_AMS: {
uint16_t rawVal = abs_spi_dma_rx_[0];
// check if parity is correct (even) and error flag clear
- if (ams_parity(rawVal) || ((rawVal >> 14) & 1)) {
+ if (ams_parity(rawVal & 0x7FFF) || ((rawVal >> 14) & 1)) {
goto done;
}
pos = rawVal & 0x3fff;
diff --git a/tools/odrive/utils.py b/tools/odrive/utils.py
index 73489130..75e52783 100755
--- a/tools/odrive/utils.py
+++ b/tools/odrive/utils.py
@@ -133,7 +133,7 @@ def oscilloscope_dump(odrv, num_vals, filename='oscilloscope.csv'):
data_rate = 200
plot_rate = 10
-num_samples = 500
+num_samples = 5000
def start_liveplotter(get_var_callback):
"""
Starts a liveplotter.
diff --git a/tools/odrivetool b/tools/odrivetool
index 5d0e9776..4ad9e67a 100755
--- a/tools/odrivetool
+++ b/tools/odrivetool
@@ -157,8 +157,8 @@ try:
# If you want to plot different values, change them here.
# You can plot any number of values concurrently.
cancellation_token = start_liveplotter(lambda: [
- my_odrive.axis0.encoder.pos_estimate,
- my_odrive.axis1.encoder.pos_estimate,
+ my_odrive.axis0.encoder.count_in_cpr/16384.0,
+ my_odrive.axis0.encoder.spi_error_rate,
])
print("Showing plot. Press Ctrl+C to exit.")
For the sake of sanity, I tried commenting out the whole IF statement with the goto, and I got this:
It is as if there really is some flag that is set 50% of the time, and is corrupting the data.
I do have an ST-Link, would it be worth setting up a debugger? Or perhaps I will check my scope traces against the chip’s datasheet to see wtf it is really sending.
Also, I tried a second time (no changes except system power cycle including encoder) and I get this: (motor turning steadily clockwise by hand)
Since i’m getting variable results, I will remove my hack and try your code again, but I don’t think it’s going to work since clearly the position data is wrong.