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/16 20:13] – [Contacts] christian.jacolotprojets:2019:stageavrilubo [2024/04/16 22:26] (Version actuelle) – modification externe 127.0.0.1
Ligne 229: Ligne 229:
  
  
-Code +Pour récupérer le code du robot adapté: 
 + 
 +<code> 
 +$ git clone https://git.archieri.fr/simon/SimpleBotArduino.git 
 + 
 +</code> 
 + 
 +Android APK pour le robot Arduino: 
 +https://cloud.archieri.fr/s/WzxmeGBmEKow5co 
 + 
 + 
 + 
 +Test Servo 
 +<code> 
 + 
 +# include <Servo.h> 
 + 
 +Servo servoLeft; 
 +Servo servoRight; 
 + 
 +void setup() { 
 +  servoLeft.attach(11); 
 +  servoRight.attach(10); 
 +  Serial.begin(9600); 
 +
 + 
 +void loop() { 
 +  servoLeft.write(90); // 0 => sens, 180 => autre sens 
 +  servoRight.write(90); //  
 +
 + 
 +void stop() { 
 +  servoLeft.write(90); // 0 => sens, 180 => autre sens 
 +  servoRight.write(90); //  
 +
 + 
 +void avancer() { 
 +  servoLeft.write( xx  ); // 0 => sens, 180 => autre sens 
 +  servoRight.write( xx ); //  
 +
 + 
 +void reculer() { 
 +  servoLeft.write( xx  ); // 0 => sens, 180 => autre sens 
 +  servoRight.write( xx ); //  
 +
 + 
 +void tourner() { 
 +  servoLeft.write( xx  ); // 0 => sens, 180 => autre sens 
 +  servoRight.write( xx ); //  
 +
 + 
 +</code> 
 + 
 +Avec le sonar 
 +<code> 
 +#include <NewPing.h> 
 +#include <Servo.h> 
 + 
 +Servo servoLeft; 
 +Servo servoRight; 
 + 
 +NewPing sonar(7, 6, 200); 
 + 
 +void setup() { 
 +  servoLeft.attach(11); 
 +  servoRight.attach(10); 
 +  Serial.begin(9600); 
 +
 + 
 +void loop() { 
 +  gestionSonar(); 
 +
 + 
 +void gestionSonar() { 
 +  int distance = sonar.ping_cm(); 
 +  avancer(); 
 +  if (distance < 10) { 
 +    reculer(); 
 +    tournerGauche(); 
 +  } 
 +
 + 
 +void stop() { 
 +  servoLeft.write(90); // 0 => sens, 180 => autre sens 
 +  servoRight.write(90); //  
 +
 + 
 +void avancer() { 
 +  servoLeft.write( 0  ); // 0 => sens, 180 => autre sens 
 +  servoRight.write( 180 ); //  
 +
 + 
 +void reculer() { 
 +  servoLeft.write( 180  ); // 0 => sens, 180 => autre sens 
 +  servoRight.write( 0 ); //  
 +
 + 
 +void tournerGauche() { 
 +  servoLeft.write(45); // 0 => sens, 180 => autre sens 
 +  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"); 
 +
 + 
 +</code> 
  
projets/2019/stageavrilubo.1555438428.txt.gz · Dernière modification : 2024/04/16 22:27 (modification externe)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki