From 161651ae484dd5dfccda5370f8a6c9ba59406e02 Mon Sep 17 00:00:00 2001 From: Paul Guenette Date: Wed, 22 Nov 2017 21:11:38 -0500 Subject: [PATCH] Move max_allowed_current to current_control struct --- Firmware/MotorControl/low_level.c | 10 +++++----- Firmware/MotorControl/low_level.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Firmware/MotorControl/low_level.c b/Firmware/MotorControl/low_level.c index 79617b44..a4fe5379 100644 --- a/Firmware/MotorControl/low_level.c +++ b/Firmware/MotorControl/low_level.c @@ -104,6 +104,7 @@ Motor_t motors[] = { .final_v_alpha = 0.0f, .final_v_beta = 0.0f, .Iq = 0.0f, + .max_allowed_current = 0.0f, }, // .rotor_mode = ROTOR_MODE_SENSORLESS, // .rotor_mode = ROTOR_MODE_RUN_ENCODER_TEST_SENSORLESS, @@ -144,7 +145,6 @@ Motor_t motors[] = { .calib_pos_threshold = 1.0f, .calib_vel_threshold = 1.0f, }, - .max_allowed_current = 0.0f, }, { // M1 .control_mode = CTRL_MODE_POSITION_CONTROL, //see: Motor_control_mode_t @@ -197,6 +197,7 @@ Motor_t motors[] = { .final_v_alpha = 0.0f, .final_v_beta = 0.0f, .Iq = 0.0f, + .max_allowed_current = 0.0f, }, .rotor_mode = ROTOR_MODE_ENCODER, .encoder = { @@ -234,8 +235,7 @@ Motor_t motors[] = { .calib_anticogging = false, .calib_pos_threshold = 1.0f, .calib_vel_threshold = 1.0f, - }, - .max_allowed_current = 0.0f, + } } }; const int num_motors = sizeof(motors)/sizeof(motors[0]); @@ -422,7 +422,7 @@ static void DRV8301_setup(Motor_t* motor) { float margin = 0.95f; float max_input = margin * 0.3f * motor->shunt_conductance; float max_swing = margin * 1.6f * motor->shunt_conductance * motor->phase_current_rev_gain; - motor->max_allowed_current = MACRO_MIN(max_input, max_swing); + motor->current_control.max_allowed_current = MACRO_MIN(max_input, max_swing); local_regs->SndCmd = true; DRV8301_writeData(gate_driver, local_regs); @@ -1309,7 +1309,7 @@ static void control_motor_loop(Motor_t* motor) { } // Current limiting - float Ilim = MACRO_MIN(motor->current_control.current_lim, motor->max_allowed_current); + float Ilim = MACRO_MIN(motor->current_control.current_lim, motor->current_control.max_allowed_current); bool limited = false; if (Iq > Ilim) { limited = true; diff --git a/Firmware/MotorControl/low_level.h b/Firmware/MotorControl/low_level.h index 4293f935..4806bbcb 100644 --- a/Firmware/MotorControl/low_level.h +++ b/Firmware/MotorControl/low_level.h @@ -71,6 +71,7 @@ typedef struct { float final_v_alpha; // [V] float final_v_beta; // [V] float Iq; + float max_allowed_current; } Current_control_t; typedef enum { @@ -146,7 +147,6 @@ typedef struct { int timing_log_index; uint16_t timing_log[TIMING_LOG_SIZE]; Anticogging_t anticogging; - float max_allowed_current; } Motor_t; typedef struct{