diff --git a/Firmware/MotorControl/controller.cpp b/Firmware/MotorControl/controller.cpp index 70324f655..11c85b458 100644 --- a/Firmware/MotorControl/controller.cpp +++ b/Firmware/MotorControl/controller.cpp @@ -1,6 +1,7 @@ #include "odrive_main.h" #include +#include bool Controller::apply_config() { config_.parent = this; @@ -53,6 +54,20 @@ void Controller::start_anticogging_calibration() { } } +float Controller::remove_anticogging_bias() +{ + auto& cogmap = config_.anticogging.cogging_map; + + auto sum = std::accumulate(std::begin(cogmap), std::end(cogmap), 0.0f); + auto average = sum / std::size(cogmap); + + for(auto& val : cogmap) { + val -= average; + } + + return average; +} + /* * This anti-cogging implementation iterates through each encoder position, diff --git a/Firmware/MotorControl/controller.hpp b/Firmware/MotorControl/controller.hpp index 7a7d8acf9..2b78d6c58 100644 --- a/Firmware/MotorControl/controller.hpp +++ b/Firmware/MotorControl/controller.hpp @@ -81,6 +81,7 @@ class Controller : public ODriveIntf::ControllerIntf { // TODO: make this more similar to other calibration loops void start_anticogging_calibration(); + float remove_anticogging_bias(); bool anticogging_calibration(float pos_estimate, float vel_estimate); float get_anticogging_value(uint32_t index) { diff --git a/Firmware/odrive-interface.yaml b/Firmware/odrive-interface.yaml index 5ece87565..34cb09d06 100644 --- a/Firmware/odrive-interface.yaml +++ b/Firmware/odrive-interface.yaml @@ -1196,6 +1196,7 @@ interfaces: usually corresponds roughly to the current position of the axis.' } start_anticogging_calibration: + remove_anticogging_bias: {out: {val: float32}} get_anticogging_value: {in: {index: uint32}, out: {val: float32}}