created SKATEBOARD variant

This commit is contained in:
EmanuelFeru 2020-07-20 20:33:42 +02:00
parent dcdac4f6db
commit 733fd80362
4 changed files with 70 additions and 4 deletions

View File

@ -19,6 +19,7 @@
//#define VARIANT_HOVERCAR // Variant for HOVERCAR build //#define VARIANT_HOVERCAR // Variant for HOVERCAR build
//#define VARIANT_HOVERBOARD // Variant for HOVERBOARD build //#define VARIANT_HOVERBOARD // Variant for HOVERBOARD build
//#define VARIANT_TRANSPOTTER // Variant for TRANSPOTTER build https://github.com/NiklasFauth/hoverboard-firmware-hack/wiki/Build-Instruction:-TranspOtter https://hackaday.io/project/161891-transpotter-ng //#define VARIANT_TRANSPOTTER // Variant for TRANSPOTTER build https://github.com/NiklasFauth/hoverboard-firmware-hack/wiki/Build-Instruction:-TranspOtter https://hackaday.io/project/161891-transpotter-ng
//#define VARIANT_SKATEBOARD // Variant for SKATEBOARD build
#endif #endif
// ########################### END OF VARIANT SELECTION ############################ // ########################### END OF VARIANT SELECTION ############################
@ -432,6 +433,40 @@
// ############################# END OF VARIANT_TRANSPOTTER SETTINGS ######################## // ############################# END OF VARIANT_TRANSPOTTER SETTINGS ########################
// ################################# VARIANT_PWM SETTINGS ##############################
#ifdef VARIANT_SKATEBOARD
/* ###### CONTROL VIA RC REMOTE ######
* right sensor board cable. Connect PB10 to channel 1 and PB11 to channel 2 on receiver.
* Channel 1: steering, Channel 2: speed.
*/
#undef CTRL_MOD_REQ
#define CTRL_MOD_REQ TRQ_MODE // SKATEBOARD works best in TORQUE Mode
#define CONTROL_PWM_LEFT // use RC PWM as input on the LEFT cable. disable DEBUG_SERIAL_USART2!
// #define CONTROL_PWM_RIGHT // use RC PWM as input on the RIGHT cable. disable DEBUG_SERIAL_USART3!
#ifdef CONTROL_PWM_RIGHT
#define DEBUG_SERIAL_USART2 // left sensor cable debug
#else
#define DEBUG_SERIAL_USART3 // right sensor cable debug
#endif
#define PWM_DEADBAND 100 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0)
// Min / Max values of each channel (use DEBUG to determine these values)
#define PWM_CH1_MAX 1000 // (0 - 1000)
#define PWM_CH1_MIN -1000 // (-1000 - 0)
#define PWM_CH2_MAX 700 // (0 - 1000)
#define PWM_CH2_MIN -800 // (-1000 - 0)
#define PWM_CH2_OUT_MIN -150 // (-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_L_DIRECTION
// #define SUPPORT_BUTTONS_LEFT // use left sensor board cable for button inputs. Disable DEBUG_SERIAL_USART2!
// #define SUPPORT_BUTTONS_RIGHT // use right sensor board cable for button inputs. Disable DEBUG_SERIAL_USART3!
// #define STANDSTILL_HOLD_ENABLE // [-] Flag to hold the position when standtill is reached. Only available and makes sense for VOLTAGE or TORQUE mode.
#endif
// ############################# END OF VARIANT_PPM SETTINGS ############################
// ########################### UART SETIINGS ############################ // ########################### UART SETIINGS ############################
#if defined(FEEDBACK_SERIAL_USART2) || defined(CONTROL_SERIAL_USART2) || defined(DEBUG_SERIAL_USART2) || defined(SIDEBOARD_SERIAL_USART2) || \ #if defined(FEEDBACK_SERIAL_USART2) || defined(CONTROL_SERIAL_USART2) || defined(DEBUG_SERIAL_USART2) || defined(SIDEBOARD_SERIAL_USART2) || \
@ -473,7 +508,7 @@
// ############################### VALIDATE SETTINGS ############################### // ############################### VALIDATE SETTINGS ###############################
#if !defined(VARIANT_ADC) && !defined(VARIANT_USART) && !defined(VARIANT_NUNCHUK) && !defined(VARIANT_PPM) && !defined(VARIANT_PWM) && \ #if !defined(VARIANT_ADC) && !defined(VARIANT_USART) && !defined(VARIANT_NUNCHUK) && !defined(VARIANT_PPM) && !defined(VARIANT_PWM) && \
!defined(VARIANT_IBUS) && !defined(VARIANT_HOVERCAR) && !defined(VARIANT_HOVERBOARD) && !defined(VARIANT_TRANSPOTTER) !defined(VARIANT_IBUS) && !defined(VARIANT_HOVERCAR) && !defined(VARIANT_HOVERBOARD) && !defined(VARIANT_TRANSPOTTER) && !defined(VARIANT_SKATEBOARD)
#error Variant not defined! Please check platformio.ini or Inc/config.h for available variants. #error Variant not defined! Please check platformio.ini or Inc/config.h for available variants.
#endif #endif

View File

@ -213,7 +213,7 @@ int main(void) {
} }
// ####### VARIANT_HOVERCAR ####### // ####### VARIANT_HOVERCAR #######
#if defined(VARIANT_HOVERCAR) || 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]
#endif #endif
@ -240,6 +240,12 @@ int main(void) {
} }
#endif #endif
#ifdef VARIANT_SKATEBOARD
if (cmd2 < 0) { // When Throttle pedal is negative, it acts as brake. This condition is to make sure it goes to 0 as we reach standstill (to avoid Reverse driving)
cmd2 = (int16_t)((cmd2 * speedBlend) >> 15);
}
#endif
// ####### LOW-PASS FILTER ####### // ####### LOW-PASS FILTER #######
rateLimiter16(cmd1, RATE, &steerRateFixdt); rateLimiter16(cmd1, RATE, &steerRateFixdt);
rateLimiter16(cmd2, RATE, &speedRateFixdt); rateLimiter16(cmd2, RATE, &speedRateFixdt);

