- removed default / fallback variant; you are forced to define the variant of your choice now or build will stop with an error

- added condition in config.h to either take setting from platform.ini or config.h
- homogenized default_envs naming; all variants now have VARIANT_ as prefix
- added nunchuck variant in platform.ini and config.h
- added PPM variant in platform.ini and config.h
- README: added jan's nunchuck breakout board repo
This commit is contained in:
kai 2020-01-04 00:09:57 +01:00
parent 641fd0bd76
commit ec2f6a1eb6
6 changed files with 132 additions and 60 deletions

View File

@ -44,7 +44,7 @@ matrix:
before_script: arm-none-eabi-gcc --version
- name: platformio
script: platformio run -e VARIANT_ADC -e VARIANT_USART3 -e HOVERCAR -e TRANSPOTTER
script: platformio run -e VARIANT_ADC -e VARIANT_USART3 -e VARIANT_HOVERCAR -e VARIANT_TRANSPOTTER -e VARIANT_NUNCHUCK -e VARIANT_PPM
language: python
python:
- "2.7"

View File

@ -3,18 +3,24 @@
// ############################### DEFINE FIRMWARE VARIANT ###############################
// For variant selection, check platformio.ini
// For any particular needs, feel free to change this file according to your needs.
// or define the desired build variant here if you want to use make
// Select the VARIANT_ADC as default variant, in case NO variant is defined
#if !defined(VARIANT_ADC) && !defined(VARIANT_USART3) && !defined(HOVERCAR) && !defined(TRANSPOTTER)
#define VARIANT_ADC
#if !defined(PLATFORMIO)
//#define VARIANT_ADC // Variant for control via ADC input
//#define VARIANT_USART3 // Variant for Serial control via USART3 input
//#define VARIANT_HOVERCAR // Variant for HOVERCAR 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_NUNCHUCK // Variant for Nunchuck controlled vehicle build
//#define VARIANT_PPM // Variant for RC-Remote with PPM-Sum Signal
#endif
// For any particular needs, feel free to change this file according to your needs.
// ############################### DO-NOT-TOUCH SETTINGS ###############################
#define PWM_FREQ 16000 // PWM frequency in Hz
#define DEAD_TIME 48 // PWM deadtime
#ifdef TRANSPOTTER
#ifdef VARIANT_TRANSPOTTER
#define DELAY_IN_MAIN_LOOP 2
#else
#define DELAY_IN_MAIN_LOOP 5 // in ms. default 5. it is independent of all the timing critical stuff. do not touch if you do not know what you are doing.
@ -92,9 +98,9 @@
// ############################### SERIAL DEBUG ###############################
#ifndef TRANSPOTTER
#ifndef VARIANT_TRANSPOTTER
//#define DEBUG_SERIAL_SERVOTERM
#define DEBUG_SERIAL_ASCII // "1:345 2:1337 3:0 4:0 5:0 6:0 7:0 8:0\r\n"
//#define DEBUG_SERIAL_ASCII // "1:345 2:1337 3:0 4:0 5:0 6:0 7:0 8:0\r\n"
#endif
@ -109,7 +115,7 @@
#define USART3_BAUD 38400 // UART3 baud rate (short wired cable)
#define USART3_WORDLENGTH UART_WORDLENGTH_8B // UART_WORDLENGTH_8B or UART_WORDLENGTH_9B
#if defined(VARIANT_ADC) || defined(HOVERCAR)
#if defined(VARIANT_ADC) || defined(VARIANT_HOVERCAR)
// #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!
// #define DEBUG_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used!
@ -128,17 +134,19 @@
#endif
#if defined(FEEDBACK_SERIAL_USART2) || defined(DEBUG_SERIAL_USART2)
#define UART_DMA_CHANNEL DMA1_Channel7
#define UART_DMA_CHANNEL DMA1_Channel7
#endif
#if defined(FEEDBACK_SERIAL_USART3) || defined(DEBUG_SERIAL_USART3)
#define UART_DMA_CHANNEL DMA1_Channel2
#define UART_DMA_CHANNEL DMA1_Channel2
#endif
#ifdef VARIANT_PPM
// ###### CONTROL VIA RC REMOTE ######
// left sensor board cable. Channel 1: steering, Channel 2: speed.
//#define CONTROL_PPM // use PPM-Sum as input. disable CONTROL_SERIAL_USART2!
#define CONTROL_PPM // use PPM-Sum as input. disable CONTROL_SERIAL_USART2!
//#define PPM_NUM_CHANNELS 6 // total number of PPM channels to receive, even if they are not used.
#endif
// ###### CONTROL VIA TWO POTENTIOMETERS ######
/* ADC-calibration to cover the full poti-range:
@ -162,7 +170,7 @@
#define ADC2_MID 2048 // mid ADC2-value while poti at minimum-position (ADC2_MIN - ADC2_MAX)
#define ADC2_MAX 4095 // max ADC2-value while poti at maximum-position (0 - 4095)
#endif
#ifdef HOVERCAR
#ifdef VARIANT_HOVERCAR
#define CONTROL_ADC // use ADC as input. disable CONTROL_SERIAL_USART2, FEEDBACK_SERIAL_USART2, DEBUG_SERIAL_USART2!
#define ADC_PROTECT_ENA // ADC Protection Enable flag. Use this flag to make sure the ADC is protected when GND or Vcc wire is disconnected
#define ADC_PROTECT_TIMEOUT 30 // ADC Protection: number of wrong / missing input commands before safety state is taken
@ -173,14 +181,16 @@
#define ADC2_MAX 2200 // max ADC2-value while poti at maximum-position (0 - 4095)
#endif
// ###### CONTROL VIA NINTENDO NUNCHUCK ######
/* left sensor board cable.
#ifdef VARIANT_NUNCHUCK
// ###### CONTROL VIA NINTENDO NUNCHUCK ######
/* left sensor board cable.
* keep cable short, use shielded cable, use ferrits, stabalize voltage in nunchuck,
* use the right one of the 2 types of nunchucks, add i2c pullups.
* use original nunchuck. most clones does not work very well.
* Recommendation: Nunchuck Breakout Board https://github.com/Jan--Henrik/hoverboard-breakout
*/
// #define CONTROL_NUNCHUCK // use nunchuck as input. disable FEEDBACK_SERIAL_USART3, DEBUG_SERIAL_USART3!
#define CONTROL_NUNCHUCK // use nunchuck as input. disable FEEDBACK_SERIAL_USART3, DEBUG_SERIAL_USART3!
#endif
// ############################### MOTOR CONTROL #########################
// Control selections
@ -246,10 +256,12 @@
#define RATE 480 // 30.0f [-] lower value == slower rate [0, 32767] = [0.0, 2047.9375]. Do NOT make rate negative (>32767)
// Value of FILTER is in fixdt(0,16,16): VAL_fixedPoint = VAL_floatingPoint * 2^16. In this case 6553 = 0.1 * 2^16
#define FILTER 6553 // 0.1f [-] lower value == softer filter [0, 65535] = [0.0 - 1.0].
#ifndef VARIANT_NUNCHUCK
#define FILTER 6553 // 0.1f [-] lower value == softer filter [0, 65535] = [0.0 - 1.0].
#endif
// ################################# DEFAULT SETTINGS ############################
#if !defined(HOVERCAR) && !defined(TRANSPOTTER)
#if !defined(VARIANT_HOVERCAR) && !defined(VARIANT_TRANSPOTTER) && !defined(VARIANT_NUNCHUCK)
// Value of COEFFICIENT is in fixdt(1,16,14)
// If VAL_floatingPoint >= 0, VAL_fixedPoint = VAL_floatingPoint * 2^14
// If VAL_floatingPoint < 0, VAL_fixedPoint = 2^16 + floor(VAL_floatingPoint * 2^14).
@ -260,8 +272,8 @@
#define INVERT_L_DIRECTION
#endif
// ################################# HOVERCAR SETTINGS ############################
#ifdef HOVERCAR
// ################################# VARIANT_HOVERCAR SETTINGS ############################
#ifdef VARIANT_HOVERCAR
#define SPEED_COEFFICIENT 16384 // 1.0f
#define STEER_COEFFICIENT 0 // 0.0f
@ -269,8 +281,8 @@
// #define INVERT_L_DIRECTION
#endif
// ################################# TRANSPOTTER SETTINGS ############################
#ifdef TRANSPOTTER
// ################################# VARIANT_TRANSPOTTER SETTINGS ############################
#ifdef VARIANT_TRANSPOTTER
#define CONTROL_GAMETRAK
#define SUPPORT_LCD
#define SUPPORT_NUNCHUCK
@ -288,19 +300,27 @@
#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
#endif
// ################################# VARIANT_NUNCHUCK SETTINGS ############################
#ifdef VARIANT_NUNCHUCK
// # ARMCHAIR #
#define FILTER 3276 // 0.05f
#define SPEED_COEFFICIENT 8192 // 0.5f
#define STEER_COEFFICIENT 62259 // -0.2f
#endif
// ################################# SIMPLE BOBBYCAR #################################
// for better bobbycar code see: https://github.com/larsmm/hoverboard-firmware-hack-bbcar
// #define FILTER 6553 // 0.1f
// #define SPEED_COEFFICIENT 49152 // -1.0f
// #define STEER_COEFFICIENT 0 // 0.0f
// ################################# ARMCHAIR #################################
// #define FILTER 3276 // 0.05f
// #define SPEED_COEFFICIENT 8192 // 0.5f
// #define STEER_COEFFICIENT 62259 // -0.2f
// ############################### VALIDATE SETTINGS ###############################
#if !defined(VARIANT_ADC) && !defined(VARIANT_USART3) && !defined(VARIANT_HOVERCAR) && !defined(VARIANT_TRANSPOTTER) && !defined(VARIANT_NUNCHUCK) && !defined(VARIANT_PPM)
#error Variant not defined! Please check platformio.ini or inc/config.h for available variants.
#endif
#if defined(CONTROL_SERIAL_USART2) && defined(CONTROL_SERIAL_USART3)
#error CONTROL_SERIAL_USART2 and CONTROL_SERIAL_USART3 not allowed, choose one.
#endif
@ -350,3 +370,7 @@
#warning ADC2 Protection NOT possible! Adjust the ADC thresholds.
#undef ADC_PROTECT_ENA
#endif
#if defined(CONTROL_PPM) && !defined(PPM_NUM_CHANNELS)
#error Total number of PPM channels needs to be set
#endif

