Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
- Committer:
- Wael_H
- Date:
- 2019-06-06
- Revision:
- 25:033263cf832c
- Parent:
- 24:314b1f6607c5
- Child:
- 26:fa8a8fa175cb
File content as of revision 25:033263cf832c:
#include "mbed.h" #include "CAN_asser.h" #include "Robot.h" void automate_testDeplacement(Robot&); bool automate_arretUrgence(Robot&); int main(void) { Robot robot; robot.setSpeed(80,400); Timer timer_dbug; timer_dbug.start(); while(1) if(!Robot::Jack) { automate_testDeplacement(robot); if(timer_dbug.read() > 0.5f) { timer_dbug.stop(); timer_dbug.reset(); timer_dbug.start(); } } } void automate_testDeplacement(Robot& robot) { typedef enum{ AVANCE, ARRET_URGENCE } type_etat; static type_etat etat = AVANCE; switch(etat) { case AVANCE: robot.avance(2500); if( automate_arretUrgence(robot) ) etat = ARRET_URGENCE; break; case ARRET_URGENCE: robot.stop(); break; } } bool automate_arretUrgence(Robot& robot) { typedef enum{RAS, PERCEPTION, ARRET_URGENCE, ATTENTE_REPLACEMENT} type_etat; static type_etat etat = RAS; // Timer pour la durée sur la ligne blanche static Timer timerCNY; switch(etat) { case RAS : if(robot.surBlanc(Robot::CNY_GAUCHE) && robot.surBlanc(Robot::CNY_DROIT)){ etat = PERCEPTION; timerCNY.start(); } break; case PERCEPTION : if(robot.surBlanc(Robot::CNY_GAUCHE) && robot.surBlanc(Robot::CNY_DROIT) && timerCNY.read() >= 0.15f ) etat = ARRET_URGENCE; else if( timerCNY.read() >= 0.15f ){ etat = RAS; timerCNY.stop(); timerCNY.reset(); } break; case ARRET_URGENCE : timerCNY.stop(); timerCNY.reset(); etat = ATTENTE_REPLACEMENT; return true; case ATTENTE_REPLACEMENT : if(!robot.surBlanc(Robot::CNY_GAUCHE) && !robot.surBlanc(Robot::CNY_DROIT)) etat = RAS; break; } return false; }