Outils pour utilisateurs

Outils du site


projets:2019:stageavrilubo

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
projets:2019:stageavrilubo [2019/04/18 09:17] – [Contacts] christian.jacolotprojets:2019:stageavrilubo [2022/09/04 21:04] (Version actuelle) – modification externe 127.0.0.1
Ligne 235: Ligne 235:
  
 </code> </code>
 +
 +Android APK pour le robot Arduino:
 +https://cloud.archieri.fr/s/WzxmeGBmEKow5co
 +
  
  
Ligne 281: Ligne 285:
 <code> <code>
 #include <NewPing.h> #include <NewPing.h>
- +#include <Servo.h>
-# include <Servo.h>+
  
 Servo servoLeft; Servo servoLeft;
Ligne 303: Ligne 306:
   avancer();   avancer();
   if (distance < 10) {   if (distance < 10) {
-    reculer() +    reculer(); 
-    gauche();+    tournerGauche();
   }   }
 } }
Ligne 314: Ligne 317:
  
 void avancer() { void avancer() {
-  servoLeft.write( xx  ); // 0 => sens, 180 => autre sens +  servoLeft.write(  ); // 0 => sens, 180 => autre sens 
-  servoRight.write( xx ); // +  servoRight.write( 180 ); // 
 } }
  
 void reculer() { void reculer() {
-  servoLeft.write( xx  ); // 0 => sens, 180 => autre sens +  servoLeft.write( 180  ); // 0 => sens, 180 => autre sens 
-  servoRight.write( xx ); // +  servoRight.write( ); // 
 } }
  
-void tourner() { +void tournerGauche() { 
-  servoLeft.write( xx  ); // 0 => sens, 180 => autre sens +  servoLeft.write(45); // 0 => sens, 180 => autre sens 
-  servoRight.write( xx ); // +  servoRight.write(45); //  
 +
 + 
 +void tournerDroite() { 
 +  servoLeft.write(135); // 0 => sens, 180 => autre sens 
 +  servoRight.write(135); //  
 +
 + 
 +</code> 
 + 
 + 
 +Avec le bluetooth (message provenant du robot): 
 +<code> 
 +#include <NewPing.h> 
 +#include <Servo.h> 
 +#include <SoftwareSerial.h> 
 + 
 +Servo servoLeft; 
 +Servo servoRight; 
 + 
 +NewPing sonar(7, 6, 200); 
 + 
 +SoftwareSerial BTSerial(4, 8); // TX, RX 
 + 
 +void setup() { 
 +  servoLeft.attach(11); 
 +  servoRight.attach(10); 
 +  //Serial.begin(9600); 
 +  BTSerial.begin(9600); 
 +
 + 
 +void loop() { 
 +  gestionSonar(); 
 +
 + 
 +void gestionSonar() { 
 +  int distance = sonar.ping_cm(); 
 +  avancer(); 
 +  if (distance > 0 && distance < 10) { 
 +    BTSerial.println("obstacle < 10cm");  
 +    reculer(); 
 +    tournerGauche(); 
 +  } 
 +
 + 
 +void stop() { 
 +  servoLeft.write(90); // 0 => sens, 180 => autre sens 
 +  servoRight.write(90); // 
 +  BTSerial.println("stop");  
 +
 + 
 +void avancer() { 
 +  servoLeft.write( 0  ); // 0 => sens, 180 => autre sens 
 +  servoRight.write( 180 ); //  
 +  BTSerial.println("avance"); 
 +
 + 
 +void reculer() { 
 +  servoLeft.write( 180  ); // 0 => sens, 180 => autre sens 
 +  servoRight.write( 0 ); //  
 +  BTSerial.println("recule"); 
 +
 + 
 +void tournerGauche() { 
 +  servoLeft.write(45); // 0 => sens, 180 => autre sens 
 +  servoRight.write(45); //  
 +  BTSerial.println("gauche"); 
 +
 + 
 +void tournerDroite() { 
 +  servoLeft.write(135); // 0 => sens, 180 => autre sens 
 +  servoRight.write(135); //  
 +  BTSerial.println("droite"); 
 +
 + 
 +</code> 
 + 
 + 
 +Avec le bluetooth (piloter le robot): 
 +<code> 
 +#include <NewPing.h> 
 +#include <Servo.h> 
 +#include <SoftwareSerial.h> 
 + 
 +Servo servoLeft; 
 +Servo servoRight; 
 + 
 +NewPing sonar(7, 6, 200); 
 + 
 +SoftwareSerial BTSerial(4, 8); // TX, RX 
 + 
 +String message; 
 + 
 +void setup() { 
 +  servoLeft.attach(11); 
 +  servoRight.attach(10); 
 +  //Serial.begin(9600); 
 +  BTSerial.begin(9600); 
 +
 + 
 +void loop() { 
 +  gestionSonar(); 
 +  readBTSerial(); 
 +
 + 
 +String readBTSerial() { 
 +  while (BTSerial.available()) { 
 +    message = BTSerial.readString();   
 +  } 
 +  if (message == "av\r\n") { 
 +    avancer(); 
 +  } else if (message == "ar\r\n") { 
 +    reculer(); 
 +  } else if (message == "g\r\n") { 
 +    tournerGauche(); 
 +  } else if (message == "d\r\n") { 
 +    tournerDroite(); 
 +  } 
 +
 + 
 +void gestionSonar() { 
 +  int distance = sonar.ping_cm(); 
 +  avancer(); 
 +  if (distance > 0 && distance < 10) { 
 +    BTSerial.println("obstacle < 10cm");  
 +    reculer(); 
 +    tournerGauche(); 
 +  } 
 +
 + 
 +void stop() { 
 +  servoLeft.write(90); // 0 => sens, 180 => autre sens 
 +  servoRight.write(90); // 
 +  BTSerial.println("stop");  
 +
 + 
 +void avancer() { 
 +  servoLeft.write( 0  ); // 0 => sens, 180 => autre sens 
 +  servoRight.write( 180 ); //  
 +  BTSerial.println("avance"); 
 +
 + 
 +void reculer() { 
 +  servoLeft.write( 180  ); // 0 => sens, 180 => autre sens 
 +  servoRight.write( 0 ); //  
 +  BTSerial.println("recule"); 
 +
 + 
 +void tournerGauche() { 
 +  servoLeft.write(45); // 0 => sens, 180 => autre sens 
 +  servoRight.write(45); //  
 +  BTSerial.println("gauche"); 
 +
 + 
 +void tournerDroite() { 
 +  servoLeft.write(135); // 0 => sens, 180 => autre sens 
 +  servoRight.write(135); //  
 +  BTSerial.println("droite");
 } }
  
projets/2019/stageavrilubo.1555579056.txt.gz · Dernière modification : 2022/09/04 21:03 (modification externe)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki