Skip to content

Commit

Permalink
ODrive receives coupled positions in rad
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyAZ committed Aug 23, 2018
1 parent 7d69747 commit 7feb7ff
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Firmware/MotorControl/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ void Controller::set_current_setpoint(float current_setpoint) {
}

void Controller::set_coupled_setpoints(float theta_setpoint, float gamma_setpoint) {
theta_setpoint_ = theta_setpoint;
gamma_setpoint_ = gamma_setpoint;
theta_setpoint_ = rad_to_encoder(theta_setpoint);
gamma_setpoint_ = rad_to_encoder(gamma_setpoint);
config_.control_mode = CTRL_MODE_COUPLED_CONTROL;
#ifdef DEBUG_PRINT
printf("COUPLED_CONTROL %3.3f %3.3f\n", theta_setpoint_, gamma_setpoint_);
#endif
}

float rad_to_encoder(float theta) {
return theta * axis_->encoder_.config_.cpr * config_.gear_ratio / (2 * M_PI);
}

void Controller::start_anticogging_calibration() {
// Ensure the cogging map was correctly allocated earlier and that the motor is capable of calibrating
if (anticogging_.cogging_map != NULL && axis_->error_ == Axis::ERROR_NONE) {
Expand Down
4 changes: 4 additions & 0 deletions Firmware/MotorControl/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ struct ControllerConfig_t {
float kd_theta = 5.0f / 10000.0f;
float kp_gamma = 15.0f;
float kd_gamma = 5.0f / 10000.0f;

float gear_ratio = 3.0;
};

class Controller {
Expand All @@ -39,6 +41,8 @@ class Controller {
void set_current_setpoint(float current_setpoint);
void set_coupled_setpoints(float theta_setpoint, float gamma_setpoint);

float rad_to_encoder(float theta);

// TODO: make this more similar to other calibration loops
void start_anticogging_calibration();
bool anticogging_calibration(float pos_estimate, float vel_estimate);
Expand Down
5 changes: 5 additions & 0 deletions Firmware/communication/ascii_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ void ASCII_protocol_process_line(const uint8_t* buffer, size_t len, StreamSink&
float theta_sp, gamma_sp;
int result = parseDualCurrent(cmd,theta_sp, gamma_sp);

const float MULTIPLIER = 1000.0;

theta_sp /= MULTIPLIER;
gamma_sp /= MULTIPLIER;

if (result != 1) {
respond(response_channel, use_checksum, "Failed on parse or checksum: ");
respond(response_channel, use_checksum, cmd);
Expand Down
2 changes: 1 addition & 1 deletion Firmware/tup.config.default
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copy this file to tup.config and adapt it to your needs
# make sure this fits your board
#CONFIG_BOARD_VERSION=v3.5-24V
#CONFIG_BOARD_VERSION=v3.5-48V
CONFIG_USB_PROTOCOL=native
CONFIG_UART_PROTOCOL=ascii

Expand Down

0 comments on commit 7feb7ff

Please sign in to comment.