From 11ab8481030616d4b108b58d4fab4313817a9394 Mon Sep 17 00:00:00 2001 From: Candas1 Date: Fri, 13 Nov 2020 22:31:49 +0100 Subject: [PATCH] Current and speed setting for all variants --- Inc/config.h | 21 +++++++++++++-------- Src/util.c | 42 +++++++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/Inc/config.h b/Inc/config.h index 15da433..449c9fb 100644 --- a/Inc/config.h +++ b/Inc/config.h @@ -135,8 +135,8 @@ #define TRQ_MODE 3 // [-] TORQUE mode // Enable/Disable Motor -//#define MOTOR_LEFT_ENA // [-] Enable LEFT motor. Comment-out if this motor is not needed to be operational -//#define MOTOR_RIGHT_ENA // [-] Enable RIGHT motor. Comment-out if this motor is not needed to be operational +#define MOTOR_LEFT_ENA // [-] Enable LEFT motor. Comment-out if this motor is not needed to be operational +#define MOTOR_RIGHT_ENA // [-] Enable RIGHT motor. Comment-out if this motor is not needed to be operational // Control selections #define CTRL_TYP_SEL FOC_CTRL // [-] Control type selection: COM_CTRL, SIN_CTRL, FOC_CTRL (default) @@ -324,6 +324,7 @@ #define FILTER 3276 // 0.05f #define SPEED_COEFFICIENT 8192 // 0.5f #define STEER_COEFFICIENT 62259 // -0.2f + #define DEBUG_SERIAL_USART2 // left sensor cable debug // #define SUPPORT_BUTTONS // Define for Nunchuck buttons support #endif // ############################# END OF VARIANT_NUNCHUK SETTINGS ######################### @@ -371,6 +372,11 @@ */ #define CONTROL_PWM_LEFT // use RC PWM as input on the LEFT cable. disable DEBUG_SERIAL_USART2! // #define CONTROL_PWM_RIGHT // use RC PWM as input on the RIGHT cable. disable DEBUG_SERIAL_USART3! + #ifdef CONTROL_PWM_RIGHT + #define DEBUG_SERIAL_USART2 // left sensor cable debug + #else + #define DEBUG_SERIAL_USART3 // right sensor cable debug + #endif // Min / Max values of each channel (use DEBUG to determine these values) #define INPUT1_TYPE 2 // 0:Disabled 1:Normal POT 2:Middle Resting Pot #define INPUT1_DEADBAND 100 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0) @@ -519,7 +525,11 @@ #define CTRL_MOD_REQ TRQ_MODE // SKATEBOARD works best in TORQUE Mode //#define CONTROL_PWM_LEFT // use RC PWM as input on the LEFT cable. disable DEBUG_SERIAL_USART2! #define CONTROL_PWM_RIGHT // use RC PWM as input on the RIGHT cable. disable DEBUG_SERIAL_USART3! - + #ifdef CONTROL_PWM_RIGHT + #define DEBUG_SERIAL_USART2 // left sensor cable debug + #else + #define DEBUG_SERIAL_USART3 // right sensor cable debug + #endif // Min / Max values of each channel (use DEBUG to determine these values) #define INPUT1_TYPE 0 // 0:Disabled 1:Normal POT 2:Middle Resting Pot #define INPUT1_DEADBAND 100 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0) @@ -542,11 +552,6 @@ // #define SUPPORT_BUTTONS_LEFT // use left sensor board cable for button inputs. Disable DEBUG_SERIAL_USART2! // #define SUPPORT_BUTTONS_RIGHT // use right sensor board cable for button inputs. Disable DEBUG_SERIAL_USART3! // #define STANDSTILL_HOLD_ENABLE // [-] Flag to hold the position when standtill is reached. Only available and makes sense for VOLTAGE or TORQUE mode. - #ifdef CONTROL_PWM_RIGHT - #define DEBUG_SERIAL_USART2 // left sensor cable debug - #else - #define DEBUG_SERIAL_USART3 // right sensor cable debug - #endif #endif // ############################# END OF VARIANT_SKATEBOARD SETTINGS ############################ diff --git a/Src/util.c b/Src/util.c index 6c4352e..87cb14e 100644 --- a/Src/util.c +++ b/Src/util.c @@ -464,7 +464,7 @@ void adcCalibLim(void) { HAL_Delay(5); } - HAL_Delay(50); + HAL_Delay(10); uint16_t input_margin = 0; #ifdef CONTROL_ADC @@ -489,7 +489,7 @@ void adcCalibLim(void) { consoleLog("Input1 is a mid-resting pot"); } - HAL_Delay(50); + HAL_Delay(10); #ifdef CONTROL_ADC if ( (INPUT1_MIN_CAL - ADC_PROTECT_THRESH) > 0 && (INPUT1_MAX_CAL + ADC_PROTECT_THRESH) < 4095){ consoleLog(" and protected"); @@ -498,9 +498,9 @@ void adcCalibLim(void) { input_cal_valid = 1; } - HAL_Delay(50); + HAL_Delay(10); consoleLog("\n"); - HAL_Delay(50); + HAL_Delay(10); threshold = (INPUT2_MAX - INPUT2_MIN) / 10; INPUT2_MIN_CAL = INPUT2_MIN_temp + input_margin; @@ -520,7 +520,7 @@ void adcCalibLim(void) { consoleLog("Input2 is a mid-resting pot"); } - HAL_Delay(50); + HAL_Delay(10); #ifdef CONTROL_ADC if ( (INPUT2_MIN_CAL - ADC_PROTECT_THRESH) > 0 && (INPUT2_MAX_CAL + ADC_PROTECT_THRESH) < 4095 ){ @@ -530,11 +530,11 @@ void adcCalibLim(void) { input_cal_valid = 1; } - HAL_Delay(50); + HAL_Delay(10); consoleLog("\n"); - HAL_Delay(50); + HAL_Delay(10); consoleLog("Saved limits\n"); - HAL_Delay(50); + HAL_Delay(10); setScopeChannel(0, (int16_t)INPUT1_MIN_CAL); setScopeChannel(1, (int16_t)INPUT1_MID_CAL); setScopeChannel(2, (int16_t)INPUT1_MAX_CAL); @@ -545,8 +545,9 @@ void adcCalibLim(void) { setScopeChannel(7, (int16_t)0); consoleScope(); - HAL_Delay(50); - + HAL_Delay(20); + consoleLog("OK\n"); + #endif } @@ -565,7 +566,7 @@ void updateCurSpdLim(void) { #if !defined(VARIANT_HOVERBOARD) && !defined(VARIANT_TRANSPOTTER) - consoleLog("Torque and Speed limits update started... "); + consoleLog("Torque and Speed limits update started...\n"); int32_t input1_fixdt = cmd1_in << 16; int32_t input2_fixdt = cmd2_in << 16; @@ -582,14 +583,29 @@ void updateCurSpdLim(void) { } // Calculate scaling factors - cur_factor = CLAMP((input1_fixdt - (INPUT1_MIN_CAL << 16)) / (INPUT1_MAX_CAL - INPUT1_MIN_CAL), 6553, 65535); // ADC1, MIN_cur(10%) = 1.5 A - spd_factor = CLAMP((input2_fixdt - (INPUT2_MIN_CAL << 16)) / (INPUT2_MAX_CAL - INPUT2_MIN_CAL), 3276, 65535); // ADC2, MIN_spd(5%) = 50 rpm + cur_factor = CLAMP((input1_fixdt - ((int16_t)INPUT1_MIN_CAL << 16)) / ((int16_t)INPUT1_MAX_CAL - (int16_t)INPUT1_MIN_CAL), 6553, 65535); // ADC1, MIN_cur(10%) = 1.5 A + spd_factor = CLAMP((input2_fixdt - ((int16_t)INPUT2_MIN_CAL << 16)) / ((int16_t)INPUT2_MAX_CAL - (int16_t)INPUT2_MIN_CAL), 3276, 65535); // ADC2, MIN_spd(5%) = 50 rpm // Update maximum limits rtP_Left.i_max = (int16_t)((I_MOT_MAX * A2BIT_CONV * cur_factor) >> 12); // fixdt(0,16,16) to fixdt(1,16,4) rtP_Left.n_max = (int16_t)((N_MOT_MAX * spd_factor) >> 12); // fixdt(0,16,16) to fixdt(1,16,4) rtP_Right.i_max = rtP_Left.i_max; rtP_Right.n_max = rtP_Left.n_max; + HAL_Delay(10); + consoleLog("Saved limits\n"); + HAL_Delay(10); + setScopeChannel(0, (int16_t)input1_fixdt); + setScopeChannel(1, (uint16_t)cur_factor); + setScopeChannel(2, (int16_t)rtP_Right.i_max); + setScopeChannel(3, (int16_t)0); + setScopeChannel(4, (int16_t)input2_fixdt); + setScopeChannel(5, (uint16_t)spd_factor); + setScopeChannel(6, (int16_t)rtP_Right.n_max); + setScopeChannel(7, (int16_t)0); + consoleScope(); + + HAL_Delay(20); + cur_spd_valid = 1; consoleLog("OK\n"); #endif