Skip to content

Commit b707cd8

Browse files
committed
CAN baud rate setting fix, spinout detection improvements
1 parent 678c1c9 commit b707cd8

4 files changed

Lines changed: 7 additions & 8 deletions

File tree

Firmware/MotorControl/controller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ bool Controller::update() {
367367
float ideal_electrical_power = 0.0f;
368368
if (axis_->motor_.config_.motor_type != Motor::MOTOR_TYPE_GIMBAL) {
369369
ideal_electrical_power = axis_->motor_.current_control_.power_ - \
370-
axis_->motor_.current_control_.Iq_measured_ * axis_->motor_.current_control_.Iq_measured_ * axis_->motor_.config_.phase_resistance - \
371-
axis_->motor_.current_control_.Id_measured_ * axis_->motor_.current_control_.Id_measured_ * axis_->motor_.config_.phase_resistance;
370+
SQ(axis_->motor_.current_control_.Iq_measured_) * 1.5f * axis_->motor_.config_.phase_resistance - \
371+
SQ(axis_->motor_.current_control_.Id_measured_) * 1.5f * axis_->motor_.config_.phase_resistance;
372372
}
373373
else {
374374
ideal_electrical_power = axis_->motor_.current_control_.power_;

Firmware/MotorControl/foc.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ ODriveIntf::MotorIntf::Error FieldOrientedController::get_alpha_beta_output(
139139
mod_d = V_to_mod * (Vd + v_current_control_integral_d_ + Ierr_d * p_gain);
140140
mod_q = V_to_mod * (Vq + v_current_control_integral_q_ + Ierr_q * p_gain);
141141

142-
// calculate power estimate
143-
power_ = Id * (Vd + v_current_control_integral_d_) + Iq * (Vq + v_current_control_integral_q_);
144-
145142
// Vector modulation saturation, lock integrator if saturated
146143
// TODO make maximum modulation configurable
147144
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(
178175
if (Idq.has_value()) {
179176
auto [Id, Iq] = *Idq;
180177
*ibus = mod_d * Id + mod_q * Iq;
178+
power_ = vbus_voltage * (*ibus).value();
181179
}
182180

183181
return Motor::ERROR_NONE;

Firmware/communication/can/odrive_can.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ODriveCAN : public CanBusBase, public ODriveIntf::CanIntf {
2626
Protocol protocol = PROTOCOL_SIMPLE;
2727

2828
ODriveCAN* parent = nullptr; // set in apply_config()
29-
void set_baud_rate(uint32_t value) { parent->set_baud_rate(baud_rate); }
29+
void set_baud_rate(uint32_t value) { parent->set_baud_rate(value); }
3030
};
3131

3232
ODriveCAN() {}

docs/step-direction.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ This is the simplest possible way of controlling the ODrive. It is also the most
2020
<axis>.config.enable_step_dir = True
2121

2222
4. Enable circular setpoints
23+
2324
<axis>.controller.config.circular_setpoints = True
2425

2526
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: `<odrv>.<axis>.controller.config.circular_setpoint_range` and `<odrv>.<axis>.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
2627

2728
```
28-
<odrv>.<axis>.controller.config.circular_setpoint_range = 1.0
29-
<odrv>.<axis>.controller.config.steps_per_circular_range = 1024
29+
<odrv>.<axis>.controller.config.circular_setpoint_range = 1.0 [turns]
30+
<odrv>.<axis>.controller.config.steps_per_circular_range = 1024 [steps]
3031
```
3132

3233
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.

0 commit comments

Comments
 (0)