Current and speed setting for all variants
This commit is contained in:
parent
4cc02fddc1
commit
11ab848103
21
Inc/config.h
21
Inc/config.h
|
@ -135,8 +135,8 @@
|
||||||
#define TRQ_MODE 3 // [-] TORQUE mode
|
#define TRQ_MODE 3 // [-] TORQUE mode
|
||||||
|
|
||||||
// Enable/Disable Motor
|
// Enable/Disable Motor
|
||||||
//#define MOTOR_LEFT_ENA // [-] Enable LEFT 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
|
#define MOTOR_RIGHT_ENA // [-] Enable RIGHT motor. Comment-out if this motor is not needed to be operational
|
||||||
|
|
||||||
// Control selections
|
// Control selections
|
||||||
#define CTRL_TYP_SEL FOC_CTRL // [-] Control type selection: COM_CTRL, SIN_CTRL, FOC_CTRL (default)
|
#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 FILTER 3276 // 0.05f
|
||||||
#define SPEED_COEFFICIENT 8192 // 0.5f
|
#define SPEED_COEFFICIENT 8192 // 0.5f
|
||||||
#define STEER_COEFFICIENT 62259 // -0.2f
|
#define STEER_COEFFICIENT 62259 // -0.2f
|
||||||
|
#define DEBUG_SERIAL_USART2 // left sensor cable debug
|
||||||
// #define SUPPORT_BUTTONS // Define for Nunchuck buttons support
|
// #define SUPPORT_BUTTONS // Define for Nunchuck buttons support
|
||||||
#endif
|
#endif
|
||||||
// ############################# END OF VARIANT_NUNCHUK SETTINGS #########################
|
// ############################# 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_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!
|
// #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)
|
// 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_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)
|
#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 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_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!
|
#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)
|
// 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_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)
|
#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_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 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.
|
// #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
|
#endif
|
||||||
// ############################# END OF VARIANT_SKATEBOARD SETTINGS ############################
|
// ############################# END OF VARIANT_SKATEBOARD SETTINGS ############################
|
||||||
|
|
||||||
|
|
40
Src/util.c
40
Src/util.c
|
@ -464,7 +464,7 @@ void adcCalibLim(void) {
|
||||||
HAL_Delay(5);
|
HAL_Delay(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_Delay(50);
|
HAL_Delay(10);
|
||||||
|
|
||||||
uint16_t input_margin = 0;
|
uint16_t input_margin = 0;
|
||||||
#ifdef CONTROL_ADC
|
#ifdef CONTROL_ADC
|
||||||
|
@ -489,7 +489,7 @@ void adcCalibLim(void) {
|
||||||
consoleLog("Input1 is a mid-resting pot");
|
consoleLog("Input1 is a mid-resting pot");
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_Delay(50);
|
HAL_Delay(10);
|
||||||
#ifdef CONTROL_ADC
|
#ifdef CONTROL_ADC
|
||||||
if ( (INPUT1_MIN_CAL - ADC_PROTECT_THRESH) > 0 && (INPUT1_MAX_CAL + ADC_PROTECT_THRESH) < 4095){
|
if ( (INPUT1_MIN_CAL - ADC_PROTECT_THRESH) > 0 && (INPUT1_MAX_CAL + ADC_PROTECT_THRESH) < 4095){
|
||||||
consoleLog(" and protected");
|
consoleLog(" and protected");
|
||||||
|
@ -498,9 +498,9 @@ void adcCalibLim(void) {
|
||||||
input_cal_valid = 1;
|
input_cal_valid = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_Delay(50);
|
HAL_Delay(10);
|
||||||
consoleLog("\n");
|
consoleLog("\n");
|
||||||
HAL_Delay(50);
|
HAL_Delay(10);
|
||||||
|
|
||||||
threshold = (INPUT2_MAX - INPUT2_MIN) / 10;
|
threshold = (INPUT2_MAX - INPUT2_MIN) / 10;
|
||||||
INPUT2_MIN_CAL = INPUT2_MIN_temp + input_margin;
|
INPUT2_MIN_CAL = INPUT2_MIN_temp + input_margin;
|
||||||
|
@ -520,7 +520,7 @@ void adcCalibLim(void) {
|
||||||
consoleLog("Input2 is a mid-resting pot");
|
consoleLog("Input2 is a mid-resting pot");
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_Delay(50);
|
HAL_Delay(10);
|
||||||
|
|
||||||
#ifdef CONTROL_ADC
|
#ifdef CONTROL_ADC
|
||||||
if ( (INPUT2_MIN_CAL - ADC_PROTECT_THRESH) > 0 && (INPUT2_MAX_CAL + ADC_PROTECT_THRESH) < 4095 ){
|
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;
|
input_cal_valid = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_Delay(50);
|
HAL_Delay(10);
|
||||||
consoleLog("\n");
|
consoleLog("\n");
|
||||||
HAL_Delay(50);
|
HAL_Delay(10);
|
||||||
consoleLog("Saved limits\n");
|
consoleLog("Saved limits\n");
|
||||||
HAL_Delay(50);
|
HAL_Delay(10);
|
||||||
setScopeChannel(0, (int16_t)INPUT1_MIN_CAL);
|
setScopeChannel(0, (int16_t)INPUT1_MIN_CAL);
|
||||||
setScopeChannel(1, (int16_t)INPUT1_MID_CAL);
|
setScopeChannel(1, (int16_t)INPUT1_MID_CAL);
|
||||||
setScopeChannel(2, (int16_t)INPUT1_MAX_CAL);
|
setScopeChannel(2, (int16_t)INPUT1_MAX_CAL);
|
||||||
|
@ -545,7 +545,8 @@ void adcCalibLim(void) {
|
||||||
setScopeChannel(7, (int16_t)0);
|
setScopeChannel(7, (int16_t)0);
|
||||||
consoleScope();
|
consoleScope();
|
||||||
|
|
||||||
HAL_Delay(50);
|
HAL_Delay(20);
|
||||||
|
consoleLog("OK\n");
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -565,7 +566,7 @@ void updateCurSpdLim(void) {
|
||||||
|
|
||||||
#if !defined(VARIANT_HOVERBOARD) && !defined(VARIANT_TRANSPOTTER)
|
#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 input1_fixdt = cmd1_in << 16;
|
||||||
int32_t input2_fixdt = cmd2_in << 16;
|
int32_t input2_fixdt = cmd2_in << 16;
|
||||||
|
@ -582,14 +583,29 @@ void updateCurSpdLim(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate scaling factors
|
// 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
|
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 - (INPUT2_MIN_CAL << 16)) / (INPUT2_MAX_CAL - INPUT2_MIN_CAL), 3276, 65535); // ADC2, MIN_spd(5%) = 50 rpm
|
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
|
// 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.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_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.i_max = rtP_Left.i_max;
|
||||||
rtP_Right.n_max = rtP_Left.n_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;
|
cur_spd_valid = 1;
|
||||||
consoleLog("OK\n");
|
consoleLog("OK\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue