copy own changes from old version

This commit is contained in:
interfisch 2019-06-12 11:39:10 +02:00
parent 3e2cfe973a
commit 1e9a03bc50
5 changed files with 37 additions and 1165 deletions

View File

@ -8,14 +8,15 @@
#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. #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.
#define TIMEOUT 5 // number of wrong / missing input commands before emergency off #define TIMEOUT 20 // number of wrong / missing input commands before emergency off. default: 5
//for uart control: new serial control data needs to be send within every TIMEOUT*DELAY_IN_MAIN_LOOP milliseconds, otherwise motors will be disabled
// ############################### GENERAL ############################### // ############################### GENERAL ###############################
// How to calibrate: connect GND and RX of a 3.3v uart-usb adapter to the right sensor board cable (be careful not to use the red wire of the cable. 15v will destroy everything.). if you are using nunchuck, disable it temporarily. enable DEBUG_SERIAL_USART3 and DEBUG_SERIAL_ASCII use asearial terminal. // How to calibrate: connect GND and RX of a 3.3v uart-usb adapter to the right sensor board cable (be careful not to use the red wire of the cable. 15v will destroy everything.). if you are using nunchuck, disable it temporarily. enable DEBUG_SERIAL_USART3 and DEBUG_SERIAL_ASCII use asearial terminal.
// Battery voltage calibration: connect power source. see <How to calibrate>. write value nr 5 to BAT_CALIB_ADC. make and flash firmware. then you can verify voltage on value 6 (devide it by 100.0 to get calibrated voltage). // Battery voltage calibration: connect power source. see <How to calibrate>. write value nr 5 to BAT_CALIB_ADC. make and flash firmware. then you can verify voltage on value 6 (devide it by 100.0 to get calibrated voltage).
#define BAT_CALIB_REAL_VOLTAGE 43.0 // input voltage measured by multimeter #define BAT_CALIB_REAL_VOLTAGE 43.0 // input voltage measured by multimeter
#define BAT_CALIB_ADC 1704 // adc-value measured by mainboard (value nr 5 on UART debug output) #define BAT_CALIB_ADC 1704 // adc-value measured by mainboard (value nr 5 on UART debug output)
#define BAT_NUMBER_OF_CELLS 10 // normal Hoverboard battery: 10s #define BAT_NUMBER_OF_CELLS 10 // normal Hoverboard battery: 10s
@ -53,7 +54,7 @@
// ############################### INPUT ############################### // ############################### INPUT ###############################
// ###### CONTROL VIA UART (serial) ###### // ###### CONTROL VIA UART (serial) ######
//#define CONTROL_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used! #define CONTROL_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used!
#define CONTROL_BAUD 19200 // control via usart from eg an Arduino or raspberry #define CONTROL_BAUD 19200 // control via usart from eg an Arduino or raspberry
// for Arduino, use void loop(void){ Serial.write((uint8_t *) &steer, sizeof(steer)); Serial.write((uint8_t *) &speed, sizeof(speed));delay(20); } // for Arduino, use void loop(void){ Serial.write((uint8_t *) &steer, sizeof(steer)); Serial.write((uint8_t *) &speed, sizeof(speed));delay(20); }
@ -76,7 +77,7 @@
// ###### MOTOR TEST MODE ###### // ###### MOTOR TEST MODE ######
// slowly move both wheels forward and backward, ignoring all inputs // slowly move both wheels forward and backward, ignoring all inputs
#define CONTROL_MOTOR_TEST //#define CONTROL_MOTOR_TEST
#define CONTROL_MOTOR_TEST_MAX_SPEED 300 // sweep slowly from -MAX_SPEED to MAX_SPEED (0 - 1000) #define CONTROL_MOTOR_TEST_MAX_SPEED 300 // sweep slowly from -MAX_SPEED to MAX_SPEED (0 - 1000)
// ############################### DRIVING BEHAVIOR ############################### // ############################### DRIVING BEHAVIOR ###############################
@ -89,12 +90,12 @@
// - speedR and speedL: normal driving -1000 to 1000 // - speedR and speedL: normal driving -1000 to 1000
// - weakr and weakl: field weakening for extra boost at high speed (speedR > 700 and speedL > 700). 0 to ~400 // - weakr and weakl: field weakening for extra boost at high speed (speedR > 700 and speedL > 700). 0 to ~400
#define FILTER 0.1 // lower value == softer filter. do not use values <0.01, you will get float precision issues. #define FILTER 0.05 // lower value == softer filter. do not use values <0.01, you will get float precision issues.
#define SPEED_COEFFICIENT 0.5 // higher value == stronger. 0.0 to ~2.0? #define SPEED_COEFFICIENT 1 // higher value == stronger. 0.0 to ~2.0?
#define STEER_COEFFICIENT 0.5 // higher value == stronger. if you do not want any steering, set it to 0.0; 0.0 to 1.0 #define STEER_COEFFICIENT 0.5 // higher value == stronger. if you do not want any steering, set it to 0.0; 0.0 to 1.0
#define INVERT_R_DIRECTION //#define INVERT_R_DIRECTION
#define INVERT_L_DIRECTION //#define INVERT_L_DIRECTION
#define BEEPS_BACKWARD 1 // 0 or 1 #define BEEPS_BACKWARD 0 // 0 or 1
//Turbo boost at high speeds while button1 is pressed: //Turbo boost at high speeds while button1 is pressed:
//#define ADDITIONAL_CODE \ //#define ADDITIONAL_CODE \

