add present counter, add state app_manual and auto

main
Simon Frei 4 years ago
parent 900ff1ae96
commit b96cd7582f
  1. 53
      ADIS_Sumo/Sumo/Application.c
  2. 2
      ADIS_Sumo/Sumo/LineFollow.c
  3. 10
      ADIS_Sumo/Sumo/Maze.c
  4. 3
      ADIS_Sumo/Sumo/Maze.h
  5. 2
      ADIS_Sumo/Sumo/Reflectance.c

@ -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;

@ -306,7 +306,7 @@ static void StateMachine(void) {
#endif #endif
//SHELL_SendString((unsigned char *)"MAZE: Going back to start...\r\n"); //SHELL_SendString((unsigned char *)"MAZE: Going back to start...\r\n");
//LF_currState = STATE_FOLLOW_SEGMENT; /* go back to start */ //LF_currState = STATE_FOLLOW_SEGMENT; /* go back to start */
MAZE_ClearSolution(); /* clear solution */ //MAZE_ClearSolution(); /* clear solution */
LF_currState = STATE_STOP; LF_currState = STATE_STOP;
break; break;
#endif #endif

@ -51,6 +51,15 @@ static TURN_Kind path[MAZE_MAX_PATH];
static uint8_t pathLength; static uint8_t pathLength;
static bool isSolved = FALSE; static bool isSolved = FALSE;
static bool useLeftHandOnTheWallRule = TRUE; static bool useLeftHandOnTheWallRule = TRUE;
static uint8_t presentCounter = 0;
uint8_t MAZE_ResetPresentCount(){
presentCounter = 0;
}
uint8_t MAZE_GetPresentCount(){
return presentCounter;
}
bool MAZE_IsLeftHandRule(void) { bool MAZE_IsLeftHandRule(void) {
return useLeftHandOnTheWallRule; return useLeftHandOnTheWallRule;
@ -207,6 +216,7 @@ uint8_t MAZE_EvaluteTurn(bool *finished, bool *deadEndGoBw) {
} }
#endif #endif
TURN_Turn(turn, NULL); /* make turn */ TURN_Turn(turn, NULL); /* make turn */
presentCounter++;
MAZE_AddPath(turn); MAZE_AddPath(turn);
MAZE_SimplifyPath(); MAZE_SimplifyPath();
return ERR_OK; /* turn finished */ return ERR_OK; /* turn finished */

@ -11,6 +11,9 @@
#if PL_CONFIG_APP_LINE_MAZE #if PL_CONFIG_APP_LINE_MAZE
#include "Turn.h" #include "Turn.h"
uint8_t MAZE_ResetPresentCount();
uint8_t MAZE_GetPresentCount();
/*! /*!
* \brief Adds a new path while going forward through the maze * \brief Adds a new path while going forward through the maze
* \param kind New path to be added * \param kind New path to be added

@ -754,7 +754,7 @@ void REF_Init(void) {
}; };
REF_Sensor.isEnabled = true; REF_Sensor.isEnabled = true;
REF_Sensor.savePower = false; /* turn off, as this extends the ref sensor task time by around 200 us */ REF_Sensor.savePower = true; /* turn off, as this extends the ref sensor task time by around 200 us */
McuGPIO_GetDefaultConfig(&gpioConfig); McuGPIO_GetDefaultConfig(&gpioConfig);
/* IR on/off: PTD1, high active */ /* IR on/off: PTD1, high active */
gpioConfig.hw.gpio = GPIOD; gpioConfig.hw.gpio = GPIOD;

Loading…
Cancel
Save