/*! * \brief Performs a turn. * \return Returns TRUE while turn is still in progress. */ uint8_t MAZE_EvaluteTurn(bool *finished) { REF_LineKind historyLineKind, currLineKind; TURN_Kind turn; *finished = FALSE; currLineKind = REF_GetLineKind(); if (currLineKind==REF_LINE_NONE) { /* nothing, must be dead end */ turn = TURN_LEFT180; } else { MAZE_ClearSensorHistory(); /* clear history values */ MAZE_SampleSensorHistory(); /* store current values */ TURN_Turn(TURN_STEP_LINE_FW_POST_LINE, MAZE_SampleTurnStopFunction); /* do the line and beyond in one step */ historyLineKind = MAZE_HistoryLineKind(); /* new read new values */ currLineKind = REF_GetLineKind(); turn = MAZE_SelectTurn(historyLineKind, currLineKind); } if (turn==TURN_FINISHED) { *finished = TRUE; LF_StopFollowing(); SHELL_SendString((unsigned char*)"MAZE: finished!\r\n"); return ERR_OK; } else if (turn==TURN_STRAIGHT) { /*! \todo Extend if necessary */ SHELL_SendString((unsigned char*)"going straight\r\n"); return ERR_OK; } else if (turn==TURN_STOP) { /* should not happen here? */ LF_StopFollowing(); SHELL_SendString((unsigned char*)"Failure, stopped!!!\r\n"); return ERR_FAILED; /* error case */ } else { /* turn or do something */ /*! \todo Extend if necessary */ return ERR_OK; /* turn finished */ } }
/*! * \brief Performs a turn. * \return Returns TRUE while turn is still in progress. */ uint8_t MAZE_EvaluteTurn(bool *finished, bool rule) { REF_LineKind historyLineKind, currLineKind; TURN_Kind turn; if (MAZE_IsSolved()) { if (!FollowSegment()) { if (index < pathLength) { //TURN_Turn(TURN_STEP_LINE_FW_POST_LINE,MAZE_SampleTurnStopFunction); TURN_Turn(TURN_STEP_LINE_FW_POST_LINE, NULL); TURN_Turn(MAZE_GetSolvedTurn(&index), NULL); } else { TURN_Turn(TURN_STEP_LINE_FW_POST_LINE, NULL); LF_StopFollowing(); index = 0; } } return ERR_OK; } else { *finished = FALSE; currLineKind = REF_GetLineKind(); if (currLineKind == REF_LINE_NONE) { /* nothing, must be dead end */ MAZE_AddPath(TURN_LEFT180); turn = TURN_LEFT180; } else { MAZE_ClearSensorHistory(); /* clear history values */ MAZE_SampleSensorHistory(); /* store current values */ TURN_Turn(TURN_STEP_LINE_FW_POST_LINE, MAZE_SampleTurnStopFunction); /* do the line and beyond in one step */ historyLineKind = MAZE_HistoryLineKind(); /* new read new values */ currLineKind = REF_GetLineKind(); turn = MAZE_SelectTurn(historyLineKind, currLineKind, rule); } if (turn == TURN_FINISHED) { *finished = TRUE; //LF_StopFollowing(); return ERR_OK; } else if (turn == TURN_STRAIGHT) { //SHELL_SendString((unsigned char*) "going straight\r\n"); return ERR_OK; } else if (turn == TURN_STOP) { /* should not happen here? */ LF_StopFollowing(); return ERR_FAILED; /* error case */ } else { /* turn or do something */ TURN_Turn(turn, NULL); return ERR_OK; /* turn finished */ } } }