View File

@ -50,7 +50,7 @@ startup_stm32f103xe.s
####################################### #######################################
# binaries # binaries
####################################### #######################################
PREFIX = arm-none-eabi- PREFIX = ~/gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-
CC = $(PREFIX)gcc CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy CP = $(PREFIX)objcopy

View File

@ -8,7 +8,8 @@
TIM_HandleTypeDef TimHandle; TIM_HandleTypeDef TimHandle;
uint8_t ppm_count = 0; uint8_t ppm_count = 0;
uint32_t timeout = 100; //uint32_t timeout = 100;
uint32_t timeout = 0; //start with 0, because if once timeout>TIMEOUT board will stay disabled
uint8_t nunchuck_data[6] = {0}; uint8_t nunchuck_data[6] = {0};
uint8_t i2cBuffer[2]; uint8_t i2cBuffer[2];

View File

@ -44,6 +44,7 @@ typedef struct{
int16_t steer; int16_t steer;
int16_t speed; int16_t speed;
//uint32_t crc; //uint32_t crc;
uint8_t checksum; //simple checksum for error handling and connection break check. 0 disables motors
} Serialcommand; } Serialcommand;
volatile Serialcommand command; volatile Serialcommand command;
@ -157,7 +158,7 @@ int main(void) {
#ifdef CONTROL_SERIAL_USART2 #ifdef CONTROL_SERIAL_USART2
UART_Control_Init(); UART_Control_Init();
HAL_UART_Receive_DMA(&huart2, (uint8_t *)&command, 4); HAL_UART_Receive_DMA(&huart2, (uint8_t *)&command, 5); //size 5= 2x16bit + 1x8bit (checksum)
#endif #endif
#ifdef DEBUG_I2C_LCD #ifdef DEBUG_I2C_LCD
@ -219,10 +220,23 @@ int main(void) {
#endif #endif
#ifdef CONTROL_SERIAL_USART2 #ifdef CONTROL_SERIAL_USART2
cmd1 = CLAMP((int16_t)command.steer, -1000, 1000); uint8_t calcchecksum = ((uint8_t) ((uint8_t)command.steer)*((uint8_t)command.speed)); //simple checksum
cmd2 = CLAMP((int16_t)command.speed, -1000, 1000); if (calcchecksum==0 || calcchecksum==255){ calcchecksum=1; } //cannot be 0 or 255 (special purpose)
timeout = 0; if (command.checksum==0 || command.checksum==calcchecksum){ //motor off or correct checksum
if (timeout<TIMEOUT){ //reset only if no error detected
timeout = 0; //values ok, reset timeout
}
cmd1 = CLAMP((int16_t)command.steer, -1000, 1000);
cmd2 = CLAMP((int16_t)command.speed, -1000, 1000);
if (command.checksum==0){ //received checksum 0 disables motors
enable=0;
}else{ //checksum ok and not intended to disable motors
enable=1;
}
}
command.checksum=255; //set 255 as flag "values read"
#endif #endif
#ifdef CONTROL_MOTOR_TEST #ifdef CONTROL_MOTOR_TEST
@ -270,7 +284,7 @@ int main(void) {
// ####### CALC BOARD TEMPERATURE ####### // ####### CALC BOARD TEMPERATURE #######
board_temp_adc_filtered = board_temp_adc_filtered * 0.99 + (float)adc_buffer.temp * 0.01; board_temp_adc_filtered = board_temp_adc_filtered * 0.99 + (float)adc_buffer.temp * 0.01;
board_temp_deg_c = ((float)TEMP_CAL_HIGH_DEG_C - (float)TEMP_CAL_LOW_DEG_C) / ((float)TEMP_CAL_HIGH_ADC - (float)TEMP_CAL_LOW_ADC) * (board_temp_adc_filtered - (float)TEMP_CAL_LOW_ADC) + (float)TEMP_CAL_LOW_DEG_C; board_temp_deg_c = ((float)TEMP_CAL_HIGH_DEG_C - (float)TEMP_CAL_LOW_DEG_C) / ((float)TEMP_CAL_HIGH_ADC - (float)TEMP_CAL_LOW_ADC) * (board_temp_adc_filtered - (float)TEMP_CAL_LOW_ADC) + (float)TEMP_CAL_LOW_DEG_C;
// ####### DEBUG SERIAL OUT ####### // ####### DEBUG SERIAL OUT #######
#ifdef CONTROL_ADC #ifdef CONTROL_ADC
setScopeChannel(0, (int)adc_buffer.l_tx2); // 1: ADC1 setScopeChannel(0, (int)adc_buffer.l_tx2); // 1: ADC1
@ -324,9 +338,12 @@ int main(void) {
if (inactivity_timeout_counter > (INACTIVITY_TIMEOUT * 60 * 1000) / (DELAY_IN_MAIN_LOOP + 1)) { // rest of main loop needs maybe 1ms if (inactivity_timeout_counter > (INACTIVITY_TIMEOUT * 60 * 1000) / (DELAY_IN_MAIN_LOOP + 1)) { // rest of main loop needs maybe 1ms
poweroff(); poweroff();
} }
main_loop_counter += 1; main_loop_counter += 1;
timeout++;
if (timeout<=TIMEOUT+10){ //do not increase if value is high enough (prevent overflow)
timeout++; //timeout>TIMEOUT disables motors
}
} }
} }

File diff suppressed because it is too large Load Diff