View File

@ -737,8 +737,8 @@ void readCommand(void) {
#endif #endif
#if defined(CONTROL_PPM_LEFT) || defined(CONTROL_PPM_RIGHT) #if defined(CONTROL_PPM_LEFT) || defined(CONTROL_PPM_RIGHT)
cmd1 = CLAMP(addDeadBand((ppm_captured_value[0] - 500) * 2, PPM_DEADBAND, PPM_CH1_MIN, PPM_CH1_MAX), INPUT_MIN, INPUT_MAX); cmd1 = addDeadBand((ppm_captured_value[0] - 500) * 2, PPM_DEADBAND, PPM_CH1_MIN, PPM_CH1_MAX, INPUT_MIN, INPUT_MAX);
cmd2 = CLAMP(addDeadBand((ppm_captured_value[1] - 500) * 2, PPM_DEADBAND, PPM_CH2_MIN, PPM_CH2_MAX), INPUT_MIN, INPUT_MAX); cmd2 = addDeadBand((ppm_captured_value[1] - 500) * 2, PPM_DEADBAND, PPM_CH2_MIN, PPM_CH2_MAX, INPUT_MIN, INPUT_MAX);
#ifdef SUPPORT_BUTTONS #ifdef SUPPORT_BUTTONS
button1 = ppm_captured_value[5] > 500; button1 = ppm_captured_value[5] > 500;
button2 = 0; button2 = 0;
@ -751,7 +751,11 @@ void readCommand(void) {
#if defined(CONTROL_PWM_LEFT) || defined(CONTROL_PWM_RIGHT) #if defined(CONTROL_PWM_LEFT) || defined(CONTROL_PWM_RIGHT)
cmd1 = addDeadBand((pwm_captured_ch1_value - 500) * 2, PWM_DEADBAND, PWM_CH1_MIN, PWM_CH1_MAX, INPUT_MIN, INPUT_MAX); cmd1 = addDeadBand((pwm_captured_ch1_value - 500) * 2, PWM_DEADBAND, PWM_CH1_MIN, PWM_CH1_MAX, INPUT_MIN, INPUT_MAX);
#if !defined(VARIANT_SKATEBOARD)
cmd2 = addDeadBand((pwm_captured_ch2_value - 500) * 2, PWM_DEADBAND, PWM_CH2_MIN, PWM_CH2_MAX, INPUT_MIN, INPUT_MAX); cmd2 = addDeadBand((pwm_captured_ch2_value - 500) * 2, PWM_DEADBAND, PWM_CH2_MIN, PWM_CH2_MAX, INPUT_MIN, INPUT_MAX);
#else
cmd2 = addDeadBand((pwm_captured_ch2_value - 500) * 2, PWM_DEADBAND, PWM_CH2_MIN, PWM_CH2_MAX, PWM_CH2_OUT_MIN, INPUT_MAX);
#endif
#if defined(SUPPORT_BUTTONS_LEFT) || defined(SUPPORT_BUTTONS_RIGHT) #if defined(SUPPORT_BUTTONS_LEFT) || defined(SUPPORT_BUTTONS_RIGHT)
button1 = !HAL_GPIO_ReadPin(BUTTON1_PORT, BUTTON1_PIN); button1 = !HAL_GPIO_ReadPin(BUTTON1_PORT, BUTTON1_PIN);
button2 = !HAL_GPIO_ReadPin(BUTTON2_PORT, BUTTON2_PIN); button2 = !HAL_GPIO_ReadPin(BUTTON2_PORT, BUTTON2_PIN);

View File

@ -18,6 +18,7 @@ src_dir = Src
;default_envs = VARIANT_HOVERCAR ; Variant for HOVERCAR build ;default_envs = VARIANT_HOVERCAR ; Variant for HOVERCAR build
;default_envs = VARIANT_HOVERBOARD ; Variant for HOVERBOARD ;default_envs = VARIANT_HOVERBOARD ; Variant for HOVERBOARD
;default_envs = VARIANT_TRANSPOTTER ; Variant for TRANSPOTTER build https://github.com/NiklasFauth/hoverboard-firmware-hack/wiki/Build-Instruction:-TranspOtter https://hackaday.io/project/161891-transpotter-ng ;default_envs = VARIANT_TRANSPOTTER ; Variant for TRANSPOTTER build https://github.com/NiklasFauth/hoverboard-firmware-hack/wiki/Build-Instruction:-TranspOtter https://hackaday.io/project/161891-transpotter-ng
;default_envs = VARIANT_SKATEBOARD ; Variant for SKATEBOARD build controlled via RC-Remotes with PWM signal
;================================================================ ;================================================================
;================================================================ ;================================================================
@ -208,3 +209,23 @@ build_flags =
-D VARIANT_TRANSPOTTER -D VARIANT_TRANSPOTTER
;================================================================ ;================================================================
[env:VARIANT_SKATEBOARD]
platform = ststm32
framework = stm32cube
board = genericSTM32F103RC
debug_tool = stlink
upload_protocol = stlink
build_flags =
-DUSE_HAL_DRIVER
-DSTM32F103xE
-Wl,-T./STM32F103RCTx_FLASH.ld
-Wl,-lc
-Wl,-lm
-g -ggdb ; to generate correctly the 'firmware.elf' for STM STUDIO vizualization
# -Wl,-lnosys
-D VARIANT_SKATEBOARD
;================================================================