implement maybe working board online offline failchecks

This commit is contained in:
interfisch 2019-12-13 23:24:11 +01:00
parent a3d018b7fb
commit e136bcd074
2 changed files with 76 additions and 3 deletions

View File

@ -79,20 +79,29 @@ boolean board2Enabled=false;
// Global variables for serial communication
//Serial1 (Rear)
uint8_t idx1 = 0; // Index for new data pointer
uint16_t bufStartFrame1; // Buffer Start Frame
byte *p1; // Pointer declaration for the new received data
byte incomingByte1;
byte incomingBytePrev1;
long lastValidDataSerial1_time;
long board1lastPoweron=0; //mainly for failcheck
long board1lastPoweroff=0;
long board1lastFeedbackMinSpeed;
boolean board1lastFeedbackMinSpeed_above=false;
//Same for Serial2
//Same for Serial2 (Front)
uint8_t idx2 = 0; // Index for new data pointer
uint16_t bufStartFrame2; // Buffer Start Frame
byte *p2; // Pointer declaration for the new received data
byte incomingByte2;
byte incomingBytePrev2;
long lastValidDataSerial2_time;
long board2lastPoweron=0; //mainly for failcheck
long board2lastPoweroff=0;
long board2lastFeedbackMinSpeed;
boolean board2lastFeedbackMinSpeed_above=false;
typedef struct{
uint16_t start;
@ -365,12 +374,17 @@ void handleModeChange() {
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++;
@ -460,7 +474,66 @@ boolean boardsPowered()
void failChecks()
{
#define FAILCHECK_WAITCHECK_AFTER_POWEROFF_TIME 3000 //time to start failchecking boardpower after board poweroff
#define FAILCHECK_RECEIVERECENT_TIME 1000 //should be less than FAILCHECK_WAITCHECK_AFTER_POWEROFF_TIME
// ## Check if board is really 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-lastValidDataSerial1_time < FAILCHECK_RECEIVERECENT_TIME) { //new message received recently?
errormessage="Board 1 should be offline but feedback received";
Serial.println(errormessage);
requestmode=error;
}
}
}
if (!board2Enabled) { //board should be offline
if (loopmillis-board2lastPoweroff > FAILCHECK_WAITCHECK_AFTER_POWEROFF_TIME){ //wait some time before checking if board did power off
if (loopmillis-lastValidDataSerial2_time < FAILCHECK_RECEIVERECENT_TIME) { //new message received recently?
errormessage="Board 2 should be offline but feedback received";
Serial.println(errormessage);
requestmode=error;
}
}
}
#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 ) ){
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) ##
if (board1Enabled) { //board should be online
if (loopmillis-board1lastFeedbackMinSpeed > FAILCHECK_WAITCHECK_AFTER_MINSPEED_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?
errormessage="Board 1 should be online and give feedback but didnt";
Serial.println(errormessage);
requestmode=error;
}
}
}
if (board2Enabled) { //board should be online
if (loopmillis-board2lastFeedbackMinSpeed > FAILCHECK_WAITCHECK_AFTER_MINSPEED_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?
errormessage="Board 2 should be online and give feedback but didnt";
Serial.println(errormessage);
requestmode=error;
}
}
}
}

@ -1 +1 @@
Subproject commit 9fb4b7a8d5d9812edc8863dbfe1082a1c96bef9c
Subproject commit 7c76c9f8392b9344033f6a7c06d4ceb000b024da