427
Inc/config.h
|
@ -120,7 +120,7 @@
|
||||||
* 3. If you re-calibrate the Field Weakening please take all the safety measures! The motors can spin very fast!
|
* 3. If you re-calibrate the Field Weakening please take all the safety measures! The motors can spin very fast!
|
||||||
|
|
||||||
Inputs:
|
Inputs:
|
||||||
- cmd1 and cmd2: analog normalized input values. INPUT_MIN to INPUT_MAX
|
- input1[inIdx].cmd and input2[inIdx].cmd: normalized input values. INPUT_MIN to INPUT_MAX
|
||||||
- button1 and button2: digital input values. 0 or 1
|
- button1 and button2: digital input values. 0 or 1
|
||||||
- adc_buffer.l_tx2 and adc_buffer.l_rx2: unfiltered ADC values (you do not need them). 0 to 4095
|
- adc_buffer.l_tx2 and adc_buffer.l_rx2: unfiltered ADC values (you do not need them). 0 to 4095
|
||||||
Outputs:
|
Outputs:
|
||||||
|
@ -169,7 +169,9 @@
|
||||||
// Default settings will be applied at the end of this config file if not set before
|
// Default settings will be applied at the end of this config file if not set before
|
||||||
#define INACTIVITY_TIMEOUT 8 // Minutes of not driving until poweroff. it is not very precise.
|
#define INACTIVITY_TIMEOUT 8 // Minutes of not driving until poweroff. it is not very precise.
|
||||||
#define BEEPS_BACKWARD 1 // 0 or 1
|
#define BEEPS_BACKWARD 1 // 0 or 1
|
||||||
#define FLASH_WRITE_KEY 0x1233 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
#define ADC_MARGIN 100 // ADC input margin applied on the raw ADC min and max to make sure the MIN and MAX values are reached even in the presence of noise
|
||||||
|
#define ADC_PROTECT_TIMEOUT 100 // ADC Protection: number of wrong / missing input commands before safety state is taken
|
||||||
|
#define ADC_PROTECT_THRESH 200 // ADC Protection threshold below/above the MIN/MAX ADC values
|
||||||
|
|
||||||
/* FILTER is in fixdt(0,16,16): VAL_fixedPoint = VAL_floatingPoint * 2^16. In this case 6553 = 0.1 * 2^16
|
/* FILTER is in fixdt(0,16,16): VAL_fixedPoint = VAL_floatingPoint * 2^16. In this case 6553 = 0.1 * 2^16
|
||||||
* Value of COEFFICIENT is in fixdt(1,16,14)
|
* Value of COEFFICIENT is in fixdt(1,16,14)
|
||||||
|
@ -185,6 +187,24 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ############################## INPUT FORMAT ############################
|
||||||
|
/* ***_INPUT: TYPE, MIN, MID, MAX, DEADBAND
|
||||||
|
* -----------------------------------------
|
||||||
|
* TYPE: 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
||||||
|
* MIN: min ADC1-value while poti at minimum-position (0 - 4095)
|
||||||
|
* MID: mid ADC1-value while poti at mid-position (INPUT_MIN - INPUT_MAX)
|
||||||
|
* MAX: max ADC2-value while poti at maximum-position (0 - 4095)
|
||||||
|
* DEADBAND: how much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
||||||
|
*
|
||||||
|
* Dual-inputs
|
||||||
|
* PRI_INPUT: Primary Input. These limits will be used for the input with priority 0
|
||||||
|
* AUX_INPUT: Auxiliary Input. These limits will be used for the input with priority 1
|
||||||
|
* -----------------------------------------
|
||||||
|
*/
|
||||||
|
// ############################## END OF INPUT FORMAT ############################
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ############################## CRUISE CONTROL SETTINGS ############################
|
// ############################## CRUISE CONTROL SETTINGS ############################
|
||||||
/* Cruise Control info:
|
/* Cruise Control info:
|
||||||
* enable CRUISE_CONTROL_SUPPORT and (SUPPORT_BUTTONS_LEFT or SUPPORT_BUTTONS_RIGHT depending on which cable is the button installed)
|
* enable CRUISE_CONTROL_SUPPORT and (SUPPORT_BUTTONS_LEFT or SUPPORT_BUTTONS_RIGHT depending on which cable is the button installed)
|
||||||
|
@ -210,10 +230,10 @@
|
||||||
* DEBUG_SERIAL_ASCII output is:
|
* DEBUG_SERIAL_ASCII output is:
|
||||||
* // "in1:345 in2:1337 cmdL:0 cmdR:0 BatADC:0 BatV:0 TempADC:0 Temp:0\r\n"
|
* // "in1:345 in2:1337 cmdL:0 cmdR:0 BatADC:0 BatV:0 TempADC:0 Temp:0\r\n"
|
||||||
*
|
*
|
||||||
* in1: (int16_t)input1); raw input1: ADC1, UART, PWM, PPM, iBUS
|
* in1: (int16_t)input1[inIdx].raw); raw input1: ADC1, UART, PWM, PPM, iBUS
|
||||||
* in2: (int16_t)input2); raw input2: ADC2, UART, PWM, PPM, iBUS
|
* in2: (int16_t)input2[inIdx].raw); raw input2: ADC2, UART, PWM, PPM, iBUS
|
||||||
* cmdL: (int16_t)speedL); output command: [-1000, 1000]
|
* cmdL: (int16_t)cmdL); output command Left: [-1000, 1000]
|
||||||
* cmdR: (int16_t)speedR); output command: [-1000, 1000]
|
* cmdR: (int16_t)cmdR); output command Right: [-1000, 1000]
|
||||||
* BatADC: (int16_t)adc_buffer.batt1); Battery adc-value measured by mainboard
|
* BatADC: (int16_t)adc_buffer.batt1); Battery adc-value measured by mainboard
|
||||||
* BatV: (int16_t)(batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC)); Battery calibrated voltage multiplied by 100 for verifying battery voltage calibration
|
* BatV: (int16_t)(batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC)); Battery calibrated voltage multiplied by 100 for verifying battery voltage calibration
|
||||||
* TempADC: (int16_t)board_temp_adcFilt); for board temperature calibration
|
* TempADC: (int16_t)board_temp_adcFilt); for board temperature calibration
|
||||||
|
@ -250,26 +270,27 @@
|
||||||
* Procedure:
|
* Procedure:
|
||||||
* - connect gnd, rx and tx of a usb-uart converter in 3.3V mode to the right sensor board cable (do NOT use the red 15V wire!)
|
* - connect gnd, rx and tx of a usb-uart converter in 3.3V mode to the right sensor board cable (do NOT use the red 15V wire!)
|
||||||
* - readout values using a serial terminal in 115200 baud rate
|
* - readout values using a serial terminal in 115200 baud rate
|
||||||
* - turn the potis to minimum position, write value 1 to INPUT1_MIN and value 2 to INPUT2_MIN
|
* - turn the potis to minimum position, write value in1 to PRI_INPUT1 MIN and value in2 to PRI_INPUT2 MIN
|
||||||
* - turn the potis to maximum position, write value 1 to INPUT1_MAX and value 2 to INPUT2_MAX
|
* - turn the potis to maximum position, write value in1 to PRI_INPUT1 MAX and value in2 to PRI_INPUT2 MAX
|
||||||
* - for middle resting potis: Let the potis in the middle resting position, write value 1 to INPUT1_MID and value 2 to INPUT2_MID
|
* - for middle resting potis: Let the potis in the middle resting position, write value in1 to PRI_INPUT1 MID and value in2 to PRI_INPUT2 MID
|
||||||
*/
|
*/
|
||||||
#define CONTROL_ADC // use ADC as input. disable CONTROL_SERIAL_USART2, FEEDBACK_SERIAL_USART2, DEBUG_SERIAL_USART2!
|
#define CONTROL_ADC 0 // use ADC as input. Number indicates priority for dual-input. Disable CONTROL_SERIAL_USART2, FEEDBACK_SERIAL_USART2, DEBUG_SERIAL_USART2!
|
||||||
#define ADC_PROTECT_TIMEOUT 100 // ADC Protection: number of wrong / missing input commands before safety state is taken
|
|
||||||
#define ADC_PROTECT_THRESH 200 // ADC Protection threshold below/above the MIN/MAX ADC values
|
// #define DUAL_INPUTS // ADC*(Primary) + UART(Auxiliary). Uncomment this to use Dual-inputs
|
||||||
#define INPUT1_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
#define PRI_INPUT1 3, 0, 0, 4095, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#define INPUT1_MIN 0 // min ADC1-value while poti at min-position (0 - 4095)
|
#define PRI_INPUT2 3, 0, 0, 4095, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#define INPUT1_MID 0 // mid ADC1-value while poti at mid-position (INPUT1_MIN - INPUT1_MAX)
|
#ifdef DUAL_INPUTS
|
||||||
#define INPUT1_MAX 4095 // max ADC1-value while poti at max-position (0 - 4095)
|
#define FLASH_WRITE_KEY 0x1101 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
#define INPUT1_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
// #define SIDEBOARD_SERIAL_USART3 1
|
||||||
|
#define CONTROL_SERIAL_USART3 1 // right sensor board cable. Number indicates priority for dual-input. Disable if I2C (nunchuk or lcd) is used! For Arduino control check the hoverSerial.ino
|
||||||
#define INPUT2_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
#define FEEDBACK_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!
|
||||||
#define INPUT2_MIN 0 // min ADC2-value while poti at min-position (0 - 4095)
|
#define AUX_INPUT1 3, -1000, 0, 1000, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#define INPUT2_MID 0 // mid ADC2-value while poti at mid-position (INPUT2_MIN - INPUT2_MAX)
|
#define AUX_INPUT2 3, -1000, 0, 1000, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#define INPUT2_MAX 4095 // max ADC2-value while poti at max-position (0 - 4095)
|
#else
|
||||||
#define INPUT2_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
#define FLASH_WRITE_KEY 0x1001 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
|
#define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!
|
||||||
|
#endif
|
||||||
|
|
||||||
#define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!
|
|
||||||
// #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!
|
||||||
#endif
|
#endif
|
||||||
|
@ -279,25 +300,27 @@
|
||||||
|
|
||||||
// ############################ VARIANT_USART SETTINGS ############################
|
// ############################ VARIANT_USART SETTINGS ############################
|
||||||
#ifdef VARIANT_USART
|
#ifdef VARIANT_USART
|
||||||
// #define SIDEBOARD_SERIAL_USART2
|
// #define SIDEBOARD_SERIAL_USART2 0
|
||||||
// #define CONTROL_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used! For Arduino control check the hoverSerial.ino
|
#define CONTROL_SERIAL_USART2 0 // left sensor board cable, disable if ADC or PPM is used! For Arduino control check the hoverSerial.ino
|
||||||
// #define FEEDBACK_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used!
|
#define FEEDBACK_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used!
|
||||||
|
|
||||||
|
// #define SIDEBOARD_SERIAL_USART3 0
|
||||||
|
// #define CONTROL_SERIAL_USART3 0 // right sensor board cable. Number indicates priority for dual-input. Disable if I2C (nunchuk or lcd) is used! For Arduino control check the hoverSerial.ino
|
||||||
|
// #define FEEDBACK_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!
|
||||||
|
|
||||||
|
// #define DUAL_INPUTS // UART*(Primary) + SIDEBOARD(Auxiliary). Uncomment this to use Dual-inputs
|
||||||
|
#define PRI_INPUT1 3, -1000, 0, 1000, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define PRI_INPUT2 3, -1000, 0, 1000, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#ifdef DUAL_INPUTS
|
||||||
|
#define FLASH_WRITE_KEY 0x1102 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
|
// #define SIDEBOARD_SERIAL_USART2 1 // left sideboard
|
||||||
|
#define SIDEBOARD_SERIAL_USART3 1 // right sideboard
|
||||||
|
#define AUX_INPUT1 3, -1000, 0, 1000, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define AUX_INPUT2 3, -1000, 0, 1000, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#else
|
||||||
|
#define FLASH_WRITE_KEY 0x1002 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
|
#endif
|
||||||
|
|
||||||
// #define SIDEBOARD_SERIAL_USART3
|
|
||||||
#define CONTROL_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used! For Arduino control check the hoverSerial.ino
|
|
||||||
#define FEEDBACK_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!
|
|
||||||
// Min / Max values of each channel (use DEBUG to determine these values)
|
|
||||||
#define INPUT1_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
|
||||||
#define INPUT1_MIN -1000 // (-1000 - 0)
|
|
||||||
#define INPUT1_MID 0
|
|
||||||
#define INPUT1_MAX 1000 // (0 - 1000)
|
|
||||||
#define INPUT1_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
|
||||||
|
|
||||||
#define INPUT2_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
|
||||||
#define INPUT2_MIN -1000 // (-1000 - 0)
|
|
||||||
#define INPUT2_MID 0
|
|
||||||
#define INPUT2_MAX 1000 // (0 - 1000)
|
|
||||||
#define INPUT2_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
|
||||||
// #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!
|
||||||
#endif
|
#endif
|
||||||
|
@ -313,25 +336,28 @@
|
||||||
* use original nunchuk. most clones does not work very well.
|
* use original nunchuk. most clones does not work very well.
|
||||||
* Recommendation: Nunchuk Breakout Board https://github.com/Jan--Henrik/hoverboard-breakout
|
* Recommendation: Nunchuk Breakout Board https://github.com/Jan--Henrik/hoverboard-breakout
|
||||||
*/
|
*/
|
||||||
#define CONTROL_NUNCHUK // use nunchuk as input. disable FEEDBACK_SERIAL_USART3, DEBUG_SERIAL_USART3!
|
#define CONTROL_NUNCHUK 0 // use nunchuk as input. Number indicates priority for dual-input. Disable FEEDBACK_SERIAL_USART3, DEBUG_SERIAL_USART3!
|
||||||
// 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, 3:Auto-detect
|
// #define DUAL_INPUTS // Nunchuk*(Primary) + UART(Auxiliary). Uncomment this to use Dual-inputs
|
||||||
#define INPUT1_MIN -1024 // (-1024 - 0)
|
#define PRI_INPUT1 2, -1024, 0, 1024, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#define INPUT1_MID 0
|
#define PRI_INPUT2 2, -1024, 0, 1024, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#define INPUT1_MAX 1024 // (0 - 1024)
|
#ifdef DUAL_INPUTS
|
||||||
#define INPUT1_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
#define FLASH_WRITE_KEY 0x1103 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
|
// #define SIDEBOARD_SERIAL_USART2 1
|
||||||
#define INPUT2_TYPE 2 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
#define CONTROL_SERIAL_USART2 1 // left sensor board cable, disable if ADC or PPM is used! For Arduino control check the hoverSerial.ino
|
||||||
#define INPUT2_MIN -1024 // (-1024 - 0)
|
#define FEEDBACK_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used!
|
||||||
#define INPUT2_MID 0
|
#define AUX_INPUT1 3, -1000, 0, 1000, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#define INPUT2_MAX 1024 // (0 - 1024)
|
#define AUX_INPUT2 3, -1000, 0, 1000, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#define INPUT2_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
#else
|
||||||
|
#define FLASH_WRITE_KEY 0x1003 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
|
#define DEBUG_SERIAL_USART2 // left sensor cable debug
|
||||||
|
#endif
|
||||||
|
|
||||||
// # maybe good for ARMCHAIR #
|
// # maybe good for ARMCHAIR #
|
||||||
#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 Nunchuk buttons support
|
||||||
// #define SUPPORT_BUTTONS // Define for Nunchuck buttons support
|
|
||||||
#endif
|
#endif
|
||||||
// ############################# END OF VARIANT_NUNCHUK SETTINGS #########################
|
// ############################# END OF VARIANT_NUNCHUK SETTINGS #########################
|
||||||
|
|
||||||
|
@ -343,29 +369,33 @@
|
||||||
* Right sensor board cable. Channel 1: steering, Channel 2: speed.
|
* Right sensor board cable. Channel 1: steering, Channel 2: speed.
|
||||||
* https://gist.github.com/peterpoetzi/1b63a4a844162196613871767189bd05
|
* https://gist.github.com/peterpoetzi/1b63a4a844162196613871767189bd05
|
||||||
*/
|
*/
|
||||||
// #define CONTROL_PPM_LEFT // use PPM-Sum as input on the LEFT cable . disable CONTROL_SERIAL_USART2!
|
// #define DUAL_INPUTS // ADC*(Primary) + PPM(Auxiliary). Uncomment this to use Dual-inputs
|
||||||
#define CONTROL_PPM_RIGHT // use PPM-Sum as input on the RIGHT cable. disable CONTROL_SERIAL_USART3!
|
#ifdef DUAL_INPUTS
|
||||||
#ifdef CONTROL_PPM_RIGHT
|
#define FLASH_WRITE_KEY 0x1104 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
#define DEBUG_SERIAL_USART2 // left sensor cable debug
|
#define CONTROL_ADC 0 // use ADC as input. Number indicates priority for dual-input. Disable CONTROL_SERIAL_USART2, FEEDBACK_SERIAL_USART2, DEBUG_SERIAL_USART2!
|
||||||
|
#define CONTROL_PPM_RIGHT 1 // use PPM-Sum as input on the RIGHT cable. Number indicates priority for dual-input. Disable CONTROL_SERIAL_USART3!
|
||||||
|
#define PRI_INPUT1 3, 0, 0, 4095, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define PRI_INPUT2 3, 0, 0, 4095, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define AUX_INPUT1 3, -1000, 0, 1000, 100 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define AUX_INPUT2 3, -1000, 0, 1000, 100 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#else
|
#else
|
||||||
#define DEBUG_SERIAL_USART3 // right sensor cable debug
|
#define FLASH_WRITE_KEY 0x1004 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
|
// #define CONTROL_PPM_LEFT 0 // use PPM-Sum as input on the LEFT cable. Number indicates priority for dual-input. Disable CONTROL_SERIAL_USART2!
|
||||||
|
#define CONTROL_PPM_RIGHT 0 // use PPM-Sum as input on the RIGHT cable. Number indicates priority for dual-input. Disable CONTROL_SERIAL_USART3!
|
||||||
|
#define PRI_INPUT1 3, -1000, 0, 1000, 100 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define PRI_INPUT2 3, -1000, 0, 1000, 100 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#endif
|
||||||
|
#define PPM_NUM_CHANNELS 6 // total number of PPM channels to receive, even if they are not used.
|
||||||
|
|
||||||
|
// #define SUPPORT_BUTTONS // Define for PPM buttons support
|
||||||
|
// #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!
|
||||||
|
|
||||||
|
#if defined(CONTROL_PPM_RIGHT) && !defined(DUAL_INPUTS)
|
||||||
|
#define DEBUG_SERIAL_USART2 // left sensor cable debug
|
||||||
|
#elif defined(CONTROL_PPM_LEFT) && !defined(DUAL_INPUTS)
|
||||||
|
#define DEBUG_SERIAL_USART3 // right sensor cable debug
|
||||||
#endif
|
#endif
|
||||||
#define PPM_NUM_CHANNELS 6 // total number of PPM channels to receive, even if they are not used.
|
|
||||||
// Min / Max values of each channel (use DEBUG to determine these values)
|
|
||||||
#define INPUT1_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
|
||||||
#define INPUT1_MIN -1000 // (-1000 - 0)
|
|
||||||
#define INPUT1_MID 0
|
|
||||||
#define INPUT1_MAX 1000 // (0 - 1000)
|
|
||||||
#define INPUT1_DEADBAND 100 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
|
||||||
|
|
||||||
#define INPUT2_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
|
||||||
#define INPUT2_MIN -1000 // (-1000 - 0)
|
|
||||||
#define INPUT2_MID 0
|
|
||||||
#define INPUT2_MAX 1000 // (0 - 1000)
|
|
||||||
#define INPUT2_DEADBAND 100 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
|
||||||
// #define SUPPORT_BUTTONS // Define for PPM buttons support
|
|
||||||
// #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!
|
|
||||||
#endif
|
#endif
|
||||||
// ############################# END OF VARIANT_PPM SETTINGS ############################
|
// ############################# END OF VARIANT_PPM SETTINGS ############################
|
||||||
|
|
||||||
|
@ -376,33 +406,36 @@
|
||||||
* Right sensor board cable. Connect PA2 to channel 1 and PA3 to channel 2 on receiver.
|
* Right sensor board cable. Connect PA2 to channel 1 and PA3 to channel 2 on receiver.
|
||||||
* Channel 1: steering, Channel 2: speed.
|
* Channel 1: steering, Channel 2: speed.
|
||||||
*/
|
*/
|
||||||
// #define CONTROL_PWM_LEFT // use RC PWM as input on the LEFT cable. disable DEBUG_SERIAL_USART2!
|
// #define DUAL_INPUTS // ADC*(Primary) + PWM(Auxiliary). Uncomment this to use Dual-inputs
|
||||||
#define CONTROL_PWM_RIGHT // use RC PWM as input on the RIGHT cable. disable DEBUG_SERIAL_USART3!
|
#ifdef DUAL_INPUTS
|
||||||
#ifdef CONTROL_PWM_RIGHT
|
#define FLASH_WRITE_KEY 0x1105 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
#define DEBUG_SERIAL_USART2 // left sensor cable debug
|
#define CONTROL_ADC 0 // use ADC as input. Number indicates priority for dual-input. Disable CONTROL_SERIAL_USART2, FEEDBACK_SERIAL_USART2, DEBUG_SERIAL_USART2!
|
||||||
|
#define CONTROL_PWM_RIGHT 1 // use RC PWM as input on the RIGHT cable. Number indicates priority for dual-input. Disable DEBUG_SERIAL_USART3!
|
||||||
|
#define PRI_INPUT1 3, 0, 0, 4095, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define PRI_INPUT2 3, 0, 0, 4095, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define AUX_INPUT1 3, -1000, 0, 1000, 100 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define AUX_INPUT2 3, -1000, 0, 1000, 100 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#else
|
#else
|
||||||
#define DEBUG_SERIAL_USART3 // right sensor cable debug
|
#define FLASH_WRITE_KEY 0x1005 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
|
// #define CONTROL_PWM_LEFT 0 // use RC PWM as input on the LEFT cable. Number indicates priority for dual-input. Disable DEBUG_SERIAL_USART2!
|
||||||
|
#define CONTROL_PWM_RIGHT 0 // use RC PWM as input on the RIGHT cable. Number indicates priority for dual-input. Disable DEBUG_SERIAL_USART3!
|
||||||
|
#define PRI_INPUT1 3, -1000, 0, 1000, 100 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define PRI_INPUT2 3, -1000, 0, 1000, 100 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#endif
|
#endif
|
||||||
// Min / Max values of each channel (use DEBUG to determine these values)
|
|
||||||
#define INPUT1_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
#define FILTER 6553 // 0.1f [-] fixdt(0,16,16) lower value == softer filter [0, 65535] = [0.0 - 1.0].
|
||||||
#define INPUT1_MIN -1000 // (-1000 - 0)
|
#define SPEED_COEFFICIENT 16384 // 1.0f [-] fixdt(1,16,14) higher value == stronger. [0, 65535] = [-2.0 - 2.0]. In this case 16384 = 1.0 * 2^14
|
||||||
#define INPUT1_MID 0
|
#define STEER_COEFFICIENT 16384 // 1.0f [-] fixdt(1,16,14) higher value == stronger. [0, 65535] = [-2.0 - 2.0]. In this case 16384 = 1.0 * 2^14. If you do not want any steering, set it to 0.
|
||||||
#define INPUT1_MAX 1000 // (0 - 1000)
|
|
||||||
#define INPUT1_DEADBAND 100 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
|
||||||
|
|
||||||
#define INPUT2_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
|
||||||
#define INPUT2_MIN -1000 // (-1000 - 0)
|
|
||||||
#define INPUT2_MID 0
|
|
||||||
#define INPUT2_MAX 1000 // (0 - 1000)
|
|
||||||
#define INPUT2_DEADBAND 100 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
|
||||||
|
|
||||||
#define FILTER 6553 // 0.1f [-] fixdt(0,16,16) lower value == softer filter [0, 65535] = [0.0 - 1.0].
|
|
||||||
#define SPEED_COEFFICIENT 16384 // 1.0f [-] fixdt(1,16,14) higher value == stronger. [0, 65535] = [-2.0 - 2.0]. In this case 16384 = 1.0 * 2^14
|
|
||||||
#define STEER_COEFFICIENT 16384 // 1.0f [-] fixdt(1,16,14) higher value == stronger. [0, 65535] = [-2.0 - 2.0]. In this case 16384 = 1.0 * 2^14. If you do not want any steering, set it to 0.
|
|
||||||
// #define INVERT_R_DIRECTION
|
// #define INVERT_R_DIRECTION
|
||||||
// #define INVERT_L_DIRECTION
|
// #define INVERT_L_DIRECTION
|
||||||
// #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!
|
||||||
|
|
||||||
|
#if defined(CONTROL_PWM_RIGHT) && !defined(DUAL_INPUTS)
|
||||||
|
#define DEBUG_SERIAL_USART2 // left sensor cable debug
|
||||||
|
#elif defined(CONTROL_PWM_LEFT) && !defined(DUAL_INPUTS)
|
||||||
|
#define DEBUG_SERIAL_USART3 // right sensor cable debug
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
// ############################# END OF VARIANT_PWM SETTINGS ############################
|
// ############################# END OF VARIANT_PWM SETTINGS ############################
|
||||||
|
|
||||||
|
@ -413,33 +446,35 @@
|
||||||
/* CONTROL VIA RC REMOTE WITH FLYSKY IBUS PROTOCOL
|
/* CONTROL VIA RC REMOTE WITH FLYSKY IBUS PROTOCOL
|
||||||
* Connected to Right sensor board cable. Channel 1: steering, Channel 2: speed.
|
* Connected to Right sensor board cable. Channel 1: steering, Channel 2: speed.
|
||||||
*/
|
*/
|
||||||
#define CONTROL_IBUS // use IBUS as input
|
#define CONTROL_IBUS // use IBUS as input. Number indicates priority for dual-input.
|
||||||
#define IBUS_NUM_CHANNELS 14 // total number of IBUS channels to receive, even if they are not used.
|
#define IBUS_NUM_CHANNELS 14 // total number of IBUS channels to receive, even if they are not used.
|
||||||
#define IBUS_LENGTH 0x20
|
#define IBUS_LENGTH 0x20
|
||||||
#define IBUS_COMMAND 0x40
|
#define IBUS_COMMAND 0x40
|
||||||
|
#define USART3_BAUD 115200
|
||||||
|
|
||||||
#undef USART3_BAUD
|
// #define DUAL_INPUTS // ADC*(Primary) + iBUS(Auxiliary). Uncomment this to use Dual-inputs
|
||||||
#define USART3_BAUD 115200
|
#ifdef DUAL_INPUTS
|
||||||
#define CONTROL_SERIAL_USART3 // right sensor board cable, disable if ADC or PPM is used!
|
#define FLASH_WRITE_KEY 0x1106 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
#define FEEDBACK_SERIAL_USART3 // right sensor board cable, disable if ADC or PPM is used!
|
#define CONTROL_ADC 0 // use ADC as input. Number indicates priority for dual-input. Disable CONTROL_SERIAL_USART2, FEEDBACK_SERIAL_USART2, DEBUG_SERIAL_USART2!
|
||||||
#ifdef CONTROL_SERIAL_USART3
|
#define CONTROL_SERIAL_USART3 1 // use RC iBUS input on the RIGHT cable. Number indicates priority for dual-input. Disable DEBUG_SERIAL_USART3!
|
||||||
#define DEBUG_SERIAL_USART2 // left sensor cable debug
|
#define FEEDBACK_SERIAL_USART3 // right sensor board cable, disable if ADC or PPM is used!
|
||||||
|
#define PRI_INPUT1 3, 0, 0, 4095, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define PRI_INPUT2 3, 0, 0, 4095, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define AUX_INPUT1 3, -1000, 0, 1000, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define AUX_INPUT2 3, -1000, 0, 1000, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#else
|
#else
|
||||||
#define DEBUG_SERIAL_USART3 // right sensor cable debug
|
#define FLASH_WRITE_KEY 0x1006 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
|
#define CONTROL_SERIAL_USART3 0 // use RC iBUS input on the RIGHT cable, disable if ADC or PPM is used!
|
||||||
|
#define FEEDBACK_SERIAL_USART3 // right sensor board cable, disable if ADC or PPM is used!
|
||||||
|
#define PRI_INPUT1 3, -1000, 0, 1000, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
#define PRI_INPUT2 3, -1000, 0, 1000, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Min / Max values of each channel (use DEBUG to determine these values)
|
#if defined(CONTROL_SERIAL_USART3) && !defined(DUAL_INPUTS)
|
||||||
#define INPUT1_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
#define DEBUG_SERIAL_USART2 // left sensor cable debug
|
||||||
#define INPUT1_MIN -1000 // (-1000 - 0)
|
#elif defined(DEBUG_SERIAL_USART2) && !defined(DUAL_INPUTS)
|
||||||
#define INPUT1_MID 0
|
#define DEBUG_SERIAL_USART3 // right sensor cable debug
|
||||||
#define INPUT1_MAX 1000 // (0 - 1000)
|
#endif
|
||||||
#define INPUT1_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
|
||||||
|
|
||||||
#define INPUT2_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
|
||||||
#define INPUT2_MIN -1000 // (-1000 - 0)
|
|
||||||
#define INPUT2_MID 0
|
|
||||||
#define INPUT2_MAX 1000 // (0 - 1000)
|
|
||||||
#define INPUT2_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
|
||||||
#endif
|
#endif
|
||||||
// ############################# END OF VARIANT_IBUS SETTINGS ############################
|
// ############################# END OF VARIANT_IBUS SETTINGS ############################
|
||||||
|
|
||||||
|
@ -447,45 +482,38 @@
|
||||||
|
|
||||||
// ############################ VARIANT_HOVERCAR SETTINGS ############################
|
// ############################ VARIANT_HOVERCAR SETTINGS ############################
|
||||||
#ifdef VARIANT_HOVERCAR
|
#ifdef VARIANT_HOVERCAR
|
||||||
|
#define FLASH_WRITE_KEY 0x1107 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
#undef CTRL_MOD_REQ
|
#undef CTRL_MOD_REQ
|
||||||
#define CTRL_MOD_REQ TRQ_MODE // HOVERCAR works best in TORQUE Mode
|
#define CTRL_MOD_REQ TRQ_MODE // HOVERCAR works best in TORQUE Mode
|
||||||
#define CONTROL_ADC // use ADC as input. disable CONTROL_SERIAL_USART2, FEEDBACK_SERIAL_USART2, DEBUG_SERIAL_USART2!
|
#define CONTROL_ADC 0 // use ADC as input. Number indicates priority for dual-input. Disable CONTROL_SERIAL_USART2, FEEDBACK_SERIAL_USART2, DEBUG_SERIAL_USART2!
|
||||||
#define ADC_PROTECT_TIMEOUT 100 // ADC Protection: number of wrong / missing input commands before safety state is taken
|
#define SIDEBOARD_SERIAL_USART3 1 // Rx from right sensor board: to use photosensors as buttons. Number indicates priority for dual-input. Comment-out if sideboard is not used!
|
||||||
#define ADC_PROTECT_THRESH 200 // ADC Protection threshold below/above the MIN/MAX ADC values
|
#define FEEDBACK_SERIAL_USART3 // Tx to right sensor board: for LED battery indication. Comment-out if sideboard is not used!
|
||||||
|
|
||||||
#define INPUT1_TYPE 1 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
#define DUAL_INPUTS // ADC*(Primary) + Sideboard_R(Auxiliary). Uncomment this to use Dual-inputs
|
||||||
#define INPUT1_MIN 1000 // min ADC1-value while poti at minimum-position (0 - 4095)
|
#define PRI_INPUT1 1, 1000, 0, 2500, 0 // Pedal Brake TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#define INPUT1_MID 0
|
#define PRI_INPUT2 1, 500, 0, 2200, 0 // Pedal Accel TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#define INPUT1_MAX 2500 // max ADC1-value while poti at maximum-position (0 - 4095)
|
#define AUX_INPUT1 2, -1000, 0, 1000, 0 // Sideboard Steer TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#define INPUT1_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
#define AUX_INPUT2 2, -1000, 0, 1000, 0 // Sideboard Speed TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
|
|
||||||
#define INPUT2_TYPE 1 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
#define SPEED_COEFFICIENT 16384 // 1.0f
|
||||||
#define INPUT2_MIN 500 // min ADC2-value while poti at minimum-position (0 - 4095)
|
#define STEER_COEFFICIENT 8192 // 0.5f Only active in Sideboard input
|
||||||
#define INPUT2_MID 0
|
// #define INVERT_R_DIRECTION // Invert rotation of right motor
|
||||||
#define INPUT2_MAX 2200 // max ADC2-value while poti at maximum-position (0 - 4095)
|
// #define INVERT_L_DIRECTION // Invert rotation of left motor
|
||||||
#define INPUT2_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
// #define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!
|
||||||
|
|
||||||
#define SPEED_COEFFICIENT 16384 // 1.0f
|
|
||||||
#define STEER_COEFFICIENT 0 // 0.0f
|
|
||||||
// #define INVERT_R_DIRECTION // Invert rotation of right motor
|
|
||||||
// #define INVERT_L_DIRECTION // Invert rotation of left motor
|
|
||||||
#define SIDEBOARD_SERIAL_USART3 // Tx -> Rx of right sensor board: for LED battery indication. Comment-out if sideboard is not used!
|
|
||||||
#define FEEDBACK_SERIAL_USART3 // Rx <- Tx of right sensor board: to use photosensors as buttons. Comment-out if sideboard is not used!
|
|
||||||
// #define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!
|
|
||||||
|
|
||||||
// Extra functionality
|
// Extra functionality
|
||||||
// #define CRUISE_CONTROL_SUPPORT // [-] Flag to enable Cruise Control support. Activation/Deactivation is done by sideboard button or Brake pedal press.
|
// #define CRUISE_CONTROL_SUPPORT // [-] Flag to enable Cruise Control support. Activation/Deactivation is done by sideboard button or Brake pedal press.
|
||||||
// #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.
|
||||||
// #define ELECTRIC_BRAKE_ENABLE // [-] Flag to enable electric brake and replace the motor "freewheel" with a constant braking when the input torque request is 0. Only available and makes sense for TORQUE mode.
|
// #define ELECTRIC_BRAKE_ENABLE // [-] Flag to enable electric brake and replace the motor "freewheel" with a constant braking when the input torque request is 0. Only available and makes sense for TORQUE mode.
|
||||||
// #define ELECTRIC_BRAKE_MAX 100 // (0, 500) Maximum electric brake to be applied when input torque request is 0 (pedal fully released).
|
// #define ELECTRIC_BRAKE_MAX 100 // (0, 500) Maximum electric brake to be applied when input torque request is 0 (pedal fully released).
|
||||||
// #define ELECTRIC_BRAKE_THRES 120 // (0, 500) Threshold below at which the electric brake starts engaging.
|
// #define ELECTRIC_BRAKE_THRES 120 // (0, 500) Threshold below at which the electric brake starts engaging.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Multiple tap detection: default DOUBLE Tap on Brake pedal (4 pulses)
|
// Multiple tap detection: default DOUBLE Tap on Brake pedal (4 pulses)
|
||||||
#define MULTIPLE_TAP_NR 2 * 2 // [-] Define tap number: MULTIPLE_TAP_NR = number_of_taps * 2, number_of_taps = 1 (for single taping), 2 (for double tapping), 3 (for triple tapping), etc...
|
#define MULTIPLE_TAP_NR 2 * 2 // [-] Define tap number: MULTIPLE_TAP_NR = number_of_taps * 2, number_of_taps = 1 (for single taping), 2 (for double tapping), 3 (for triple tapping), etc...
|
||||||
#define MULTIPLE_TAP_HI 600 // [-] Multiple tap detection High hysteresis threshold
|
#define MULTIPLE_TAP_HI 600 // [-] Multiple tap detection High hysteresis threshold
|
||||||
#define MULTIPLE_TAP_LO 200 // [-] Multiple tap detection Low hysteresis threshold
|
#define MULTIPLE_TAP_LO 200 // [-] Multiple tap detection Low hysteresis threshold
|
||||||
#define MULTIPLE_TAP_TIMEOUT 2000 // [ms] Multiple tap detection Timeout period. The taps need to happen within this time window to be accepted.
|
#define MULTIPLE_TAP_TIMEOUT 2000 // [ms] Multiple tap detection Timeout period. The taps need to happen within this time window to be accepted.
|
||||||
// ######################## END OF VARIANT_HOVERCAR SETTINGS #########################
|
// ######################## END OF VARIANT_HOVERCAR SETTINGS #########################
|
||||||
|
|
||||||
|
|
||||||
|
@ -494,10 +522,18 @@
|
||||||
// Communication: [DONE]
|
// Communication: [DONE]
|
||||||
// Balancing controller: [TODO]
|
// Balancing controller: [TODO]
|
||||||
#ifdef VARIANT_HOVERBOARD
|
#ifdef VARIANT_HOVERBOARD
|
||||||
#define SIDEBOARD_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used!
|
#define FLASH_WRITE_KEY 0x1008 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
|
#define SIDEBOARD_SERIAL_USART2 1 // left sensor board cable. Number indicates priority for dual-input. Disable if ADC or PPM is used!
|
||||||
#define FEEDBACK_SERIAL_USART2
|
#define FEEDBACK_SERIAL_USART2
|
||||||
#define SIDEBOARD_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!
|
#define SIDEBOARD_SERIAL_USART3 0 // right sensor board cable. Number indicates priority for dual-input. Disable if I2C (nunchuk or lcd) is used!
|
||||||
#define FEEDBACK_SERIAL_USART3
|
#define FEEDBACK_SERIAL_USART3
|
||||||
|
|
||||||
|
// If an iBUS RC receiver is connected to either Left Sideboard (AUX_INPUT) or Right Sideboard (PRI_INPUT)
|
||||||
|
// PRIMARY INPUT: TYPE, MIN, MID, MAX, DEADBAND /* TYPE: 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect */
|
||||||
|
#define PRI_INPUT1 3, -1000, 0, 1000, 0 // Priority Sideboard can be used to send commands via an iBUS Receiver connected to the sideboard
|
||||||
|
#define PRI_INPUT2 3, -1000, 0, 1000, 0 // Priority Sideboard can be used to send commands via an iBUS Receiver connected to the sideboard
|
||||||
|
#define AUX_INPUT1 3, -1000, 0, 1000, 0 // not used
|
||||||
|
#define AUX_INPUT2 3, -1000, 0, 1000, 0 // not used
|
||||||
#endif
|
#endif
|
||||||
// ######################## END OF VARIANT_HOVERBOARD SETTINGS #########################
|
// ######################## END OF VARIANT_HOVERBOARD SETTINGS #########################
|
||||||
|
|
||||||
|
@ -506,17 +542,20 @@
|
||||||
// ################################# VARIANT_TRANSPOTTER SETTINGS ############################
|
// ################################# VARIANT_TRANSPOTTER SETTINGS ############################
|
||||||
//TODO ADD VALIDATION
|
//TODO ADD VALIDATION
|
||||||
#ifdef VARIANT_TRANSPOTTER
|
#ifdef VARIANT_TRANSPOTTER
|
||||||
|
#define FLASH_WRITE_KEY 0x1009 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
#define CONTROL_GAMETRAK
|
#define CONTROL_GAMETRAK
|
||||||
#define SUPPORT_LCD
|
#define SUPPORT_LCD
|
||||||
// #define SUPPORT_NUNCHUK
|
// #define SUPPORT_NUNCHUK
|
||||||
#define GAMETRAK_CONNECTION_NORMAL // for normal wiring according to the wiki instructions
|
#define GAMETRAK_CONNECTION_NORMAL // for normal wiring according to the wiki instructions
|
||||||
//#define GAMETRAK_CONNECTION_ALTERNATE // use this define instead if you messed up the gametrak ADC wiring (steering is speed, and length of the wire is steering)
|
// #define GAMETRAK_CONNECTION_ALTERNATE // use this define instead if you messed up the gametrak ADC wiring (steering is speed, and length of the wire is steering)
|
||||||
#define ROT_P 1.2 // P coefficient for the direction controller. Positive / Negative values to invert gametrak steering direction.
|
#define ROT_P 1.2 // P coefficient for the direction controller. Positive / Negative values to invert gametrak steering direction.
|
||||||
// during nunchuk control (only relevant when activated)
|
// during nunchuk control (only relevant when activated)
|
||||||
#define SPEED_COEFFICIENT 14746 // 0.9f - higher value == stronger. 0.0 to ~2.0?
|
#define SPEED_COEFFICIENT 14746 // 0.9f - higher value == stronger. 0.0 to ~2.0?
|
||||||
#define STEER_COEFFICIENT 8192 // 0.5f - higher value == stronger. if you do not want any steering, set it to 0.0; 0.0 to 1.0
|
#define STEER_COEFFICIENT 8192 // 0.5f - higher value == stronger. if you do not want any steering, set it to 0.0; 0.0 to 1.0
|
||||||
#define INVERT_R_DIRECTION // Invert right motor
|
#define INVERT_R_DIRECTION // Invert right motor
|
||||||
#define INVERT_L_DIRECTION // Invert left motor
|
#define INVERT_L_DIRECTION // Invert left motor
|
||||||
|
#define PRI_INPUT1 2, -1000, 0, 1000, 0 // dummy input, TRANSPOTTER does not use input limitations
|
||||||
|
#define PRI_INPUT2 2, -1000, 0, 1000, 0 // dummy input, TRANSPOTTER does not use input limitations
|
||||||
#endif
|
#endif
|
||||||
// ############################# END OF VARIANT_TRANSPOTTER SETTINGS ########################
|
// ############################# END OF VARIANT_TRANSPOTTER SETTINGS ########################
|
||||||
|
|
||||||
|
@ -527,37 +566,30 @@
|
||||||
* right sensor board cable. Connect PB10 to channel 1 and PB11 to channel 2 on receiver.
|
* right sensor board cable. Connect PB10 to channel 1 and PB11 to channel 2 on receiver.
|
||||||
* Channel 1: steering, Channel 2: speed.
|
* Channel 1: steering, Channel 2: speed.
|
||||||
*/
|
*/
|
||||||
|
#define FLASH_WRITE_KEY 0x1010 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
|
||||||
#undef CTRL_MOD_REQ
|
#undef CTRL_MOD_REQ
|
||||||
#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 0 // use RC PWM as input on the LEFT cable. Number indicates priority for dual-input. 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 0 // use RC PWM as input on the RIGHT cable. Number indicates priority for dual-input. Disable DEBUG_SERIAL_USART3!
|
||||||
#ifdef CONTROL_PWM_RIGHT
|
|
||||||
#define DEBUG_SERIAL_USART2 // left sensor cable debug
|
#define PRI_INPUT1 0, -1000, 0, 1000, 0 // Disabled. TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#else
|
#define PRI_INPUT2 2, -800, 0, 700, 100 // Active. TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
|
||||||
#define DEBUG_SERIAL_USART3 // right sensor cable debug
|
#define INPUT_BRK -400 // (-1000 - 0) Change this value to adjust the braking amount
|
||||||
#endif
|
|
||||||
// Min / Max values of each channel (use DEBUG to determine these values)
|
#define FILTER 6553 // 0.1f [-] fixdt(0,16,16) lower value == softer filter [0, 65535] = [0.0 - 1.0].
|
||||||
#define INPUT1_TYPE 0 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
#define SPEED_COEFFICIENT 16384 // 1.0f [-] fixdt(1,16,14) higher value == stronger. [0, 65535] = [-2.0 - 2.0]. In this case 16384 = 1.0 * 2^14
|
||||||
#define INPUT1_MIN -1000 // (-1000 - 0)
|
#define STEER_COEFFICIENT 0 // 1.0f [-] fixdt(1,16,14) higher value == stronger. [0, 65535] = [-2.0 - 2.0]. In this case 16384 = 1.0 * 2^14. If you do not want any steering, set it to 0.
|
||||||
#define INPUT1_MID 0
|
|
||||||
#define INPUT1_MAX 1000 // (0 - 1000)
|
|
||||||
#define INPUT1_DEADBAND 100 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
|
||||||
|
|
||||||
#define INPUT2_TYPE 2 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect
|
|
||||||
#define INPUT2_MIN -800 // (-1000 - 0)
|
|
||||||
#define INPUT2_MID 0
|
|
||||||
#define INPUT2_MAX 700 // (0 - 1000)
|
|
||||||
#define INPUT2_DEADBAND 100 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
|
|
||||||
#define INPUT2_BRAKE -400 // (-1000 - 0) Change this value to adjust the braking amount
|
|
||||||
|
|
||||||
#define FILTER 6553 // 0.1f [-] fixdt(0,16,16) lower value == softer filter [0, 65535] = [0.0 - 1.0].
|
|
||||||
#define SPEED_COEFFICIENT 16384 // 1.0f [-] fixdt(1,16,14) higher value == stronger. [0, 65535] = [-2.0 - 2.0]. In this case 16384 = 1.0 * 2^14
|
|
||||||
#define STEER_COEFFICIENT 0 // 1.0f [-] fixdt(1,16,14) higher value == stronger. [0, 65535] = [-2.0 - 2.0]. In this case 16384 = 1.0 * 2^14. If you do not want any steering, set it to 0.
|
|
||||||
#define INVERT_R_DIRECTION
|
#define INVERT_R_DIRECTION
|
||||||
#define INVERT_L_DIRECTION
|
#define INVERT_L_DIRECTION
|
||||||
// #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 ############################
|
||||||
|
|
||||||
|
@ -599,10 +631,10 @@
|
||||||
#ifndef STEER_COEFFICIENT
|
#ifndef STEER_COEFFICIENT
|
||||||
#define STEER_COEFFICIENT DEFAULT_STEER_COEFFICIENT
|
#define STEER_COEFFICIENT DEFAULT_STEER_COEFFICIENT
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONTROL_ADC
|
#if defined(PRI_INPUT1) && defined(PRI_INPUT2) && defined(AUX_INPUT1) && defined(AUX_INPUT2)
|
||||||
#define INPUT_MARGIN 100 // Input margin applied on the raw ADC min and max to make sure the motor MIN and MAX values are reached even in the presence of noise
|
#define INPUTS_NR 2
|
||||||
#else
|
#else
|
||||||
#define INPUT_MARGIN 0
|
#define INPUTS_NR 1
|
||||||
#endif
|
#endif
|
||||||
// ########################### END OF APPLY DEFAULT SETTING ############################
|
// ########################### END OF APPLY DEFAULT SETTING ############################
|
||||||
|
|
||||||
|
@ -616,11 +648,6 @@
|
||||||
|
|
||||||
|
|
||||||
// General checks
|
// General checks
|
||||||
#if (defined(CONTROL_ADC) || defined(CONTROL_SERIAL_USART2) || defined(CONTROL_PPM_LEFT) || defined(CONTROL_PWM_LEFT)) && \
|
|
||||||
(defined(CONTROL_NUNCHUK) || defined(CONTROL_SERIAL_USART3) || defined(CONTROL_PPM_RIGHT) || defined(CONTROL_PWM_RIGHT))
|
|
||||||
#warning !! Multiple control input sources defined !! If NOT handled correctly, it can lead to undesired behavior!
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONTROL_SERIAL_USART2) && defined(SIDEBOARD_SERIAL_USART2)
|
#if defined(CONTROL_SERIAL_USART2) && defined(SIDEBOARD_SERIAL_USART2)
|
||||||
#error CONTROL_SERIAL_USART2 and SIDEBOARD_SERIAL_USART2 not allowed, choose one.
|
#error CONTROL_SERIAL_USART2 and SIDEBOARD_SERIAL_USART2 not allowed, choose one.
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -222,12 +222,10 @@ void PWM_ISR_CH2_Callback(void);
|
||||||
#define SENSOR2_SET (0x02)
|
#define SENSOR2_SET (0x02)
|
||||||
#define SENSOR_MPU (0x04)
|
#define SENSOR_MPU (0x04)
|
||||||
|
|
||||||
// RC iBUS switch definitions. Flysky FS-i6S has SW1, SW4 - 2 positions; SW2, SW3 - 3 positions
|
// RC iBUS switch definitions. Flysky FS-i6S has [SW1, SW2, SW3, SW4] = [2, 3, 3, 2] positions switch
|
||||||
#define SW1_SET (0x0100) // 0000 0001 0000 0000
|
#define SW1_SET (0x0100) // 0000 0001 0000 0000
|
||||||
#define SW2_SET1 (0x0200) // 0000 0010 0000 0000
|
#define SW2_SET (0x0600) // 0000 0110 0000 0000
|
||||||
#define SW2_SET2 (0x0400) // 0000 0100 0000 0000
|
#define SW3_SET (0x1800) // 0001 1000 0000 0000
|
||||||
#define SW3_SET1 (0x0800) // 0000 1000 0000 0000
|
|
||||||
#define SW3_SET2 (0x1000) // 0001 0000 0000 0000
|
|
||||||
#define SW4_SET (0x2000) // 0010 0000 0000 0000
|
#define SW4_SET (0x2000) // 0010 0000 0000 0000
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -209,7 +209,7 @@
|
||||||
#define PAGE_FULL ((uint8_t)0x80)
|
#define PAGE_FULL ((uint8_t)0x80)
|
||||||
|
|
||||||
/* Variables' number */
|
/* Variables' number */
|
||||||
#define NB_OF_VAR ((uint8_t)0x0B)
|
#define NB_OF_VAR ((uint8_t)0x13) /* 19 Variables */
|
||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
/* Exported macro ------------------------------------------------------------*/
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
|
|
31
Inc/util.h
|
@ -55,6 +55,18 @@
|
||||||
} SerialSideboard;
|
} SerialSideboard;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Input Structure
|
||||||
|
typedef struct {
|
||||||
|
int16_t raw; // raw input
|
||||||
|
int16_t cmd; // command
|
||||||
|
uint8_t typ; // type
|
||||||
|
uint8_t typDef; // type Defined
|
||||||
|
int16_t min; // minimum
|
||||||
|
int16_t mid; // middle
|
||||||
|
int16_t max; // maximum
|
||||||
|
int16_t dband; // deadband
|
||||||
|
} InputStruct;
|
||||||
|
|
||||||
// Initialization Functions
|
// Initialization Functions
|
||||||
void BLDC_Init(void);
|
void BLDC_Init(void);
|
||||||
void Input_Lim_Init(void);
|
void Input_Lim_Init(void);
|
||||||
|
@ -68,21 +80,17 @@ void beepLong(uint8_t freq);
|
||||||
void beepShort(uint8_t freq);
|
void beepShort(uint8_t freq);
|
||||||
void beepShortMany(uint8_t cnt, int8_t dir);
|
void beepShortMany(uint8_t cnt, int8_t dir);
|
||||||
void calcAvgSpeed(void);
|
void calcAvgSpeed(void);
|
||||||
int addDeadBand(int16_t u, int16_t type, int16_t deadBand, int16_t in_min, int16_t in_mid, int16_t in_max, int16_t out_min, int16_t out_max);
|
|
||||||
int checkInputType(int16_t min, int16_t mid, int16_t max);
|
|
||||||
void adcCalibLim(void);
|
void adcCalibLim(void);
|
||||||
void updateCurSpdLim(void);
|
void updateCurSpdLim(void);
|
||||||
void saveConfig(void);
|
|
||||||
void standstillHold(void);
|
void standstillHold(void);
|
||||||
void electricBrake(uint16_t speedBlend, uint8_t reverseDir);
|
void electricBrake(uint16_t speedBlend, uint8_t reverseDir);
|
||||||
void cruiseControl(uint8_t button);
|
void cruiseControl(uint8_t button);
|
||||||
|
int checkInputType(int16_t min, int16_t mid, int16_t max);
|
||||||
|
|
||||||
// Poweroff Functions
|
// Input Functions
|
||||||
void poweroff(void);
|
void calcInputCmd(InputStruct *in, int16_t out_min, int16_t out_max);
|
||||||
void poweroffPressCheck(void);
|
void readInputRaw(void);
|
||||||
|
void handleTimeout(void);
|
||||||
// Read Functions
|
|
||||||
void readInput(void);
|
|
||||||
void readCommand(void);
|
void readCommand(void);
|
||||||
void usart2_rx_check(void);
|
void usart2_rx_check(void);
|
||||||
void usart3_rx_check(void);
|
void usart3_rx_check(void);
|
||||||
|
@ -100,6 +108,11 @@ void usart_process_sideboard(SerialSideboard *Sideboard_in, SerialSideboard *Sid
|
||||||
void sideboardLeds(uint8_t *leds);
|
void sideboardLeds(uint8_t *leds);
|
||||||
void sideboardSensors(uint8_t sensors);
|
void sideboardSensors(uint8_t sensors);
|
||||||
|
|
||||||
|
// Poweroff Functions
|
||||||
|
void saveConfig(void);
|
||||||
|
void poweroff(void);
|
||||||
|
void poweroffPressCheck(void);
|
||||||
|
|
||||||
// Filtering Functions
|
// Filtering Functions
|
||||||
void filtLowPass32(int32_t u, uint16_t coef, int32_t *y);
|
void filtLowPass32(int32_t u, uint16_t coef, int32_t *y);
|
||||||
void rateLimiter16(int16_t u, int16_t rate, int16_t *y);
|
void rateLimiter16(int16_t u, int16_t rate, int16_t *y);
|
||||||
|
|
36
README.md
|
@ -14,7 +14,8 @@ Table of Contents
|
||||||
|
|
||||||
* [Hardware](#hardware)
|
* [Hardware](#hardware)
|
||||||
* [FOC Firmware](#foc-firmware)
|
* [FOC Firmware](#foc-firmware)
|
||||||
* [Example Variants ](#example-variants)
|
* [Example Variants](#example-variants)
|
||||||
|
* [Dual Inputs](#dual-inputs)
|
||||||
* [Flashing](#flashing)
|
* [Flashing](#flashing)
|
||||||
* [Troubleshooting](#troubleshooting)
|
* [Troubleshooting](#troubleshooting)
|
||||||
* [Diagnostics](#diagnostics)
|
* [Diagnostics](#diagnostics)
|
||||||
|
@ -76,11 +77,9 @@ In this firmware 3 control types are available:
|
||||||
|FOC SPEED| +++ | +++ | + | ++ | n.a. | +++ |
|
|FOC SPEED| +++ | +++ | + | ++ | n.a. | +++ |
|
||||||
|FOC TORQUE| +++ | +++ | +++ | ++ | +++<sup>(1)</sup> | n.a<sup>(2)</sup> |
|
|FOC TORQUE| +++ | +++ | +++ | ++ | +++<sup>(1)</sup> | n.a<sup>(2)</sup> |
|
||||||
|
|
||||||
<sup>(1)</sup> By enabling `ELECTRIC_BRAKE_ENABLE` in `config.h`, the freewheeling amount can be adjusted using the `ELECTRIC_BRAKE_MAX` parameter.
|
<sup>(1)</sup> By enabling `ELECTRIC_BRAKE_ENABLE` in `config.h`, the freewheeling amount can be adjusted using the `ELECTRIC_BRAKE_MAX` parameter.<br/>
|
||||||
|
|
||||||
<sup>(2)</sup> The standstill hold functionality can be forced by enabling `STANDSTILL_HOLD_ENABLE` in `config.h`.
|
<sup>(2)</sup> The standstill hold functionality can be forced by enabling `STANDSTILL_HOLD_ENABLE` in `config.h`.
|
||||||
|
|
||||||
|
|
||||||
In all FOC control modes, the controller features maximum motor speed and maximum motor current protection. This brings great advantages to fulfil the needs of many robotic applications while maintaining safe operation.
|
In all FOC control modes, the controller features maximum motor speed and maximum motor current protection. This brings great advantages to fulfil the needs of many robotic applications while maintaining safe operation.
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,7 +93,7 @@ In all FOC control modes, the controller features maximum motor speed and maximu
|
||||||
- If you re-calibrate the Field Weakening please take all the safety measures! The motors can spin very fast!
|
- If you re-calibrate the Field Weakening please take all the safety measures! The motors can spin very fast!
|
||||||
|
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
- All the calibratable motor parameters can be found in the 'BLDC_controller_data.c'. I provided you with an already calibrated controller, but if you feel like fine tuning it feel free to do so
|
- All the calibratable motor parameters can be found in the 'BLDC_controller_data.c'. I provided you with an already calibrated controller, but if you feel like fine tuning it feel free to do so
|
||||||
- The parameters are represented in Fixed-point data type for a more efficient code execution
|
- The parameters are represented in Fixed-point data type for a more efficient code execution
|
||||||
- For calibrating the fixed-point parameters use the [Fixed-Point Viewer](https://github.com/EmanuelFeru/FixedPointViewer) tool
|
- For calibrating the fixed-point parameters use the [Fixed-Point Viewer](https://github.com/EmanuelFeru/FixedPointViewer) tool
|
||||||
|
@ -102,7 +101,7 @@ In all FOC control modes, the controller features maximum motor speed and maximu
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
## Example Variants
|
## Example Variants
|
||||||
|
|
||||||
This firmware offers currently these variants (selectable in [platformio.ini](/platformio.ini) or [config.h](/Inc/config.h)):
|
This firmware offers currently these variants (selectable in [platformio.ini](/platformio.ini) or [config.h](/Inc/config.h)):
|
||||||
- **VARIANT_ADC**: The motors are controlled by two potentiometers connected to the Left sensor cable (long wired)
|
- **VARIANT_ADC**: The motors are controlled by two potentiometers connected to the Left sensor cable (long wired)
|
||||||
|
@ -119,6 +118,29 @@ This firmware offers currently these variants (selectable in [platformio.ini](/p
|
||||||
Of course the firmware can be further customized for other needs or projects.
|
Of course the firmware can be further customized for other needs or projects.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
## Dual Inputs
|
||||||
|
|
||||||
|
The firmware supports the input to be provided from two different sources connected to the Left and Right cable, respectively. To enable dual-inputs functionality uncomment `#define DUAL_INPUTS` in config.h for the respective variant. Various dual-inputs combinations can be realized as illustrated in the following table:
|
||||||
|
| Left | Right | Availability |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| ADC<sup>(0)</sup> | UART<sup>(1)</sup> | VARIANT_ADC |
|
||||||
|
| ADC<sup>(0)</sup> | {PPM,PWM,iBUS}<sup>(1)</sup> | VARIANT_{PPM,PWM,IBUS} |
|
||||||
|
| ADC<sup>(0)</sup> | Sideboard<sup></sup><sup>(1*)</sup> | VARIANT_HOVERCAR |
|
||||||
|
| UART<sup>(0)</sup> | Sideboard<sup>(1*)</sup> | VARIANT_UART |
|
||||||
|
| UART<sup>(1)</sup> | Nunchuk<sup>(0)</sup> | VARIANT_NUNCHUK |
|
||||||
|
|
||||||
|
<sup>(0)</sup> Primary input: this input is used when the Auxilliary input is not available or not connected.<br/>
|
||||||
|
<sup>(1)</sup> Auxilliary input: this inputs is used when connected or enabled by a switch<sup>(*)</sup>. If the Auxilliary input is disconnected, the firmware will automatically switch to the Primary input. Timeout is reported **only** on the Primary input.
|
||||||
|
|
||||||
|
With slight modifications in config.h, other dual-inputs combinations can be realized as:
|
||||||
|
| Left | Right | Possibility |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| Sideboard<sup>(1*)</sup> | UART<sup>(0)</sup> | VARIANT_UART |
|
||||||
|
| UART<sup>(0)</sup> | {PPM,PWM,iBUS}<sup>(1)</sup> | VARIANT_{PPM,PWM,IBUS} |
|
||||||
|
| {PPM,PWM,iBUS}<sup>(1)</sup> | Nunchuk<sup>(0)</sup> | VARIANT_{PPM,PWM,IBUS} |
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
## Flashing
|
## Flashing
|
||||||
|
|
||||||
|
@ -223,7 +245,7 @@ The errors reported by the board are in the form of audible beeps:
|
||||||
- **1 beep (low pitch)**: Motor error (see [possible causes](https://github.com/EmanuelFeru/bldc-motor-control-FOC#diagnostics))
|
- **1 beep (low pitch)**: Motor error (see [possible causes](https://github.com/EmanuelFeru/bldc-motor-control-FOC#diagnostics))
|
||||||
- **2 beeps (low pitch)**: ADC timeout
|
- **2 beeps (low pitch)**: ADC timeout
|
||||||
- **3 beeps (low pitch)**: Serial communication timeout
|
- **3 beeps (low pitch)**: Serial communication timeout
|
||||||
- **4 beeps (low pitch)**: General timeout (PPM, PWM, Nunchuck)
|
- **4 beeps (low pitch)**: General timeout (PPM, PWM, Nunchuk)
|
||||||
- **5 beeps (low pitch)**: Mainboard temperature warning
|
- **5 beeps (low pitch)**: Mainboard temperature warning
|
||||||
- **1 beep slow (medium pitch)**: Low battery voltage < 36V
|
- **1 beep slow (medium pitch)**: Low battery voltage < 36V
|
||||||
- **1 beep fast (medium pitch)**: Low battery voltage < 35V
|
- **1 beep fast (medium pitch)**: Low battery voltage < 35V
|
||||||
|
|
|
@ -8,10 +8,11 @@
|
||||||
|
|
||||||
TIM_HandleTypeDef TimHandle;
|
TIM_HandleTypeDef TimHandle;
|
||||||
TIM_HandleTypeDef TimHandle2;
|
TIM_HandleTypeDef TimHandle2;
|
||||||
uint8_t ppm_count = 0;
|
uint8_t ppm_count = 0;
|
||||||
uint8_t pwm_count = 0;
|
uint8_t pwm_count = 0;
|
||||||
uint32_t timeoutCnt = 0;
|
uint32_t timeoutCntGen = TIMEOUT;
|
||||||
uint8_t nunchuk_data[6] = {0};
|
uint8_t timeoutFlgGen = 0;
|
||||||
|
uint8_t nunchuk_data[6] = {0};
|
||||||
|
|
||||||
uint8_t i2cBuffer[2];
|
uint8_t i2cBuffer[2];
|
||||||
|
|
||||||
|
@ -34,7 +35,8 @@ void PPM_ISR_Callback(void) {
|
||||||
if (rc_delay > 3000) {
|
if (rc_delay > 3000) {
|
||||||
if (ppm_valid && ppm_count == PPM_NUM_CHANNELS) {
|
if (ppm_valid && ppm_count == PPM_NUM_CHANNELS) {
|
||||||
ppm_timeout = 0;
|
ppm_timeout = 0;
|
||||||
timeoutCnt = 0;
|
timeoutCntGen = 0;
|
||||||
|
timeoutFlgGen = 0;
|
||||||
memcpy(ppm_captured_value, ppm_captured_value_buffer, sizeof(ppm_captured_value));
|
memcpy(ppm_captured_value, ppm_captured_value_buffer, sizeof(ppm_captured_value));
|
||||||
}
|
}
|
||||||
ppm_valid = true;
|
ppm_valid = true;
|
||||||
|
@ -122,7 +124,8 @@ void PWM_ISR_CH1_Callback(void) {
|
||||||
} else { // Falling Edge interrupt -> measure pulse duration
|
} else { // Falling Edge interrupt -> measure pulse duration
|
||||||
uint16_t rc_signal = TIM2->CNT - pwm_CNT_prev_ch1;
|
uint16_t rc_signal = TIM2->CNT - pwm_CNT_prev_ch1;
|
||||||
if (IN_RANGE(rc_signal, 900, 2100)){
|
if (IN_RANGE(rc_signal, 900, 2100)){
|
||||||
timeoutCnt = 0;
|
timeoutCntGen = 0;
|
||||||
|
timeoutFlgGen = 0;
|
||||||
pwm_timeout_ch1 = 0;
|
pwm_timeout_ch1 = 0;
|
||||||
pwm_captured_ch1_value = CLAMP(rc_signal, 1000, 2000) - 1000;
|
pwm_captured_ch1_value = CLAMP(rc_signal, 1000, 2000) - 1000;
|
||||||
}
|
}
|
||||||
|
@ -141,7 +144,8 @@ void PWM_ISR_CH2_Callback(void) {
|
||||||
} else { // Falling Edge interrupt -> measure pulse duration
|
} else { // Falling Edge interrupt -> measure pulse duration
|
||||||
uint16_t rc_signal = TIM2->CNT - pwm_CNT_prev_ch2;
|
uint16_t rc_signal = TIM2->CNT - pwm_CNT_prev_ch2;
|
||||||
if (IN_RANGE(rc_signal, 900, 2100)){
|
if (IN_RANGE(rc_signal, 900, 2100)){
|
||||||
timeoutCnt = 0;
|
timeoutCntGen = 0;
|
||||||
|
timeoutFlgGen = 0;
|
||||||
pwm_timeout_ch2 = 0;
|
pwm_timeout_ch2 = 0;
|
||||||
pwm_captured_ch2_value = CLAMP(rc_signal, 1000, 2000) - 1000;
|
pwm_captured_ch2_value = CLAMP(rc_signal, 1000, 2000) - 1000;
|
||||||
}
|
}
|
||||||
|
@ -237,11 +241,12 @@ void Nunchuk_Read(void) {
|
||||||
HAL_I2C_Master_Transmit(&hi2c2,0xA4,(uint8_t*)i2cBuffer, 1, 10);
|
HAL_I2C_Master_Transmit(&hi2c2,0xA4,(uint8_t*)i2cBuffer, 1, 10);
|
||||||
HAL_Delay(3);
|
HAL_Delay(3);
|
||||||
if (HAL_I2C_Master_Receive(&hi2c2,0xA4,(uint8_t*)nunchuk_data, 6, 10) == HAL_OK) {
|
if (HAL_I2C_Master_Receive(&hi2c2,0xA4,(uint8_t*)nunchuk_data, 6, 10) == HAL_OK) {
|
||||||
timeoutCnt = 0;
|
timeoutCntGen = 0;
|
||||||
|
timeoutFlgGen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TRANSPOTTER
|
#ifndef TRANSPOTTER
|
||||||
if (timeoutCnt > 3) {
|
if (timeoutCntGen > 3) {
|
||||||
HAL_Delay(50);
|
HAL_Delay(50);
|
||||||
Nunchuk_Init();
|
Nunchuk_Init();
|
||||||
}
|
}
|
||||||
|
|
122
Src/main.c
|
@ -62,16 +62,16 @@ extern ExtY rtY_Left; /* External outputs */
|
||||||
extern ExtY rtY_Right; /* External outputs */
|
extern ExtY rtY_Right; /* External outputs */
|
||||||
//---------------
|
//---------------
|
||||||
|
|
||||||
extern int16_t cmd1; // normalized input value. -1000 to 1000
|
extern uint8_t inIdx; // input index used for dual-inputs
|
||||||
extern int16_t cmd2; // normalized input value. -1000 to 1000
|
extern InputStruct input1[]; // input structure
|
||||||
extern int16_t input1; // Non normalized input value
|
extern InputStruct input2[]; // input structure
|
||||||
extern int16_t input2; // Non normalized input value
|
|
||||||
|
|
||||||
extern int16_t speedAvg; // Average measured speed
|
extern int16_t speedAvg; // Average measured speed
|
||||||
extern int16_t speedAvgAbs; // Average measured speed in absolute
|
extern int16_t speedAvgAbs; // Average measured speed in absolute
|
||||||
extern volatile uint32_t timeoutCnt; // Timeout counter for the General timeout (PPM, PWM, Nunchuck)
|
extern volatile uint32_t timeoutCntGen; // Timeout counter for the General timeout (PPM, PWM, Nunchuk)
|
||||||
extern uint8_t timeoutFlagADC; // Timeout Flag for for ADC Protection: 0 = OK, 1 = Problem detected (line disconnected or wrong ADC data)
|
extern volatile uint8_t timeoutFlgGen; // Timeout Flag for the General timeout (PPM, PWM, Nunchuk)
|
||||||
extern uint8_t timeoutFlagSerial; // Timeout Flag for Rx Serial command: 0 = OK, 1 = Problem detected (line disconnected or wrong Rx data)
|
extern uint8_t timeoutFlgADC; // Timeout Flag for for ADC Protection: 0 = OK, 1 = Problem detected (line disconnected or wrong ADC data)
|
||||||
|
extern uint8_t timeoutFlgSerial; // Timeout Flag for Rx Serial command: 0 = OK, 1 = Problem detected (line disconnected or wrong Rx data)
|
||||||
|
|
||||||
extern volatile int pwml; // global variable for pwm left. -1000 to 1000
|
extern volatile int pwml; // global variable for pwm left. -1000 to 1000
|
||||||
extern volatile int pwmr; // global variable for pwm right. -1000 to 1000
|
extern volatile int pwmr; // global variable for pwm right. -1000 to 1000
|
||||||
|
@ -190,8 +190,8 @@ int main(void) {
|
||||||
poweronMelody();
|
poweronMelody();
|
||||||
HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_SET);
|
||||||
|
|
||||||
int16_t cmdL = 0, cmdR = 0;
|
int16_t cmdL = 0, cmdR = 0;
|
||||||
int16_t lastCmdL = 0, lastCmdR = 0;
|
int16_t cmdL_prev = 0, cmdR_prev = 0;
|
||||||
|
|
||||||
int32_t board_temp_adcFixdt = adc_buffer.temp << 16; // Fixed-point filter output initialized with current ADC converted to fixed-point
|
int32_t board_temp_adcFixdt = adc_buffer.temp << 16; // Fixed-point filter output initialized with current ADC converted to fixed-point
|
||||||
int16_t board_temp_adcFilt = adc_buffer.temp;
|
int16_t board_temp_adcFilt = adc_buffer.temp;
|
||||||
|
@ -199,14 +199,14 @@ int main(void) {
|
||||||
|
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
HAL_Delay(DELAY_IN_MAIN_LOOP); //delay in ms
|
HAL_Delay(DELAY_IN_MAIN_LOOP); // delay in ms
|
||||||
|
|
||||||
readCommand(); // Read Command: cmd1, cmd2
|
readCommand(); // Read Command: input1[inIdx].cmd, input2[inIdx].cmd
|
||||||
calcAvgSpeed(); // Calculate average measured speed: speedAvg, speedAvgAbs
|
calcAvgSpeed(); // Calculate average measured speed: speedAvg, speedAvgAbs
|
||||||
|
|
||||||
#ifndef VARIANT_TRANSPOTTER
|
#ifndef VARIANT_TRANSPOTTER
|
||||||
// ####### MOTOR ENABLING: Only if the initial input is very small (for SAFETY) #######
|
// ####### MOTOR ENABLING: Only if the initial input is very small (for SAFETY) #######
|
||||||
if (enable == 0 && (!rtY_Left.z_errCode && !rtY_Right.z_errCode) && (cmd1 > -50 && cmd1 < 50) && (cmd2 > -50 && cmd2 < 50)){
|
if (enable == 0 && (!rtY_Left.z_errCode && !rtY_Right.z_errCode) && (input1[inIdx].cmd > -50 && input1[inIdx].cmd < 50) && (input2[inIdx].cmd > -50 && input2[inIdx].cmd < 50)){
|
||||||
beepShort(6); // make 2 beeps indicating the motor enable
|
beepShort(6); // make 2 beeps indicating the motor enable
|
||||||
beepShort(4); HAL_Delay(100);
|
beepShort(4); HAL_Delay(100);
|
||||||
steerFixdt = speedFixdt = 0; // reset filters
|
steerFixdt = speedFixdt = 0; // reset filters
|
||||||
|
@ -216,7 +216,7 @@ int main(void) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ####### VARIANT_HOVERCAR #######
|
// ####### VARIANT_HOVERCAR #######
|
||||||
#if defined(VARIANT_HOVERCAR) || defined(VARIANT_SKATEBOARD) || defined(ELECTRIC_BRAKE_ENABLE)
|
#if defined(VARIANT_HOVERCAR) || defined(VARIANT_SKATEBOARD) || defined(ELECTRIC_BRAKE_ENABLE)
|
||||||
uint16_t speedBlend; // Calculate speed Blend, a number between [0, 1] in fixdt(0,16,15)
|
uint16_t speedBlend; // Calculate speed Blend, a number between [0, 1] in fixdt(0,16,15)
|
||||||
speedBlend = (uint16_t)(((CLAMP(speedAvgAbs,10,60) - 10) << 15) / 50); // speedBlend [0,1] is within [10 rpm, 60rpm]
|
speedBlend = (uint16_t)(((CLAMP(speedAvgAbs,10,60) - 10) << 15) / 50); // speedBlend [0,1] is within [10 rpm, 60rpm]
|
||||||
|
@ -226,63 +226,70 @@ int main(void) {
|
||||||
standstillHold(); // Apply Standstill Hold functionality. Only available and makes sense for VOLTAGE or TORQUE Mode
|
standstillHold(); // Apply Standstill Hold functionality. Only available and makes sense for VOLTAGE or TORQUE Mode
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VARIANT_HOVERCAR
|
#ifdef VARIANT_HOVERCAR
|
||||||
|
if (inIdx == CONTROL_ADC) { // Only use use implementation below if pedals are in use (ADC input)
|
||||||
if (speedAvgAbs < 60) { // Check if Hovercar is physically close to standstill to enable Double tap detection on Brake pedal for Reverse functionality
|
if (speedAvgAbs < 60) { // Check if Hovercar is physically close to standstill to enable Double tap detection on Brake pedal for Reverse functionality
|
||||||
multipleTapDet(cmd1, HAL_GetTick(), &MultipleTapBrake); // Brake pedal in this case is "cmd1" variable
|
multipleTapDet(input1[inIdx].cmd, HAL_GetTick(), &MultipleTapBrake); // Brake pedal in this case is "input1" variable
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd1 > 30) { // If Brake pedal (cmd1) is pressed, bring to 0 also the Throttle pedal (cmd2) to avoid "Double pedal" driving
|
if (input1[inIdx].cmd > 30) { // If Brake pedal (input1) is pressed, bring to 0 also the Throttle pedal (input2) to avoid "Double pedal" driving
|
||||||
cmd2 = (int16_t)((cmd2 * speedBlend) >> 15);
|
input2[inIdx].cmd = (int16_t)((input2[inIdx].cmd * speedBlend) >> 15);
|
||||||
cruiseControl((uint8_t)rtP_Left.b_cruiseCtrlEna); // Cruise control deactivated by Brake pedal if it was active
|
cruiseControl((uint8_t)rtP_Left.b_cruiseCtrlEna); // Cruise control deactivated by Brake pedal if it was active
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ELECTRIC_BRAKE_ENABLE
|
#ifdef ELECTRIC_BRAKE_ENABLE
|
||||||
electricBrake(speedBlend, MultipleTapBrake.b_multipleTap); // Apply Electric Brake. Only available and makes sense for TORQUE Mode
|
electricBrake(speedBlend, MultipleTapBrake.b_multipleTap); // Apply Electric Brake. Only available and makes sense for TORQUE Mode
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VARIANT_HOVERCAR
|
#ifdef VARIANT_HOVERCAR
|
||||||
|
if (inIdx == CONTROL_ADC) { // Only use use implementation below if pedals are in use (ADC input)
|
||||||
if (speedAvg > 0) { // Make sure the Brake pedal is opposite to the direction of motion AND it goes to 0 as we reach standstill (to avoid Reverse driving by Brake pedal)
|
if (speedAvg > 0) { // Make sure the Brake pedal is opposite to the direction of motion AND it goes to 0 as we reach standstill (to avoid Reverse driving by Brake pedal)
|
||||||
cmd1 = (int16_t)((-cmd1 * speedBlend) >> 15);
|
input1[inIdx].cmd = (int16_t)((-input1[inIdx].cmd * speedBlend) >> 15);
|
||||||
} else {
|
} else {
|
||||||
cmd1 = (int16_t)(( cmd1 * speedBlend) >> 15);
|
input1[inIdx].cmd = (int16_t)(( input1[inIdx].cmd * speedBlend) >> 15);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VARIANT_SKATEBOARD
|
#ifdef VARIANT_SKATEBOARD
|
||||||
if (cmd2 < 0) { // When Throttle is negative, it acts as brake. This condition is to make sure it goes to 0 as we reach standstill (to avoid Reverse driving)
|
if (input2[inIdx].cmd < 0) { // When Throttle is negative, it acts as brake. This condition is to make sure it goes to 0 as we reach standstill (to avoid Reverse driving)
|
||||||
if (speedAvg > 0) { // Make sure the braking is opposite to the direction of motion
|
if (speedAvg > 0) { // Make sure the braking is opposite to the direction of motion
|
||||||
cmd2 = (int16_t)(( cmd2 * speedBlend) >> 15);
|
input2[inIdx].cmd = (int16_t)(( input2[inIdx].cmd * speedBlend) >> 15);
|
||||||
} else {
|
} else {
|
||||||
cmd2 = (int16_t)((-cmd2 * speedBlend) >> 15);
|
input2[inIdx].cmd = (int16_t)((-input2[inIdx].cmd * speedBlend) >> 15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ####### LOW-PASS FILTER #######
|
// ####### LOW-PASS FILTER #######
|
||||||
rateLimiter16(cmd1, RATE, &steerRateFixdt);
|
rateLimiter16(input1[inIdx].cmd , RATE, &steerRateFixdt);
|
||||||
rateLimiter16(cmd2, RATE, &speedRateFixdt);
|
rateLimiter16(input2[inIdx].cmd , RATE, &speedRateFixdt);
|
||||||
filtLowPass32(steerRateFixdt >> 4, FILTER, &steerFixdt);
|
filtLowPass32(steerRateFixdt >> 4, FILTER, &steerFixdt);
|
||||||
filtLowPass32(speedRateFixdt >> 4, FILTER, &speedFixdt);
|
filtLowPass32(speedRateFixdt >> 4, FILTER, &speedFixdt);
|
||||||
steer = (int16_t)(steerFixdt >> 16); // convert fixed-point to integer
|
steer = (int16_t)(steerFixdt >> 16); // convert fixed-point to integer
|
||||||
speed = (int16_t)(speedFixdt >> 16); // convert fixed-point to integer
|
speed = (int16_t)(speedFixdt >> 16); // convert fixed-point to integer
|
||||||
|
|
||||||
// ####### VARIANT_HOVERCAR #######
|
// ####### VARIANT_HOVERCAR #######
|
||||||
#ifdef VARIANT_HOVERCAR
|
#ifdef VARIANT_HOVERCAR
|
||||||
|
if (inIdx == CONTROL_ADC) { // Only use use implementation below if pedals are in use (ADC input)
|
||||||
if (!MultipleTapBrake.b_multipleTap) { // Check driving direction
|
if (!MultipleTapBrake.b_multipleTap) { // Check driving direction
|
||||||
speed = steer + speed; // Forward driving: in this case steer = Brake, speed = Throttle
|
speed = steer + speed; // Forward driving: in this case steer = Brake, speed = Throttle
|
||||||
} else {
|
} else {
|
||||||
speed = steer - speed; // Reverse driving: in this case steer = Brake, speed = Throttle
|
speed = steer - speed; // Reverse driving: in this case steer = Brake, speed = Throttle
|
||||||
}
|
}
|
||||||
|
steer = 0; // Do not apply steering to avoid side effects if STEER_COEFFICIENT is NOT 0
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ####### MIXER #######
|
// ####### MIXER #######
|
||||||
// cmdR = CLAMP((int)(speed * SPEED_COEFFICIENT - steer * STEER_COEFFICIENT), INPUT_MIN, INPUT_MA);
|
// cmdR = CLAMP((int)(speed * SPEED_COEFFICIENT - steer * STEER_COEFFICIENT), INPUT_MIN, INPUT_MAX);
|
||||||
// cmdL = CLAMP((int)(speed * SPEED_COEFFICIENT + steer * STEER_COEFFICIENT), INPUT_MIN, INPUT_MA);
|
// cmdL = CLAMP((int)(speed * SPEED_COEFFICIENT + steer * STEER_COEFFICIENT), INPUT_MIN, INPUT_MAX);
|
||||||
mixerFcn(speed << 4, steer << 4, &cmdR, &cmdL); // This function implements the equations above
|
mixerFcn(speed << 4, steer << 4, &cmdR, &cmdL); // This function implements the equations above
|
||||||
|
|
||||||
// ####### SET OUTPUTS (if the target change is less than +/- 100) #######
|
// ####### SET OUTPUTS (if the target change is less than +/- 100) #######
|
||||||
if ((cmdL > lastCmdL-100 && cmdL < lastCmdL+100) && (cmdR > lastCmdR-100 && cmdR < lastCmdR+100)) {
|
if ((cmdL > cmdL_prev-100 && cmdL < cmdL_prev+100) && (cmdR > cmdR_prev-100 && cmdR < cmdR_prev+100)) {
|
||||||
#ifdef INVERT_R_DIRECTION
|
#ifdef INVERT_R_DIRECTION
|
||||||
pwmr = cmdR;
|
pwmr = cmdR;
|
||||||
#else
|
#else
|
||||||
|
@ -297,14 +304,14 @@ int main(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VARIANT_TRANSPOTTER
|
#ifdef VARIANT_TRANSPOTTER
|
||||||
distance = CLAMP(cmd1 - 180, 0, 4095);
|
distance = CLAMP(input1[inIdx].cmd - 180, 0, 4095);
|
||||||
steering = (cmd2 - 2048) / 2048.0;
|
steering = (input2[inIdx].cmd - 2048) / 2048.0;
|
||||||
distanceErr = distance - (int)(setDistance * 1345);
|
distanceErr = distance - (int)(setDistance * 1345);
|
||||||
|
|
||||||
if (nunchuk_connected == 0) {
|
if (nunchuk_connected == 0) {
|
||||||
cmdL = cmdL * 0.8f + (CLAMP(distanceErr + (steering*((float)MAX(ABS(distanceErr), 50)) * ROT_P), -850, 850) * -0.2f);
|
cmdL = cmdL * 0.8f + (CLAMP(distanceErr + (steering*((float)MAX(ABS(distanceErr), 50)) * ROT_P), -850, 850) * -0.2f);
|
||||||
cmdR = cmdR * 0.8f + (CLAMP(distanceErr - (steering*((float)MAX(ABS(distanceErr), 50)) * ROT_P), -850, 850) * -0.2f);
|
cmdR = cmdR * 0.8f + (CLAMP(distanceErr - (steering*((float)MAX(ABS(distanceErr), 50)) * ROT_P), -850, 850) * -0.2f);
|
||||||
if ((cmdL < lastCmdL + 50 && cmdL > lastCmdL - 50) && (cmdR < lastCmdR + 50 && cmdR > lastCmdR - 50)) {
|
if ((cmdL < cmdL_prev + 50 && cmdL > cmdL_prev - 50) && (cmdR < cmdR_prev + 50 && cmdR > cmdR_prev - 50)) {
|
||||||
if (distanceErr > 0) {
|
if (distanceErr > 0) {
|
||||||
enable = 1;
|
enable = 1;
|
||||||
}
|
}
|
||||||
|
@ -331,10 +338,11 @@ int main(void) {
|
||||||
enable = 0;
|
enable = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
timeoutCnt = 0;
|
timeoutCntGen = 0;
|
||||||
|
timeoutFlgGen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeoutCnt > TIMEOUT) {
|
if (timeoutFlgGen) {
|
||||||
pwml = 0;
|
pwml = 0;
|
||||||
pwmr = 0;
|
pwmr = 0;
|
||||||
enable = 0;
|
enable = 0;
|
||||||
|
@ -368,7 +376,8 @@ int main(void) {
|
||||||
#ifdef SUPPORT_LCD
|
#ifdef SUPPORT_LCD
|
||||||
LCD_SetLocation(&lcd, 0, 0); LCD_WriteString(&lcd, "Nunchuk Control");
|
LCD_SetLocation(&lcd, 0, 0); LCD_WriteString(&lcd, "Nunchuk Control");
|
||||||
#endif
|
#endif
|
||||||
timeoutCnt = 0;
|
timeoutCntGen = 0;
|
||||||
|
timeoutFlgGen = 0;
|
||||||
HAL_Delay(1000);
|
HAL_Delay(1000);
|
||||||
nunchuk_connected = 1;
|
nunchuk_connected = 1;
|
||||||
}
|
}
|
||||||
|
@ -394,11 +403,11 @@ int main(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ####### SIDEBOARDS HANDLING #######
|
// ####### SIDEBOARDS HANDLING #######
|
||||||
#if defined(SIDEBOARD_SERIAL_USART2)
|
#if defined(SIDEBOARD_SERIAL_USART2) && defined(FEEDBACK_SERIAL_USART2)
|
||||||
sideboardLeds(&sideboard_leds_L);
|
sideboardLeds(&sideboard_leds_L);
|
||||||
sideboardSensors((uint8_t)Sideboard_L.sensors);
|
sideboardSensors((uint8_t)Sideboard_L.sensors);
|
||||||
#endif
|
#endif
|
||||||
#if defined(SIDEBOARD_SERIAL_USART3)
|
#if defined(SIDEBOARD_SERIAL_USART3) && defined(FEEDBACK_SERIAL_USART3)
|
||||||
sideboardLeds(&sideboard_leds_R);
|
sideboardLeds(&sideboard_leds_R);
|
||||||
sideboardSensors((uint8_t)Sideboard_R.sensors);
|
sideboardSensors((uint8_t)Sideboard_R.sensors);
|
||||||
#endif
|
#endif
|
||||||
|
@ -412,8 +421,8 @@ int main(void) {
|
||||||
#if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3)
|
#if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3)
|
||||||
if (main_loop_counter % 25 == 0) { // Send data periodically every 125 ms
|
if (main_loop_counter % 25 == 0) { // Send data periodically every 125 ms
|
||||||
printf("in1:%i in2:%i cmdL:%i cmdR:%i BatADC:%i BatV:%i TempADC:%i Temp:%i\r\n",
|
printf("in1:%i in2:%i cmdL:%i cmdR:%i BatADC:%i BatV:%i TempADC:%i Temp:%i\r\n",
|
||||||
input1, // 1: INPUT1
|
input1[inIdx].raw, // 1: INPUT1
|
||||||
input2, // 2: INPUT2
|
input2[inIdx].raw, // 2: INPUT2
|
||||||
cmdL, // 3: output command: [-1000, 1000]
|
cmdL, // 3: output command: [-1000, 1000]
|
||||||
cmdR, // 4: output command: [-1000, 1000]
|
cmdR, // 4: output command: [-1000, 1000]
|
||||||
adc_buffer.batt1, // 5: for battery voltage calibration
|
adc_buffer.batt1, // 5: for battery voltage calibration
|
||||||
|
@ -427,8 +436,8 @@ int main(void) {
|
||||||
#if defined(FEEDBACK_SERIAL_USART2) || defined(FEEDBACK_SERIAL_USART3)
|
#if defined(FEEDBACK_SERIAL_USART2) || defined(FEEDBACK_SERIAL_USART3)
|
||||||
if (main_loop_counter % 2 == 0) { // Send data periodically every 10 ms
|
if (main_loop_counter % 2 == 0) { // Send data periodically every 10 ms
|
||||||
Feedback.start = (uint16_t)SERIAL_START_FRAME;
|
Feedback.start = (uint16_t)SERIAL_START_FRAME;
|
||||||
Feedback.cmd1 = (int16_t)cmd1;
|
Feedback.cmd1 = (int16_t)input1[inIdx].cmd;
|
||||||
Feedback.cmd2 = (int16_t)cmd2;
|
Feedback.cmd2 = (int16_t)input2[inIdx].cmd;
|
||||||
Feedback.speedR_meas = (int16_t)rtY_Right.n_mot;
|
Feedback.speedR_meas = (int16_t)rtY_Right.n_mot;
|
||||||
Feedback.speedL_meas = (int16_t)rtY_Left.n_mot;
|
Feedback.speedL_meas = (int16_t)rtY_Left.n_mot;
|
||||||
Feedback.batVoltage = (int16_t)(batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC);
|
Feedback.batVoltage = (int16_t)(batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC);
|
||||||
|
@ -436,22 +445,22 @@ int main(void) {
|
||||||
|
|
||||||
#if defined(FEEDBACK_SERIAL_USART2)
|
#if defined(FEEDBACK_SERIAL_USART2)
|
||||||
if(__HAL_DMA_GET_COUNTER(huart2.hdmatx) == 0) {
|
if(__HAL_DMA_GET_COUNTER(huart2.hdmatx) == 0) {
|
||||||
Feedback.cmdLed = (uint16_t)sideboard_leds_L;
|
Feedback.cmdLed = (uint16_t)sideboard_leds_L;
|
||||||
Feedback.checksum = (uint16_t)(Feedback.start ^ Feedback.cmd1 ^ Feedback.cmd2 ^ Feedback.speedR_meas ^ Feedback.speedL_meas
|
Feedback.checksum = (uint16_t)(Feedback.start ^ Feedback.cmd1 ^ Feedback.cmd2 ^ Feedback.speedR_meas ^ Feedback.speedL_meas
|
||||||
^ Feedback.batVoltage ^ Feedback.boardTemp ^ Feedback.cmdLed);
|
^ Feedback.batVoltage ^ Feedback.boardTemp ^ Feedback.cmdLed);
|
||||||
|
|
||||||
HAL_UART_Transmit_DMA(&huart2, (uint8_t *)&Feedback, sizeof(Feedback));
|
HAL_UART_Transmit_DMA(&huart2, (uint8_t *)&Feedback, sizeof(Feedback));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(FEEDBACK_SERIAL_USART3)
|
#if defined(FEEDBACK_SERIAL_USART3)
|
||||||
if(__HAL_DMA_GET_COUNTER(huart3.hdmatx) == 0) {
|
if(__HAL_DMA_GET_COUNTER(huart3.hdmatx) == 0) {
|
||||||
Feedback.cmdLed = (uint16_t)sideboard_leds_R;
|
Feedback.cmdLed = (uint16_t)sideboard_leds_R;
|
||||||
Feedback.checksum = (uint16_t)(Feedback.start ^ Feedback.cmd1 ^ Feedback.cmd2 ^ Feedback.speedR_meas ^ Feedback.speedL_meas
|
Feedback.checksum = (uint16_t)(Feedback.start ^ Feedback.cmd1 ^ Feedback.cmd2 ^ Feedback.speedR_meas ^ Feedback.speedL_meas
|
||||||
^ Feedback.batVoltage ^ Feedback.boardTemp ^ Feedback.cmdLed);
|
^ Feedback.batVoltage ^ Feedback.boardTemp ^ Feedback.cmdLed);
|
||||||
|
|
||||||
HAL_UART_Transmit_DMA(&huart3, (uint8_t *)&Feedback, sizeof(Feedback));
|
HAL_UART_Transmit_DMA(&huart3, (uint8_t *)&Feedback, sizeof(Feedback));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -464,11 +473,11 @@ int main(void) {
|
||||||
} else if (rtY_Left.z_errCode || rtY_Right.z_errCode) { // 1 beep (low pitch): Motor error, disable motors
|
} else if (rtY_Left.z_errCode || rtY_Right.z_errCode) { // 1 beep (low pitch): Motor error, disable motors
|
||||||
enable = 0;
|
enable = 0;
|
||||||
beepCount(1, 24, 1);
|
beepCount(1, 24, 1);
|
||||||
} else if (timeoutFlagADC) { // 2 beeps (low pitch): ADC timeout
|
} else if (timeoutFlgADC) { // 2 beeps (low pitch): ADC timeout
|
||||||
beepCount(2, 24, 1);
|
beepCount(2, 24, 1);
|
||||||
} else if (timeoutFlagSerial) { // 3 beeps (low pitch): Serial timeout
|
} else if (timeoutFlgSerial) { // 3 beeps (low pitch): Serial timeout
|
||||||
beepCount(3, 24, 1);
|
beepCount(3, 24, 1);
|
||||||
} else if (timeoutCnt > TIMEOUT) { // 4 beeps (low pitch): General timeout (PPM, PWM, Nunchuck)
|
} else if (timeoutFlgGen) { // 4 beeps (low pitch): General timeout (PPM, PWM, Nunchuk)
|
||||||
beepCount(4, 24, 1);
|
beepCount(4, 24, 1);
|
||||||
} else if (TEMP_WARNING_ENABLE && board_temp_deg_c >= TEMP_WARNING) { // 5 beeps (low pitch): Mainboard temperature warning
|
} else if (TEMP_WARNING_ENABLE && board_temp_deg_c >= TEMP_WARNING) { // 5 beeps (low pitch): Mainboard temperature warning
|
||||||
beepCount(5, 24, 1);
|
beepCount(5, 24, 1);
|
||||||
|
@ -497,10 +506,9 @@ int main(void) {
|
||||||
|
|
||||||
// HAL_GPIO_TogglePin(LED_PORT, LED_PIN); // This is to measure the main() loop duration with an oscilloscope connected to LED_PIN
|
// HAL_GPIO_TogglePin(LED_PORT, LED_PIN); // This is to measure the main() loop duration with an oscilloscope connected to LED_PIN
|
||||||
// Update main loop states
|
// Update main loop states
|
||||||
lastCmdL = cmdL;
|
cmdL_prev = cmdL;
|
||||||
lastCmdR = cmdR;
|
cmdR_prev = cmdR;
|
||||||
main_loop_counter++;
|
main_loop_counter++;
|
||||||
timeoutCnt++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1291
Src/util.c
|
@ -0,0 +1,5 @@
|
||||||
|
https://s.click.aliexpress.com/e/_ATlz43
|
||||||
|
https://www.banggood.com/custlink/vvDdP7tGZ2
|
||||||
|
https://www.banggood.com/custlink/3KvdPnfDPc
|
||||||
|
https://www.banggood.com/custlink/KD3RFswKcT
|
||||||
|
https://www.banggood.com/custlink/K33dH7HDjt
|
After Width: | Height: | Size: 233 KiB |
After Width: | Height: | Size: 566 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 49 KiB |