forked from EFeru/hoverboard-firmware-hack-FOC
Merge pull request #309 from Guruth/MultiModeHoverCar
Multiple Drive Modes for Hovercar variant
This commit is contained in:
13
Inc/config.h
13
Inc/config.h
@@ -524,6 +524,19 @@
|
|||||||
// #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.
|
||||||
|
|
||||||
|
// #define MULTI_MODE_DRIVE
|
||||||
|
#ifdef MULTI_MODE_DRIVE
|
||||||
|
#define MULTI_MODE_DRIVE_M1_MAX 175
|
||||||
|
#define MULTI_MODE_DRIVE_M1_RATE 175
|
||||||
|
|
||||||
|
#define MULTI_MODE_DRIVE_M2_MAX 500
|
||||||
|
#define MULTI_MODE_DRIVE_M2_RATE 300
|
||||||
|
|
||||||
|
#define MULTI_MODE_DRIVE_M3_MAX 1000
|
||||||
|
#define MULTI_MODE_DRIVE_M3_RATE 450
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Multiple tap detection: default DOUBLE Tap on Brake pedal (4 pulses)
|
// Multiple tap detection: default DOUBLE Tap on Brake pedal (4 pulses)
|
||||||
|
42
Src/main.c
42
Src/main.c
@@ -162,6 +162,14 @@ static uint32_t buzzerTimer_prev = 0;
|
|||||||
static uint32_t inactivity_timeout_counter;
|
static uint32_t inactivity_timeout_counter;
|
||||||
static MultipleTap MultipleTapBrake; // define multiple tap functionality for the Brake pedal
|
static MultipleTap MultipleTapBrake; // define multiple tap functionality for the Brake pedal
|
||||||
|
|
||||||
|
static uint16_t rate = RATE; // Adjustable rate to support multiple drive modes on startup
|
||||||
|
|
||||||
|
#ifdef MULTI_MODE_DRIVE
|
||||||
|
static uint8_t drive_mode;
|
||||||
|
static uint16_t max_speed;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
HAL_Init();
|
HAL_Init();
|
||||||
@@ -205,9 +213,32 @@ int main(void) {
|
|||||||
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;
|
||||||
|
|
||||||
|
#ifdef MULTI_MODE_DRIVE
|
||||||
|
if (adc_buffer.l_rx2 >= input1[0].min) {
|
||||||
|
drive_mode = 0;
|
||||||
|
max_speed = MULTI_MODE_DRIVE_M1_MAX;
|
||||||
|
rate = MULTI_MODE_DRIVE_M1_RATE;
|
||||||
|
} else if (adc_buffer.l_tx2 >= input2[0].min) {
|
||||||
|
drive_mode = 2;
|
||||||
|
max_speed = MULTI_MODE_DRIVE_M3_MAX;
|
||||||
|
rate = MULTI_MODE_DRIVE_M3_RATE;
|
||||||
|
} else {
|
||||||
|
drive_mode = 1;
|
||||||
|
max_speed = MULTI_MODE_DRIVE_M2_MAX;
|
||||||
|
rate = MULTI_MODE_DRIVE_M2_RATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Drive mode %i selected: max_speed:%i acc_rate:%i \r\n", drive_mode, max_speed, rate);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Loop until button is released
|
// Loop until button is released
|
||||||
while(HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) { HAL_Delay(10); }
|
while(HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) { HAL_Delay(10); }
|
||||||
|
|
||||||
|
#ifdef MULTI_MODE_DRIVE
|
||||||
|
// Wait until triggers are released
|
||||||
|
while((adc_buffer.l_rx2 + adc_buffer.l_tx2) >= (input1[0].min + input2[0].min)) { HAL_Delay(10); }
|
||||||
|
#endif
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
if (buzzerTimer - buzzerTimer_prev > 16*DELAY_IN_MAIN_LOOP) { // 1 ms = 16 ticks buzzerTimer
|
if (buzzerTimer - buzzerTimer_prev > 16*DELAY_IN_MAIN_LOOP) { // 1 ms = 16 ticks buzzerTimer
|
||||||
|
|
||||||
@@ -275,8 +306,8 @@ int main(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ####### LOW-PASS FILTER #######
|
// ####### LOW-PASS FILTER #######
|
||||||
rateLimiter16(input1[inIdx].cmd , RATE, &steerRateFixdt);
|
rateLimiter16(input1[inIdx].cmd, rate, &steerRateFixdt);
|
||||||
rateLimiter16(input2[inIdx].cmd , 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
|
||||||
@@ -285,6 +316,13 @@ int main(void) {
|
|||||||
// ####### 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 (inIdx == CONTROL_ADC) { // Only use use implementation below if pedals are in use (ADC input)
|
||||||
|
|
||||||
|
#ifdef MULTI_MODE_DRIVE
|
||||||
|
if (speed >= max_speed) {
|
||||||
|
speed = max_speed;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
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 {
|
||||||
|
Reference in New Issue
Block a user