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@25:033263cf832c, 2019-06-06 (annotated)
- Committer:
- Wael_H
- Date:
- Thu Jun 06 12:39:55 2019 +0000
- Revision:
- 25:033263cf832c
- Parent:
- 24:314b1f6607c5
- Child:
- 26:fa8a8fa175cb
Arret d'urgence derniere version
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Wael_H | 2:8971078b1ccf | 1 | #include "mbed.h" |
| Wael_H | 5:34048faec367 | 2 | #include "CAN_asser.h" |
| Wael_H | 10:efa507ba2b35 | 3 | #include "Robot.h" |
| Wael_H | 10:efa507ba2b35 | 4 | |
| Wael_H | 24:314b1f6607c5 | 5 | void automate_testDeplacement(Robot&); |
| Wael_H | 24:314b1f6607c5 | 6 | bool automate_arretUrgence(Robot&); |
| Wael_H | 8:94ecfe411d02 | 7 | |
| Wael_H | 2:8971078b1ccf | 8 | int main(void) |
| Wael_H | 2:8971078b1ccf | 9 | { |
| Wael_H | 10:efa507ba2b35 | 10 | Robot robot; |
| Wael_H | 24:314b1f6607c5 | 11 | |
| Wael_H | 24:314b1f6607c5 | 12 | robot.setSpeed(80,400); |
| theolp | 17:aae5361ddddf | 13 | |
| Wael_H | 24:314b1f6607c5 | 14 | Timer timer_dbug; |
| Wael_H | 24:314b1f6607c5 | 15 | timer_dbug.start(); |
| theolp | 20:a1b5d032b422 | 16 | |
| Wael_H | 15:3d4543a6c100 | 17 | while(1) |
| Wael_H | 25:033263cf832c | 18 | if(!Robot::Jack) |
| theolp | 17:aae5361ddddf | 19 | { |
| Wael_H | 24:314b1f6607c5 | 20 | automate_testDeplacement(robot); |
| theolp | 17:aae5361ddddf | 21 | |
| Wael_H | 24:314b1f6607c5 | 22 | if(timer_dbug.read() > 0.5f) |
| Wael_H | 24:314b1f6607c5 | 23 | { |
| Wael_H | 24:314b1f6607c5 | 24 | timer_dbug.stop(); |
| Wael_H | 24:314b1f6607c5 | 25 | timer_dbug.reset(); |
| Wael_H | 24:314b1f6607c5 | 26 | timer_dbug.start(); |
| Wael_H | 24:314b1f6607c5 | 27 | } |
| theolp | 17:aae5361ddddf | 28 | } |
| Wael_H | 15:3d4543a6c100 | 29 | } |
| Wael_H | 15:3d4543a6c100 | 30 | |
| Wael_H | 24:314b1f6607c5 | 31 | void automate_testDeplacement(Robot& robot) |
| Wael_H | 24:314b1f6607c5 | 32 | { |
| Wael_H | 24:314b1f6607c5 | 33 | typedef enum{ AVANCE, ARRET_URGENCE } type_etat; |
| Wael_H | 24:314b1f6607c5 | 34 | static type_etat etat = AVANCE; |
| Wael_H | 23:bb1535360a98 | 35 | |
| Wael_H | 7:753e901d441b | 36 | |
| Wael_H | 7:753e901d441b | 37 | switch(etat) |
| Wael_H | 9:2113adf37c66 | 38 | { |
| Wael_H | 24:314b1f6607c5 | 39 | case AVANCE: |
| Wael_H | 24:314b1f6607c5 | 40 | robot.avance(2500); |
| Wael_H | 24:314b1f6607c5 | 41 | if( automate_arretUrgence(robot) ) |
| Wael_H | 24:314b1f6607c5 | 42 | etat = ARRET_URGENCE; |
| Wael_H | 13:9c62e263f245 | 43 | break; |
| Wael_H | 13:9c62e263f245 | 44 | |
| Wael_H | 24:314b1f6607c5 | 45 | case ARRET_URGENCE: |
| Wael_H | 24:314b1f6607c5 | 46 | robot.stop(); |
| Wael_H | 13:9c62e263f245 | 47 | break; |
| Wael_H | 13:9c62e263f245 | 48 | } |
| Wael_H | 13:9c62e263f245 | 49 | } |
| Wael_H | 23:bb1535360a98 | 50 | |
| Wael_H | 24:314b1f6607c5 | 51 | bool automate_arretUrgence(Robot& robot) |
| Wael_H | 24:314b1f6607c5 | 52 | { |
| Wael_H | 24:314b1f6607c5 | 53 | typedef enum{RAS, PERCEPTION, ARRET_URGENCE, ATTENTE_REPLACEMENT} type_etat; |
| Wael_H | 24:314b1f6607c5 | 54 | static type_etat etat = RAS; |
| Wael_H | 24:314b1f6607c5 | 55 | |
| Wael_H | 24:314b1f6607c5 | 56 | // Timer pour la durée sur la ligne blanche |
| Wael_H | 24:314b1f6607c5 | 57 | static Timer timerCNY; |
| Wael_H | 24:314b1f6607c5 | 58 | |
| Wael_H | 24:314b1f6607c5 | 59 | switch(etat) |
| Wael_H | 23:bb1535360a98 | 60 | { |
| Wael_H | 24:314b1f6607c5 | 61 | case RAS : |
| Wael_H | 24:314b1f6607c5 | 62 | if(robot.surBlanc(Robot::CNY_GAUCHE) && robot.surBlanc(Robot::CNY_DROIT)){ |
| Wael_H | 24:314b1f6607c5 | 63 | etat = PERCEPTION; |
| Wael_H | 24:314b1f6607c5 | 64 | timerCNY.start(); |
| Wael_H | 24:314b1f6607c5 | 65 | } |
| Wael_H | 23:bb1535360a98 | 66 | break; |
| Wael_H | 23:bb1535360a98 | 67 | |
| Wael_H | 24:314b1f6607c5 | 68 | case PERCEPTION : |
| Wael_H | 24:314b1f6607c5 | 69 | if(robot.surBlanc(Robot::CNY_GAUCHE) && robot.surBlanc(Robot::CNY_DROIT) && timerCNY.read() >= 0.15f ) |
| Wael_H | 24:314b1f6607c5 | 70 | etat = ARRET_URGENCE; |
| Wael_H | 24:314b1f6607c5 | 71 | else if( timerCNY.read() >= 0.15f ){ |
| Wael_H | 24:314b1f6607c5 | 72 | etat = RAS; |
| Wael_H | 24:314b1f6607c5 | 73 | timerCNY.stop(); |
| Wael_H | 24:314b1f6607c5 | 74 | timerCNY.reset(); |
| Wael_H | 24:314b1f6607c5 | 75 | } |
| Wael_H | 23:bb1535360a98 | 76 | break; |
| Wael_H | 23:bb1535360a98 | 77 | |
| Wael_H | 24:314b1f6607c5 | 78 | case ARRET_URGENCE : |
| Wael_H | 24:314b1f6607c5 | 79 | timerCNY.stop(); |
| Wael_H | 24:314b1f6607c5 | 80 | timerCNY.reset(); |
| Wael_H | 24:314b1f6607c5 | 81 | |
| Wael_H | 24:314b1f6607c5 | 82 | etat = ATTENTE_REPLACEMENT; |
| Wael_H | 23:bb1535360a98 | 83 | |
| Wael_H | 24:314b1f6607c5 | 84 | return true; |
| Wael_H | 24:314b1f6607c5 | 85 | |
| Wael_H | 24:314b1f6607c5 | 86 | case ATTENTE_REPLACEMENT : |
| Wael_H | 24:314b1f6607c5 | 87 | if(!robot.surBlanc(Robot::CNY_GAUCHE) && !robot.surBlanc(Robot::CNY_DROIT)) |
| Wael_H | 24:314b1f6607c5 | 88 | etat = RAS; |
| Wael_H | 23:bb1535360a98 | 89 | break; |
| Wael_H | 23:bb1535360a98 | 90 | } |
| Wael_H | 24:314b1f6607c5 | 91 | |
| Wael_H | 24:314b1f6607c5 | 92 | return false; |
| Wael_H | 23:bb1535360a98 | 93 | } |
| Wael_H | 24:314b1f6607c5 | 94 |