Merge pull request #84 from EmanuelFeru/variant-skateboard-PWM
Variant skateboard pwm
This commit is contained in:
commit
b1f7c4c296
49
Inc/config.h
49
Inc/config.h
|
@ -19,6 +19,7 @@
|
|||
//#define VARIANT_HOVERCAR // Variant for HOVERCAR 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_SKATEBOARD // Variant for SKATEBOARD build
|
||||
#endif
|
||||
// ########################### END OF VARIANT SELECTION ############################
|
||||
|
||||
|
@ -323,11 +324,6 @@
|
|||
*/
|
||||
#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)
|
||||
|
@ -341,8 +337,13 @@
|
|||
// #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!
|
||||
#ifdef CONTROL_PWM_RIGHT
|
||||
#define DEBUG_SERIAL_USART2 // left sensor cable debug
|
||||
#else
|
||||
#define DEBUG_SERIAL_USART3 // right sensor cable debug
|
||||
#endif
|
||||
#endif
|
||||
// ############################# END OF VARIANT_PPM SETTINGS ############################
|
||||
// ############################# END OF VARIANT_PWM SETTINGS ############################
|
||||
|
||||
|
||||
|
||||
|
@ -432,6 +433,40 @@
|
|||
// ############################# END OF VARIANT_TRANSPOTTER SETTINGS ########################
|
||||
|
||||
|
||||
// ################################# VARIANT_SKATEBOARD 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!
|
||||
#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 -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_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.
|
||||
#ifdef CONTROL_PWM_RIGHT
|
||||
#define DEBUG_SERIAL_USART2 // left sensor cable debug
|
||||
#else
|
||||
#define DEBUG_SERIAL_USART3 // right sensor cable debug
|
||||
#endif
|
||||
#endif
|
||||
// ############################# END OF VARIANT_SKATEBOARD SETTINGS ############################
|
||||
|
||||
|
||||
|
||||
// ########################### UART SETIINGS ############################
|
||||
#if defined(FEEDBACK_SERIAL_USART2) || defined(CONTROL_SERIAL_USART2) || defined(DEBUG_SERIAL_USART2) || defined(SIDEBOARD_SERIAL_USART2) || \
|
||||
|
@ -473,7 +508,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_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.
|
||||
#endif
|
||||
|
||||
|
|
|
@ -125,6 +125,7 @@ This firmware offers currently these variants (selectable in [platformio.ini](/p
|
|||
- **VARIANT_HOVERCAR**: In this variant the motors are controlled by two pedals brake and throttle. Reverse is engaged by double tapping on the brake pedal at standstill. See [HOVERCAR video](https://www.youtube.com/watch?v=IgHCcj0NgWQ&t=).
|
||||
- **VARIANT_HOVERBOARD**: In this variant the mainboard reads the sideboards data. The sideboards need to be flashed with the hacked version. Only balancing controller is still to be implemented.
|
||||
- **VARIANT_TRANSPOTTER**: This build is for transpotter which is a hoverboard based transportation system. For more details on how to build it check [here](https://github.com/NiklasFauth/hoverboard-firmware-hack/wiki/Build-Instruction:-TranspOtter) and [here](https://hackaday.io/project/161891-transpotter-ng).
|
||||
- **VARIANT_SKATEBOARD**: This is for skateboard build, controlled using an RC remote with PWM signal connected to the right sensor cable.
|
||||
|
||||
Of course the firmware can be further customized for other needs or projects.
|
||||
|
||||
|
|
14
Src/main.c
14
Src/main.c
|
@ -213,7 +213,7 @@ int main(void) {
|
|||
}
|
||||
|
||||
// ####### 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)
|
||||
speedBlend = (uint16_t)(((CLAMP(speedAvgAbs,10,60) - 10) << 15) / 50); // speedBlend [0,1] is within [10 rpm, 60rpm]
|
||||
#endif
|
||||
|
@ -236,7 +236,17 @@ int main(void) {
|
|||
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);
|
||||
} else {
|
||||
cmd1 = (int16_t)(( cmd1 * speedBlend) >> 15);
|
||||
cmd1 = (int16_t)(( cmd1 * speedBlend) >> 15);
|
||||
}
|
||||
#endif
|
||||
|
||||
#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 (speedAvg > 0) { // Make sure the braking is opposite to the direction of motion
|
||||
cmd2 = (int16_t)(( cmd2 * speedBlend) >> 15);
|
||||
} else {
|
||||
cmd2 = (int16_t)((-cmd2 * speedBlend) >> 15);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -751,7 +751,11 @@ void readCommand(void) {
|
|||
|
||||
#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);
|
||||
#if !defined(VARIANT_SKATEBOARD)
|
||||
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)
|
||||
button1 = !HAL_GPIO_ReadPin(BUTTON1_PORT, BUTTON1_PIN);
|
||||
button2 = !HAL_GPIO_ReadPin(BUTTON2_PORT, BUTTON2_PIN);
|
||||
|
|
|
@ -18,6 +18,7 @@ src_dir = Src
|
|||
;default_envs = VARIANT_HOVERCAR ; Variant for HOVERCAR build
|
||||
;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
|
||||
;================================================================
|
||||
|
||||
;================================================================
|
||||
|
@ -208,3 +209,23 @@ build_flags =
|
|||
-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
|
||||
|
||||
;================================================================
|
||||
|
|
Loading…
Reference in New Issue