copy own changes from old version
This commit is contained in:
parent
3e2cfe973a
commit
1e9a03bc50
17
Inc/config.h
17
Inc/config.h
|
@ -8,7 +8,8 @@
|
|||
|
||||
#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 ###############################
|
||||
|
||||
|
@ -53,7 +54,7 @@
|
|||
// ############################### INPUT ###############################
|
||||
|
||||
// ###### 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
|
||||
// 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 ######
|
||||
// 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)
|
||||
|
||||
// ############################### DRIVING BEHAVIOR ###############################
|
||||
|
@ -89,12 +90,12 @@
|
|||
// - 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
|
||||
|
||||
#define FILTER 0.1 // 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 FILTER 0.05 // lower value == softer filter. do not use values <0.01, you will get float precision issues.
|
||||
#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 INVERT_R_DIRECTION
|
||||
#define INVERT_L_DIRECTION
|
||||
#define BEEPS_BACKWARD 1 // 0 or 1
|
||||
//#define INVERT_R_DIRECTION
|
||||
//#define INVERT_L_DIRECTION
|
||||
#define BEEPS_BACKWARD 0 // 0 or 1
|
||||
|
||||
//Turbo boost at high speeds while button1 is pressed:
|
||||
//#define ADDITIONAL_CODE \
|
||||
|
|
2
Makefile
2
Makefile
|
@ -50,7 +50,7 @@ startup_stm32f103xe.s
|
|||
#######################################
|
||||
# binaries
|
||||
#######################################
|
||||
PREFIX = arm-none-eabi-
|
||||
PREFIX = ~/gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-
|
||||
CC = $(PREFIX)gcc
|
||||
AS = $(PREFIX)gcc -x assembler-with-cpp
|
||||
CP = $(PREFIX)objcopy
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
|
||||
TIM_HandleTypeDef TimHandle;
|
||||
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 i2cBuffer[2];
|
||||
|
|
25
Src/main.c
25
Src/main.c
|
@ -44,6 +44,7 @@ typedef struct{
|
|||
int16_t steer;
|
||||
int16_t speed;
|
||||
//uint32_t crc;
|
||||
uint8_t checksum; //simple checksum for error handling and connection break check. 0 disables motors
|
||||
} Serialcommand;
|
||||
|
||||
volatile Serialcommand command;
|
||||
|
@ -157,7 +158,7 @@ int main(void) {
|
|||
|
||||
#ifdef CONTROL_SERIAL_USART2
|
||||
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
|
||||
|
||||
#ifdef DEBUG_I2C_LCD
|
||||
|
@ -219,10 +220,23 @@ int main(void) {
|
|||
#endif
|
||||
|
||||
#ifdef CONTROL_SERIAL_USART2
|
||||
uint8_t calcchecksum = ((uint8_t) ((uint8_t)command.steer)*((uint8_t)command.speed)); //simple checksum
|
||||
if (calcchecksum==0 || calcchecksum==255){ calcchecksum=1; } //cannot be 0 or 255 (special purpose)
|
||||
|
||||
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);
|
||||
|
||||
timeout = 0;
|
||||
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
|
||||
|
||||
#ifdef CONTROL_MOTOR_TEST
|
||||
|
@ -326,7 +340,10 @@ int main(void) {
|
|||
}
|
||||
|
||||
main_loop_counter += 1;
|
||||
timeout++;
|
||||
|
||||
if (timeout<=TIMEOUT+10){ //do not increase if value is high enough (prevent overflow)
|
||||
timeout++; //timeout>TIMEOUT disables motors
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
1147
build/hover.hex
1147
build/hover.hex
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue