|
|
|
@ -163,7 +163,9 @@ typedef enum { |
|
|
|
#if PL_CONFIG_APP_SUMO |
|
|
|
#if PL_CONFIG_APP_SUMO |
|
|
|
APP_STATE_RUN_SUMO, /* Sumo fight */ |
|
|
|
APP_STATE_RUN_SUMO, /* Sumo fight */ |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
APP_STATE_IDLE |
|
|
|
APP_STATE_IDLE, |
|
|
|
|
|
|
|
APP_STATE_MANUAL_MOVE, |
|
|
|
|
|
|
|
APP_STATE_AUTO, |
|
|
|
} AppStateType; |
|
|
|
} AppStateType; |
|
|
|
|
|
|
|
|
|
|
|
static AppStateType appState = APP_STATE_STARTUP; |
|
|
|
static AppStateType appState = APP_STATE_STARTUP; |
|
|
|
@ -211,6 +213,8 @@ static unsigned char *AppStateString(AppStateType state) { |
|
|
|
static void StateMachine(bool buttonPress) { |
|
|
|
static void StateMachine(bool buttonPress) { |
|
|
|
#if PL_CONFIG_USE_LINE_SENSOR |
|
|
|
#if PL_CONFIG_USE_LINE_SENSOR |
|
|
|
static uint8_t cnt; |
|
|
|
static uint8_t cnt; |
|
|
|
|
|
|
|
static uint8_t mazeFailure; |
|
|
|
|
|
|
|
static uint8_t presentCnt; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
// TODO: send appstate via Mqtt
|
|
|
|
// TODO: send appstate via Mqtt
|
|
|
|
switch (appState) { |
|
|
|
switch (appState) { |
|
|
|
@ -357,6 +361,43 @@ static void StateMachine(bool buttonPress) { |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
case APP_STATE_MANUAL_MOVE: |
|
|
|
|
|
|
|
if(REF_GetLineKind(REF_LINE_KIND_MODE_MAZE) == REF_LINE_STRAIGHT){ |
|
|
|
|
|
|
|
// send to mqtt AUTO
|
|
|
|
|
|
|
|
SHELL_SendString((unsigned char*)"AUTO!!!\r\n"); |
|
|
|
|
|
|
|
appState = APP_STATE_AUTO; |
|
|
|
|
|
|
|
mazeFailure = 0; |
|
|
|
|
|
|
|
MAZE_ResetPresentCount(); |
|
|
|
|
|
|
|
presentCnt = MAZE_GetPresentCount(); |
|
|
|
|
|
|
|
MAZE_ClearSolution(); |
|
|
|
|
|
|
|
LF_StartFollowing(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case APP_STATE_AUTO: |
|
|
|
|
|
|
|
if(!LF_IsFollowing() && MAZE_IsSolved()){ |
|
|
|
|
|
|
|
//done
|
|
|
|
|
|
|
|
SHELL_SendString((unsigned char*)"MAZE: done, stopped!!!\r\n"); |
|
|
|
|
|
|
|
appState = APP_STATE_IDLE; |
|
|
|
|
|
|
|
}else if(!LF_IsFollowing() && !MAZE_IsSolved() && mazeFailure < 5){ |
|
|
|
|
|
|
|
// failed
|
|
|
|
|
|
|
|
mazeFailure++; |
|
|
|
|
|
|
|
SHELL_SendString((unsigned char*)"MAZE: Failure, stopped OMG!!!\r\n"); |
|
|
|
|
|
|
|
MAZE_ClearSolution(); |
|
|
|
|
|
|
|
DRV_SetSpeed(0, 0); |
|
|
|
|
|
|
|
DRV_SetMode(DRV_MODE_SPEED); |
|
|
|
|
|
|
|
LF_StartFollowing(); |
|
|
|
|
|
|
|
}else if(!LF_IsFollowing() && !MAZE_IsSolved() && mazeFailure >= 5){ |
|
|
|
|
|
|
|
appState = APP_STATE_IDLE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(MAZE_GetPresentCount() != presentCnt){ |
|
|
|
|
|
|
|
presentCnt = MAZE_GetPresentCount(); |
|
|
|
|
|
|
|
//publish
|
|
|
|
|
|
|
|
uint8_t counter[5] = ""; |
|
|
|
|
|
|
|
McuUtility_Num8uToStr(counter, sizeof(counter), presentCnt); |
|
|
|
|
|
|
|
SHELL_SendString((unsigned char*)counter); |
|
|
|
|
|
|
|
SHELL_SendString((unsigned char*)"\r\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
break; |
|
|
|
break; |
|
|
|
} /* switch */ |
|
|
|
} /* switch */ |
|
|
|
@ -456,6 +497,11 @@ static uint8_t AutoCalibrateReflectance(void) { |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t SetManualMode(){ |
|
|
|
|
|
|
|
appState = APP_STATE_MANUAL_MOVE; |
|
|
|
|
|
|
|
return ERR_OK; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if 0 /* do not use this any more, use proper debouncing! */
|
|
|
|
#if 0 /* do not use this any more, use proper debouncing! */
|
|
|
|
static void CheckButton(void) { |
|
|
|
static void CheckButton(void) { |
|
|
|
#if PL_HAS_USER_BUTTON |
|
|
|
#if PL_HAS_USER_BUTTON |
|
|
|
@ -1011,6 +1057,8 @@ static uint8_t APP_PrintHelp(const McuShell_StdIOType *io) { |
|
|
|
#if PL_CONFIG_USE_LINE_SENSOR && PL_HAS_TURN |
|
|
|
#if PL_CONFIG_USE_LINE_SENSOR && PL_HAS_TURN |
|
|
|
McuShell_SendHelpStr((unsigned char*)" autocalib", (unsigned char*)"Automatically calibrate line sensor\r\n", io->stdOut); |
|
|
|
McuShell_SendHelpStr((unsigned char*)" autocalib", (unsigned char*)"Automatically calibrate line sensor\r\n", io->stdOut); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
//app manualdrive
|
|
|
|
|
|
|
|
McuShell_SendHelpStr((unsigned char*)" manualdrive", (unsigned char*)"Robot can be driven manualy\r\n", io->stdOut); |
|
|
|
return ERR_OK; |
|
|
|
return ERR_OK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1048,6 +1096,9 @@ uint8_t APP_ParseCommand(const unsigned char *cmd, bool *handled, const McuShell |
|
|
|
} else if (McuUtility_strcmp((char*)cmd, (char*)McuShell_CMD_STATUS)==0 || McuUtility_strcmp((char*)cmd, (char*)"app status")==0) { |
|
|
|
} else if (McuUtility_strcmp((char*)cmd, (char*)McuShell_CMD_STATUS)==0 || McuUtility_strcmp((char*)cmd, (char*)"app status")==0) { |
|
|
|
*handled = TRUE; |
|
|
|
*handled = TRUE; |
|
|
|
return APP_PrintStatus(io); |
|
|
|
return APP_PrintStatus(io); |
|
|
|
|
|
|
|
}else if(McuUtility_strcmp((char*)cmd, (char*)"app manualdrive")==0){ |
|
|
|
|
|
|
|
*handled = TRUE; |
|
|
|
|
|
|
|
return SetManualMode(); |
|
|
|
#if PL_CONFIG_USE_LINE_SENSOR && PL_HAS_TURN |
|
|
|
#if PL_CONFIG_USE_LINE_SENSOR && PL_HAS_TURN |
|
|
|
} else if (McuUtility_strcmp((char*)cmd, (char*)"app autocalib")==0) { |
|
|
|
} else if (McuUtility_strcmp((char*)cmd, (char*)"app autocalib")==0) { |
|
|
|
*handled = TRUE; |
|
|
|
*handled = TRUE; |
|
|
|
|