View File

@ -55,7 +55,8 @@ startup_stm32f103xe.s
#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
#PREFIX = arm-none-eabi-
PREFIX = gcc-arm-none-eabi-7/bin/arm-none-eabi-
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy

View File

@ -146,6 +146,8 @@ Nunchuck not working: Use the right one of the 2 types of nunchucks. Use i2c pul
Nunchuck or PPM working bad: The i2c bus and PPM signal are very sensitive to emv distortions of the motor controller. They get stronger the faster you are. Keep cables short, use shielded cable, use ferrits, stabilize voltage in nunchuck or reviever, add i2c pullups. To many errors leads to very high accelerations which triggers the protection board within the battery to shut everything down.
Recommendation: Nunchuck Breakout Board https://github.com/Jan--Henrik/hoverboard-breakout
Most robust way for input is to use the ADC and potis. It works well even on 1m unshielded cable. Solder ~100k Ohm resistors between ADC-inputs and gnd directly on the mainboard. Use potis as pullups to 3.3V.
---

View File

@ -31,7 +31,7 @@
#include "hd44780.h"
#endif
#ifdef TRANSPOTTER
#ifdef VARIANT_TRANSPOTTER
#include "eeprom.h"
#endif
@ -71,7 +71,7 @@ extern volatile adc_buf_t adc_buffer;
LCD_PCF8574_HandleTypeDef lcd;
#endif
extern I2C_HandleTypeDef hi2c2;
#ifndef TRANSPOTTER
#ifndef VARIANT_TRANSPOTTER
extern UART_HandleTypeDef huart2;
extern UART_HandleTypeDef huart3;
static UART_HandleTypeDef huart;
@ -81,7 +81,7 @@ extern I2C_HandleTypeDef hi2c2;
extern uint8_t LCDerrorFlag;
#endif
#ifdef TRANSPOTTER
#ifdef VARIANT_TRANSPOTTER
uint8_t nunchuck_connected = 0;
float steering;
int feedforward;
@ -142,14 +142,14 @@ uint8_t ctrlModReq = CTRL_MOD_REQ; // Final control mode request
static int cmd1; // normalized input value. -1000 to 1000
static int cmd2; // normalized input value. -1000 to 1000
static int16_t speed; // local variable for speed. -1000 to 1000
#ifndef TRANSPOTTER
#ifndef VARIANT_TRANSPOTTER
static int16_t steer; // local variable for steering. -1000 to 1000
static int16_t steerRateFixdt; // local fixed-point variable for steering rate limiter
static int16_t speedRateFixdt; // local fixed-point variable for speed rate limiter
static int32_t steerFixdt; // local fixed-point variable for steering low-pass filter
static int32_t speedFixdt; // local fixed-point variable for speed low-pass filter
#endif
#ifdef HOVERCAR
#ifdef VARIANT_HOVERCAR
static MultipleTap MultipleTapBreak; // define multiple tap functionality for the Break pedal
#endif
static int16_t speedAvg; // average measured speed
@ -267,7 +267,7 @@ int main(void) {
HAL_GPIO_WritePin(LED_PORT, LED_PIN, 1);
#ifdef TRANSPOTTER
#ifdef VARIANT_TRANSPOTTER
int lastDistance = 0;
enable = 1;
uint8_t checkRemote = 0;
@ -324,7 +324,7 @@ int main(void) {
LCD_ClearDisplay(&lcd);
HAL_Delay(5);
LCD_SetLocation(&lcd, 0, 0);
#ifdef TRANSPOTTER
#ifdef VARIANT_TRANSPOTTER
LCD_WriteString(&lcd, "TranspOtter V2.1");
#else
LCD_WriteString(&lcd, "Hover V2.0");
@ -333,7 +333,7 @@ int main(void) {
LCD_WriteString(&lcd, "Initializing...");
#endif
#if defined(TRANSPOTTER) && defined(SUPPORT_LCD)
#if defined(VARIANT_TRANSPOTTER) && defined(SUPPORT_LCD)
LCD_ClearDisplay(&lcd);
HAL_Delay(5);
LCD_SetLocation(&lcd, 0, 1);
@ -363,7 +363,7 @@ int main(void) {
while(1) {
HAL_Delay(DELAY_IN_MAIN_LOOP); //delay in ms
#ifdef TRANSPOTTER
#ifdef VARIANT_TRANSPOTTER
if(HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) {
enable = 0;
while(HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) {
@ -559,7 +559,7 @@ int main(void) {
}
speedAvgAbs = abs(speedAvg);
#ifndef TRANSPOTTER
#ifndef VARIANT_TRANSPOTTER
// ####### MOTOR ENABLING: Only if the initial input is very small (for SAFETY) #######
if (enable == 0 && (!errCode_Left && !errCode_Right) && (cmd1 > -50 && cmd1 < 50) && (cmd2 > -50 && cmd2 < 50)){
shortBeep(6); // make 2 beeps indicating the motor enable
@ -567,8 +567,8 @@ int main(void) {
enable = 1; // enable motors
}
// ####### HOVERCAR #######
#ifdef HOVERCAR
// ####### VARIANT_HOVERCAR #######
#ifdef VARIANT_HOVERCAR
// Calculate speed Blend, a number between [0, 1] in fixdt(0,16,15)
uint16_t speedBlend;
speedBlend = (uint16_t)(((CLAMP(speedAvgAbs,30,90) - 30) << 15) / 60); // speedBlend [0,1] is within [30 rpm, 90rpm]
@ -599,8 +599,8 @@ int main(void) {
steer = (int16_t)(steerFixdt >> 20); // convert fixed-point to integer
speed = (int16_t)(speedFixdt >> 20); // convert fixed-point to integer
// ####### HOVERCAR #######
#ifdef HOVERCAR
// ####### VARIANT_HOVERCAR #######
#ifdef VARIANT_HOVERCAR
if (!MultipleTapBreak.b_multipleTap) { // Check driving direction
speed = steer + speed; // Forward driving
} else {
@ -636,7 +636,7 @@ int main(void) {
lastSpeedL = speedL;
lastSpeedR = speedR;
#ifdef TRANSPOTTER
#ifdef VARIANT_TRANSPOTTER
if (timeout > TIMEOUT) {
pwml = 0;
pwmr = 0;
@ -809,7 +809,7 @@ int main(void) {
}
}
#ifdef TRANSPOTTER
#ifdef VARIANT_TRANSPOTTER
void saveConfig() {
HAL_FLASH_Unlock();
EE_WriteVariable(VirtAddVarTab[0], saveValue);

View File

@ -6,10 +6,13 @@ include_dir = Inc
src_dir = Src
;=================== VARIANT SELECTION ==========================
default_envs = VARIANT_ADC ; Variant for control via ADC input
default_envs = UNDEFINED ;
;default_envs = VARIANT_ADC ; Variant for control via ADC input
;default_envs = VARIANT_USART3 ; Variant for Serial control via USART3 input
;default_envs = HOVERCAR ; Variant for HOVERCAR build
;default_envs = 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_HOVERCAR ; Variant for HOVERCAR build
;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_NUNCHUCK ; Variant for Nunchuck controlled vehicle build
;default_envs = VARIANT_PPM ; Variant for RC-Remotes with PPM-Sum signal
;================================================================
[env:VARIANT_ADC]
@ -33,6 +36,7 @@ build_flags =
-g -ggdb ; to generate correctly the 'firmware.elf' for STM STUDIO vizualization
# -Wl,-lnosys
-D VARIANT_ADC
-D PALTFORMIO
[env:VARIANT_USART3]
platform = ststm32
@ -55,8 +59,9 @@ build_flags =
-g -ggdb ; to generate correctly the 'firmware.elf' for STM STUDIO vizualization
# -Wl,-lnosys
-D VARIANT_USART3
-D PALTFORMIO
[env:HOVERCAR]
[env:VARIANT_HOVERCAR]
platform = ststm32
framework = stm32cube
board = genericSTM32F103RC
@ -76,9 +81,10 @@ build_flags =
-Wl,-lm
-g -ggdb ; to generate correctly the 'firmware.elf' for STM STUDIO vizualization
# -Wl,-lnosys
-D HOVERCAR
-D VARIANT_HOVERCAR
-D PALTFORMIO
[env:TRANSPOTTER]
[env:VARIANT_TRANSPOTTER]
platform = ststm32
framework = stm32cube
board = genericSTM32F103RC
@ -94,4 +100,43 @@ build_flags =
-Wl,-lm
-g -ggdb ; to generate correctly the 'firmware.elf' for STM STUDIO vizualization
# -Wl,-lnosys
-D TRANSPOTTER
-D VARIANT_TRANSPOTTER
-D PALTFORMIO
[env:VARIANT_NUNCHUCK]
platform = ststm32
framework = stm32cube
board = genericSTM32F103RC
debug_tool = stlink
upload_protocol = stlink
build_flags =
-I${PROJECT_DIR}/inc/
-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_NUNCHUCK
-D PALTFORMIO
[env:VARIANT_PPM]
platform = ststm32
framework = stm32cube
board = genericSTM32F103RC
debug_tool = stlink
upload_protocol = stlink
build_flags =
-I${PROJECT_DIR}/inc/
-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_PPM
-D PALTFORMIO