vittascience:labyrinthe
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| vittascience:labyrinthe [2026/03/06 12:46] – [idées d'algorythme pour sortir d un labytrinthe] admin | vittascience:labyrinthe [2026/03/06 16:23] (Version actuelle) – [algorythme essai] admin | ||
|---|---|---|---|
| Ligne 55: | Ligne 55: | ||
| ==== algorythme essai ==== | ==== algorythme essai ==== | ||
| - | 1- régler vitesse des moteurs entre 20% et 50% | + | * 1- régler vitesse des moteurs entre 20% et 50% |
| - | 2- Création de sous programmes : avancer , reculer, tourner droite 90° , tourner gauche 90°, stop, test distance | + | |
| - | 3- avancer jusqu' | + | |
| - | 4- si distance < 3 cm => stop | + | |
| - | 5- Tourner à droite => test distance obstacle | + | |
| - | 6- si distance > 20 => avancer jusqu' | + | |
| - | 7- sinon si distance < 3 cm => tourner encore à droite ( en tout depuis l' | + | |
| - | 8- test rotation si rotation => 180° | + | |
| - | 8- tourner encore de 180° ( 2 fois tourner droite) | + | |
| - | 8- si distance > 20 => avancer | + | |
| + | |||
| + | |||
| + | {{ : | ||
| + | |||
| + | |||
| + | {{ : | ||
| + | |||
| + | <code c laby0033.ino> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | MeDCMotor motor_L(9); | ||
| + | MeDCMotor motor_R(10); | ||
| + | // Ultrasonic on PORT_3 | ||
| + | MeUltrasonicSensor ultrasonic_3(PORT_3); | ||
| + | |||
| + | int distancemax; | ||
| + | int pause; | ||
| + | int vitesse; | ||
| + | |||
| + | void mBot_setMotorLeft(int8_t dir, int16_t speed) { | ||
| + | speed = speed/ | ||
| + | motor_L.run((9) == M1 ? -(dir*speed) : (dir*speed)); | ||
| + | } | ||
| + | |||
| + | void mBot_setMotorRight(int8_t dir, int16_t speed) { | ||
| + | speed = speed/ | ||
| + | motor_R.run((10) == M1 ? -(dir*speed) : (dir*speed)); | ||
| + | } | ||
| + | |||
| + | void avancer() { | ||
| + | while (ultrasonic_3.distanceCm() >= distancemax) { | ||
| + | mBot_setMotorRight(1, | ||
| + | mBot_setMotorLeft(1, | ||
| + | } | ||
| + | mBot_setMotorRight(0, | ||
| + | mBot_setMotorLeft(0, | ||
| + | delay(1000*pause); | ||
| + | } | ||
| + | |||
| + | void droite() { | ||
| + | mBot_setMotorRight(-1, | ||
| + | mBot_setMotorLeft(1, | ||
| + | delay(1000*pause); | ||
| + | mBot_setMotorRight(0, | ||
| + | mBot_setMotorLeft(0, | ||
| + | } | ||
| + | |||
| + | void gauche() { | ||
| + | mBot_setMotorLeft(-1, | ||
| + | mBot_setMotorRight(1, | ||
| + | delay(1000*pause); | ||
| + | mBot_setMotorRight(0, | ||
| + | mBot_setMotorLeft(0, | ||
| + | } | ||
| + | |||
| + | |||
| + | void setup() { | ||
| + | distancemax = 3; | ||
| + | pause = 1; | ||
| + | vitesse = 22; | ||
| + | avancer(); | ||
| + | droite(); | ||
| + | avancer(); | ||
| + | gauche(); | ||
| + | avancer(); | ||
| + | gauche(); | ||
| + | avancer(); | ||
| + | droite(); | ||
| + | mBot_setMotorRight(1, | ||
| + | mBot_setMotorLeft(1, | ||
| + | delay(1000*1); | ||
| + | mBot_setMotorRight(0, | ||
| + | mBot_setMotorLeft(0, | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | } | ||
| + | </ | ||
/home/chanteri/www/fablab37110/data/attic/vittascience/labyrinthe.1772797572.txt.gz · Dernière modification : de admin
