From b707cd870f32e3d05d768df3285ef2d39b5c6578 Mon Sep 17 00:00:00 2001 From: PAJohnson Date: Thu, 13 May 2021 23:21:48 -0400 Subject: [PATCH] CAN baud rate setting fix, spinout detection improvements --- Firmware/MotorControl/controller.cpp | 4 ++-- Firmware/MotorControl/foc.cpp | 4 +--- Firmware/communication/can/odrive_can.hpp | 2 +- docs/step-direction.md | 5 +++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Firmware/MotorControl/controller.cpp b/Firmware/MotorControl/controller.cpp index 4941cac5..c94fdfa0 100644 --- a/Firmware/MotorControl/controller.cpp +++ b/Firmware/MotorControl/controller.cpp @@ -367,8 +367,8 @@ bool Controller::update() { float ideal_electrical_power = 0.0f; if (axis_->motor_.config_.motor_type != Motor::MOTOR_TYPE_GIMBAL) { ideal_electrical_power = axis_->motor_.current_control_.power_ - \ - axis_->motor_.current_control_.Iq_measured_ * axis_->motor_.current_control_.Iq_measured_ * axis_->motor_.config_.phase_resistance - \ - axis_->motor_.current_control_.Id_measured_ * axis_->motor_.current_control_.Id_measured_ * axis_->motor_.config_.phase_resistance; + SQ(axis_->motor_.current_control_.Iq_measured_) * 1.5f * axis_->motor_.config_.phase_resistance - \ + SQ(axis_->motor_.current_control_.Id_measured_) * 1.5f * axis_->motor_.config_.phase_resistance; } else { ideal_electrical_power = axis_->motor_.current_control_.power_; diff --git a/Firmware/MotorControl/foc.cpp b/Firmware/MotorControl/foc.cpp index c02e474d..46fc8e00 100644 --- a/Firmware/MotorControl/foc.cpp +++ b/Firmware/MotorControl/foc.cpp @@ -139,9 +139,6 @@ ODriveIntf::MotorIntf::Error FieldOrientedController::get_alpha_beta_output( mod_d = V_to_mod * (Vd + v_current_control_integral_d_ + Ierr_d * p_gain); mod_q = V_to_mod * (Vq + v_current_control_integral_q_ + Ierr_q * p_gain); - // calculate power estimate - power_ = Id * (Vd + v_current_control_integral_d_) + Iq * (Vq + v_current_control_integral_q_); - // Vector modulation saturation, lock integrator if saturated // TODO make maximum modulation configurable float mod_scalefactor = 0.80f * sqrt3_by_2 * 1.0f / std::sqrt(mod_d * mod_d + mod_q * mod_q); @@ -178,6 +175,7 @@ ODriveIntf::MotorIntf::Error FieldOrientedController::get_alpha_beta_output( if (Idq.has_value()) { auto [Id, Iq] = *Idq; *ibus = mod_d * Id + mod_q * Iq; + power_ = vbus_voltage * (*ibus).value(); } return Motor::ERROR_NONE; diff --git a/Firmware/communication/can/odrive_can.hpp b/Firmware/communication/can/odrive_can.hpp index 8c2ba24c..5910c730 100644 --- a/Firmware/communication/can/odrive_can.hpp +++ b/Firmware/communication/can/odrive_can.hpp @@ -26,7 +26,7 @@ public: Protocol protocol = PROTOCOL_SIMPLE; ODriveCAN* parent = nullptr; // set in apply_config() - void set_baud_rate(uint32_t value) { parent->set_baud_rate(baud_rate); } + void set_baud_rate(uint32_t value) { parent->set_baud_rate(value); } }; ODriveCAN() {} diff --git a/docs/step-direction.md b/docs/step-direction.md index 2233ae3a..f428379e 100644 --- a/docs/step-direction.md +++ b/docs/step-direction.md @@ -20,13 +20,14 @@ This is the simplest possible way of controlling the ODrive. It is also the most .config.enable_step_dir = True 4. Enable circular setpoints + .controller.config.circular_setpoints = True Circular setpoints are used to keep floating point error at a manageable error for systems where the motor can rotate large amounts. If the motor is commanded out of the circular range, the position setpoint automatically wraps around to stay in the range. Two parameters are used to control this behavior: `..controller.config.circular_setpoint_range` and `..controller.config.steps_per_circular_range`. The circular setpoint range sets the operating range of input_pos, starting at 0.0. The `steps per circular range` setting controls how many steps are needed to traverse the entire range. For example, to use 1024 steps per 1 full motor turn, set ``` -..controller.config.circular_setpoint_range = 1.0 -..controller.config.steps_per_circular_range = 1024 +..controller.config.circular_setpoint_range = 1.0 [turns] +..controller.config.steps_per_circular_range = 1024 [steps] ``` The circular range is a floating point value and the steps per circular range parameter is an integer. For best results, set both parameters to powers of 2.