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
Prochaine révisionLes deux révisions suivantes
projets:2019:stageavrilubo [2019/04/17 15:02] – [Contacts] christian.jacolotprojets:2019:stageavrilubo [2019/04/19 08:36] christian.jacolot
Ligne 235: Ligne 235:
  
 </code> </code>
 +
 +Android APK pour le robot Arduino:
 +https://cloud.archieri.fr/s/fytRHdn9XXqJqtH
 +
 +
  
  
Ligne 261: Ligne 266:
 } }
  
-void avance() {+void avancer() {
   servoLeft.write( xx  ); // 0 => sens, 180 => autre sens   servoLeft.write( xx  ); // 0 => sens, 180 => autre sens
   servoRight.write( xx ); //    servoRight.write( xx ); // 
Ligne 277: Ligne 282:
  
 </code> </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.txt · Dernière modification : 2022/09/04 21:04 de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki