From b0d086614758b33d33a0b3f4d2a58b3b85e918e9 Mon Sep 17 00:00:00 2001 From: JbLb Date: Tue, 15 Dec 2020 15:51:06 +0100 Subject: [PATCH] add VARIANT_USART_JBLB (usart based in TORQUE Mode) --- Inc/config.h | 69 ++++++++++++++++++++++++++++++++++++-------------- platformio.ini | 28 ++++++++++++++++++-- 2 files changed, 76 insertions(+), 21 deletions(-) diff --git a/Inc/config.h b/Inc/config.h index 1d9924f..c5b1356 100644 --- a/Inc/config.h +++ b/Inc/config.h @@ -12,6 +12,7 @@ #if !defined(PLATFORMIO) //#define VARIANT_ADC // Variant for control via ADC input //#define VARIANT_USART // Variant for Serial control via USART3 input + #define VARIANT_USART_JBLB //#define VARIANT_NUNCHUK // Variant for Nunchuk controlled vehicle build //#define VARIANT_PPM // Variant for RC-Remote with PPM-Sum Signal //#define VARIANT_PWM // Variant for RC-Remote with PWM Signal @@ -74,7 +75,7 @@ #define BAT_BLINK_INTERVAL 80 // battery led blink interval (80 loops * 5ms ~= 400ms) #define BAT_LVL5 (390 * BAT_CELLS * BAT_CALIB_ADC) / BAT_CALIB_REAL_VOLTAGE // Green blink: no beep #define BAT_LVL4 (380 * BAT_CELLS * BAT_CALIB_ADC) / BAT_CALIB_REAL_VOLTAGE // Yellow: no beep -#define BAT_LVL3 (370 * BAT_CELLS * BAT_CALIB_ADC) / BAT_CALIB_REAL_VOLTAGE // Yellow blink: no beep +#define BAT_LVL3 (370 * BAT_CELLS * BAT_CALIB_ADC) / BAT_CALIB_REAL_VOLTAGE // Yellow blink: no beep #define BAT_LVL2 (360 * BAT_CELLS * BAT_CALIB_ADC) / BAT_CALIB_REAL_VOLTAGE // Red: gently beep at this voltage level. [V*100/cell]. In this case 3.60 V/cell #define BAT_LVL1 (350 * BAT_CELLS * BAT_CALIB_ADC) / BAT_CALIB_REAL_VOLTAGE // Red blink: fast beep. Your battery is almost empty. Charge now! [V*100/cell]. In this case 3.50 V/cell #define BAT_DEAD (337 * BAT_CELLS * BAT_CALIB_ADC) / BAT_CALIB_REAL_VOLTAGE // All leds off: undervoltage poweroff. (while not driving) [V*100/cell]. In this case 3.37 V/cell @@ -258,7 +259,7 @@ #define INPUT1_MID 0 // mid ADC1-value while poti at minimum-position (ADC1_MIN - ADC1_MAX) #define INPUT1_MAX 4095 // max ADC1-value while poti at maximum-position (0 - 4095) #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 0 // min ADC2-value while poti at minimum-position (0 - 4095) #define INPUT2_MID 0 // mid ADC2-value while poti at minimum-position (ADC2_MIN - ADC2_MAX) @@ -286,7 +287,7 @@ #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 1 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect #define INPUT2_MIN -1000 // (-1000 - 0) #define INPUT2_MID 0 @@ -298,6 +299,36 @@ // ######################## END OF VARIANT_USART SETTINGS ######################### +// ############################ VARIANT_USART SETTINGS by JBLB ############################ +#ifdef VARIANT_USART_JBLB + // #define SIDEBOARD_SERIAL_USART2 + // #define CONTROL_SERIAL_USART2 // 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! + + #undef CTRL_MOD_REQ + #define CTRL_MOD_REQ TRQ_MODE // HOVERCAR works best in TORQUE Mode + + // #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 1 // 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 1 // 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_RIGHT // use right sensor board cable for button inputs. Disable DEBUG_SERIAL_USART3! +#endif +// ######################## END OF VARIANT_USART SETTINGS by JBLB ######################### + + // ################################# VARIANT_NUNCHUK SETTINGS ############################ #ifdef VARIANT_NUNCHUK @@ -314,7 +345,7 @@ #define INPUT1_MID 0 #define INPUT1_MAX 1024 // (0 - 1024) #define INPUT1_DEADBAND 0 // 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 -1024 // (-1024 - 0) #define INPUT2_MID 0 @@ -351,7 +382,7 @@ #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 @@ -383,13 +414,13 @@ #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 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. @@ -404,7 +435,7 @@ // ################################# VARIANT_IBUS SETTINGS ############################## #ifdef VARIANT_IBUS -/* 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. */ #define CONTROL_IBUS // use IBUS as input @@ -428,7 +459,7 @@ #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 @@ -446,19 +477,19 @@ #define CONTROL_ADC // use ADC as 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 INPUT1_TYPE 1 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect #define INPUT1_MIN 1000 // min ADC1-value while poti at minimum-position (0 - 4095) #define INPUT1_MID 0 #define INPUT1_MAX 2500 // max ADC1-value while poti at maximum-position (0 - 4095) #define INPUT1_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0) - + #define INPUT2_TYPE 1 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect #define INPUT2_MIN 500 // min ADC2-value while poti at minimum-position (0 - 4095) #define INPUT2_MID 0 #define INPUT2_MAX 2200 // max ADC2-value while poti at maximum-position (0 - 4095) #define INPUT2_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0) - + #define SPEED_COEFFICIENT 16384 // 1.0f #define STEER_COEFFICIENT 0 // 0.0f // #define INVERT_R_DIRECTION // Invert rotation of right motor @@ -488,10 +519,10 @@ // Communication: [DONE] // Balancing controller: [TODO] #ifdef VARIANT_HOVERBOARD - #define SIDEBOARD_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used! + #define SIDEBOARD_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used! #define FEEDBACK_SERIAL_USART2 - #define SIDEBOARD_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used! - #define FEEDBACK_SERIAL_USART3 + #define SIDEBOARD_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used! + #define FEEDBACK_SERIAL_USART3 #endif // ######################## END OF VARIANT_HOVERBOARD SETTINGS ######################### @@ -529,21 +560,21 @@ #define DEBUG_SERIAL_USART2 // left sensor cable debug #else #define DEBUG_SERIAL_USART3 // right sensor cable debug - #endif + #endif // Min / Max values of each channel (use DEBUG to determine these values) #define INPUT1_TYPE 0 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 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 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. @@ -604,7 +635,7 @@ // ############################### VALIDATE SETTINGS ############################### #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_SKATEBOARD) + !defined(VARIANT_IBUS) && !defined(VARIANT_HOVERCAR) && !defined(VARIANT_HOVERBOARD) && !defined(VARIANT_TRANSPOTTER) && !defined(VARIANT_SKATEBOARD) && !defined(VARIANT_USART_JBLB) #error Variant not defined! Please check platformio.ini or Inc/config.h for available variants. #endif diff --git a/platformio.ini b/platformio.ini index c31fc8d..9df92e5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -2,8 +2,8 @@ ; http://docs.platformio.org/page/projectconf.html [platformio] -include_dir = Inc -src_dir = Src +include_dir = ./Inc +src_dir = ./Src ;=================== VARIANT SELECTION ========================== ; @@ -19,6 +19,8 @@ src_dir = Src ;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_SKATEBOARD ; Variant for SKATEBOARD build controlled via RC-Remotes with PWM signal +default_envs = VARIANT_USART_JBLB + ;================================================================ ;================================================================ @@ -45,6 +47,28 @@ build_flags = ;================================================================ +[env:VARIANT_USART_JBLB] +platform = ststm32 +framework = stm32cube +board = genericSTM32F103RC +debug_tool = stlink +upload_protocol = stlink + +; Serial Port settings (make sure the COM port is correct) +monitor_port = COM5 +monitor_speed = 38400 + +build_flags = + -DUSE_HAL_DRIVER + -DSTM32F103xE + -T./STM32F103RCTx_FLASH.ld + -lc + -lm + -g -ggdb ; to generate correctly the 'firmware.elf' for STM STUDIO vizualization + -D VARIANT_USART_JBLB + +;================================================================ + [env:VARIANT_USART] platform = ststm32 framework = stm32cube