apply fix for low voltage poweroff and uart checksum

This commit is contained in:
interfisch 2020-02-02 23:59:15 +01:00
parent 567b0d40d3
commit 0d7f80ec3b
2 changed files with 34 additions and 57 deletions

View File

@ -43,8 +43,8 @@ uint8_t modeled_green=0;
uint8_t modeled_red=0; uint8_t modeled_red=0;
long last_ledupdate=0; long last_ledupdate=0;
#define PIN_RELAISFRONT PB14 //connected to relais which presses the powerbutton of the hoverboard for the front wheels #define PIN_RELAISFRONT PB15 //connected to relais which presses the powerbutton of the hoverboard for the front wheels
#define PIN_RELAISREAR PB15 //connected to relais which presses the powerbutton of the hoverboard for the rear wheels #define PIN_RELAISREAR PB14 //connected to relais which presses the powerbutton of the hoverboard for the rear wheels
#define DEBOUNCETIME 20 //time to not check for inputs after key press #define DEBOUNCETIME 20 //time to not check for inputs after key press
#define BUTTONTIMEHOLD 750 //time for button hold #define BUTTONTIMEHOLD 750 //time for button hold
@ -79,10 +79,10 @@ float adc_throttle=0; //filtered value
int adc_brake_raw=0; //raw throttle value from adc int adc_brake_raw=0; //raw throttle value from adc
float adc_brake=0; //filtered value float adc_brake=0; //filtered value
uint16_t out_speedFL=0; int16_t out_speedFL=0;
uint16_t out_speedFR=0; int16_t out_speedFR=0;
uint16_t out_speedRL=0; int16_t out_speedRL=0;
uint16_t out_speedRR=0; int16_t out_speedRR=0;
long last_send = 0; long last_send = 0;
@ -101,8 +101,7 @@ byte incomingBytePrev1;
long lastValidDataSerial1_time; long lastValidDataSerial1_time;
long board1lastPoweron=0; //mainly for failcheck long board1lastPoweron=0; //mainly for failcheck
long board1lastPoweroff=0; long board1lastPoweroff=0;
long board1lastFeedbackMinSpeed;
boolean board1lastFeedbackMinSpeed_above=false;
//Same for Serial2 (Front) //Same for Serial2 (Front)
uint8_t idx2 = 0; // Index for new data pointer uint8_t idx2 = 0; // Index for new data pointer
@ -113,8 +112,6 @@ byte incomingBytePrev2;
long lastValidDataSerial2_time; long lastValidDataSerial2_time;
long board2lastPoweron=0; //mainly for failcheck long board2lastPoweron=0; //mainly for failcheck
long board2lastPoweroff=0; long board2lastPoweroff=0;
long board2lastFeedbackMinSpeed;
boolean board2lastFeedbackMinSpeed_above=false;
typedef struct{ typedef struct{
uint16_t start; uint16_t start;
@ -137,7 +134,7 @@ typedef struct{
int16_t boardTemp; int16_t boardTemp;
int16_t curL_DC; int16_t curL_DC;
int16_t curR_DC; int16_t curR_DC;
int16_t checksum; uint16_t checksum;
} SerialFeedback; } SerialFeedback;
SerialFeedback Feedback1; SerialFeedback Feedback1;
SerialFeedback NewFeedback1; SerialFeedback NewFeedback1;
@ -352,6 +349,15 @@ void handleModeChange() {
//TODO: led show aborted modechange //TODO: led show aborted modechange
}else{ //everythings fine, turn on/off }else{ //everythings fine, turn on/off
digitalWrite(PIN_RELAISFRONT,HIGH); //simulate hoverboard power button press digitalWrite(PIN_RELAISFRONT,HIGH); //simulate hoverboard power button press
//Front board is Serial2
if (requestmode==on) {
board2Enabled=true; //assume board is online
board2lastPoweron=loopmillis; //save time at which board was powered on
// ### Request Idle or Off ###
}else if(requestmode==idle || requestmode==off) {
board2Enabled=false; //assume board is offline
board2lastPoweroff=loopmillis; //save time at which board was powered off
}
state_modechange++; state_modechange++;
state_modechange_time=loopmillis; //set to current time state_modechange_time=loopmillis; //set to current time
Serial.println("PIN_RELAISFRONT,HIGH"); Serial.println("PIN_RELAISFRONT,HIGH");
@ -368,6 +374,15 @@ void handleModeChange() {
case 2: case 2:
if (loopmillis - state_modechange_time > 200) { //wait some time if (loopmillis - state_modechange_time > 200) { //wait some time
digitalWrite(PIN_RELAISREAR,HIGH); //simulate hoverboard power button press digitalWrite(PIN_RELAISREAR,HIGH); //simulate hoverboard power button press
//Rear board is Serial1
if (requestmode==on) {
board1Enabled=true; //assume board is online
board1lastPoweron=loopmillis; //save time at which board was powered on
// ### Request Idle or Off ###
}else if(requestmode==idle || requestmode==off) {
board1Enabled=false; //assume board is offline
board1lastPoweroff=loopmillis; //save time at which board was powered off
}
state_modechange++; state_modechange++;
state_modechange_time=loopmillis; //set to current time state_modechange_time=loopmillis; //set to current time
Serial.println("PIN_RELAISREAR,HIGH"); Serial.println("PIN_RELAISREAR,HIGH");
@ -388,27 +403,6 @@ void handleModeChange() {
Serial.println("Waiting finished"); Serial.println("Waiting finished");
} }
break; break;
case 5:
// ### Request On ###
if (requestmode==on) {//wait for both boards to send feedback
state_modechange++;
board1Enabled=true; //assume board is online
board1lastPoweron=loopmillis; //save time at which board was powered on
board2Enabled=true; //assume board is online
board2lastPoweron=loopmillis; //save time at which board was powered on
// ### Request Idle or Off (both power boards off) ###
}else if(requestmode==idle || requestmode==off) {
state_modechange++;
board1Enabled=false; //assume board is offline
board1lastPoweroff=loopmillis; //save time at which board was powered off
board2Enabled=false; //assume board is offline
board2lastPoweroff=loopmillis; //save time at which board was powered off
Serial.println("finished");
}else{ //if changed off from error mode
state_modechange++;
}
break;
default: //finished modechange default: //finished modechange
currentmode=requestmode; currentmode=requestmode;
state_modechange=0; state_modechange=0;
@ -520,8 +514,8 @@ boolean boardsPowered()
void failChecks() void failChecks()
{ {
#define FAILCHECK_WAITCHECK_AFTER_POWEROFF_TIME 3000 //time to start failchecking boardpower after board poweroff #define FAILCHECK_WAITCHECK_AFTER_POWEROFF_TIME 1000 //time to start failchecking boardpower after board poweroff
#define FAILCHECK_RECEIVERECENT_TIME 1000 //timeout .should be less than FAILCHECK_WAITCHECK_AFTER_POWEROFF_TIME #define FAILCHECK_RECEIVERECENT_TIME 100 //timeout .should be less than FAILCHECK_WAITCHECK_AFTER_POWEROFF_TIME and greater than send delay from mainboard
// ## Check if board is really offline ## // ## Check if board is really offline ##
if (!board1Enabled) { //board should be offline if (!board1Enabled) { //board should be offline
if (loopmillis-board1lastPoweroff > FAILCHECK_WAITCHECK_AFTER_POWEROFF_TIME){ //wait some time before checking if board did power off if (loopmillis-board1lastPoweroff > FAILCHECK_WAITCHECK_AFTER_POWEROFF_TIME){ //wait some time before checking if board did power off
@ -542,29 +536,12 @@ void failChecks()
} }
} }
#define MINSPEED_FOR_FEEDBACK 250 //speed at which feedback output should be expected
#define RESETSPEED_FOR_FEEDBACK 50 //should be less than MINSPEED_FOR_FEEDBACK. speed at which board2lastFeedbackMinSpeed will be able to be reset
if (!board2lastFeedbackMinSpeed_above && ( abs(out_speedFL) > MINSPEED_FOR_FEEDBACK || abs(out_speedFR) > MINSPEED_FOR_FEEDBACK ) ){
board2lastFeedbackMinSpeed=loopmillis; //front is board 2
board2lastFeedbackMinSpeed_above=true;
}
if (board2lastFeedbackMinSpeed_above && abs(out_speedFL) < RESETSPEED_FOR_FEEDBACK && abs(out_speedFR) < RESETSPEED_FOR_FEEDBACK) { //if speed of both wheels goes below a threshold, board2lastFeedbackMinSpeed will be able to reset
board2lastFeedbackMinSpeed_above=false;
}
if (!board1lastFeedbackMinSpeed_above && ( abs(out_speedRL) > MINSPEED_FOR_FEEDBACK || abs(out_speedRR) > MINSPEED_FOR_FEEDBACK ) ){ #define FAILCHECK_WAITCHECK_AFTER_POWERON_TIME 2000 //time to start failchecking boardpower after startup
board1lastFeedbackMinSpeed=loopmillis; //rear is board 1
board1lastFeedbackMinSpeed_above=true;
}
if (board1lastFeedbackMinSpeed_above && abs(out_speedRL) < RESETSPEED_FOR_FEEDBACK && abs(out_speedRR) < RESETSPEED_FOR_FEEDBACK) { //if speed of both wheels goes below a threshold, board2lastFeedbackMinSpeed will be able to reset
board1lastFeedbackMinSpeed_above=false;
}
#define FAILCHECK_WAITCHECK_AFTER_MINSPEED_TIME 3000 //time to start failchecking boardpower after minimum throttle that should give some feedback
// ## Check if board is online (when it should send feedback) ## // ## Check if board is online (when it should send feedback) ##
if (board1Enabled) { //board should be online if (board1Enabled) { //board should be online
if (loopmillis-board1lastFeedbackMinSpeed > FAILCHECK_WAITCHECK_AFTER_MINSPEED_TIME) { //wait some time before checking if (loopmillis-board1lastPoweron > FAILCHECK_WAITCHECK_AFTER_POWERON_TIME) { //wait some time before checking
if (board1lastFeedbackMinSpeed_above && loopmillis-lastValidDataSerial1_time > FAILCHECK_RECEIVERECENT_TIME) { //speed still high enough but no new messages recently received? if (loopmillis-lastValidDataSerial1_time > FAILCHECK_RECEIVERECENT_TIME) { //speed still high enough but no new messages recently received?
errormessage="Board 1 should be online and give feedback but didnt"; errormessage="Board 1 should be online and give feedback but didnt";
Serial.println(errormessage); Serial.println(errormessage);
requestmode=error; requestmode=error;
@ -572,8 +549,8 @@ void failChecks()
} }
} }
if (board2Enabled) { //board should be online if (board2Enabled) { //board should be online
if (loopmillis-board2lastFeedbackMinSpeed > FAILCHECK_WAITCHECK_AFTER_MINSPEED_TIME) { //wait some time before checking if (loopmillis-board2lastPoweron > FAILCHECK_WAITCHECK_AFTER_POWERON_TIME) { //wait some time before checking
if (board2lastFeedbackMinSpeed_above && loopmillis-lastValidDataSerial2_time > FAILCHECK_RECEIVERECENT_TIME) { //speed still high enough but no new messages recently received? if (loopmillis-lastValidDataSerial2_time > FAILCHECK_RECEIVERECENT_TIME) { //no new messages recently received?
errormessage="Board 2 should be online and give feedback but didnt"; errormessage="Board 2 should be online and give feedback but didnt";
Serial.println(errormessage); Serial.println(errormessage);
requestmode=error; requestmode=error;

@ -1 +1 @@
Subproject commit fc5f5a26ca648aa30aec3fc4904a3a7560c11baa Subproject commit b9bf849330f8e7355d0881300ebdc59607845e2d