Différences entre versions de « Projets:Roboto »

De wikilab
Ligne 151 : Ligne 151 :
 
===== carte arduino uno =====
 
===== carte arduino uno =====
  
[[File:Arduino uno.jpg|left|200px]]
+
[[File:Arduino uno.jpg|200px]]
  
 
===== carte arduino nano =====
 
===== carte arduino nano =====

Version du 3 octobre 2019 à 10:21

Description du projet

Projet de robot sur roulette télécommandé en bluetooth.

Liens utiles

Cahier des charges

Analyse de l'existant

Equipe (Porteur de projet et contributeurs)

  • Porteur de projet
  • Contributeurs
  • Animateur (coordinateur du projet)
  • Fabmanager référent
  • Responsable de documentation

Matériel nécessaire

matériel Robot conteur
Roboto final.jpg



bois de palette récupération
Robotmaurebzh2vers.jpg



dimension du châssis

Robot plan de réalisation.pdf


Robot plan de réalisation.pdf



Arduino uno.jpg



plaque aluminium support moteur
Cotes plaque moteur roboto.jpg

fichier svg:

Fichier:Plaque-robot.zip




roues robot

[[1]]

400




entretoise roues robot

[[2]]

Entretoise roues robot.png



vises et boulonnerie

A ajuster suivant la construction et l'épaisseur du bois




batterie 12volt 12AH
Batterie 12v 12ah.jpg

<note important>important</note> a la dimension pour l'emplacement



chargeur batterie 12volt
 a prévoir




2 led ring12

<note fichier 3d disponible plus bas>fichier 3d disponible plus bas</note> fichier 3d disponible plus bas Robotchorus:neopixel rond.jpg?200 sert pour les yeux [[3]]


interrupteur

pour le boitier 3d et pour le boitier électrique (pas de consommation inutile) [[4]]

Interupteur_robot_boitier.jpg

[[5]] Robotchorus:interupteur robot boitier electrique.jpg?200

moteur à démultiplication
Description

Takanawa motoréducteur 555 métallique 12v - 24v motoréducteur à courant continu

spécification
  • modèle dcmotor RS- 555
  • tension appropriée 12v-24v
  • vitesse 10-20-40-80 tr / min
  • courant de charge 2.5a
  • Vitesse à vide DC12V 3000-3500r / min
  • dc la 7000-8000r / min
  • grandeur diamètre : 37 mm
  • longueur: 65 mm
  • poids 502g
  • longueur de l'arbre 16mm
traits
  • Haute vitesse , couple élevé , faible consommation d'énergie , à faible bruit
  • la structure -simple machine , facile d'entretien , longue durée de vie .
  • Large utilisé pour la puissance de rideau de propulsion électrique , fours électriques , popper , réservoir de modèle
  • REDUCER à la structure simple , une installation pratique , l'alimentation à haute efficacité et un fonctionnement fiable .

https:/www.banggood.com/fr/TAKANAWA-555-Metal-Gear-Motor-12V-24V-DC-Gear-Motor-p-995307.html?rmmds=myorder&cur_warehouse=CN

Dimension moteur.png Moteur-takanawa2.jpg

carte arduino uno

Arduino uno.jpg

carte arduino nano

Robotchorus:arduino-nano-microprocessor.jpg?200


Contoleur moteur

[[6]] Robotchorus:controleur moteur robot.png?200


    • note important>important</note> nunchuck**

manette de wii filaire Robotchorus:nunchuck.jpg?200 achat dans boutique achat vente ou récupération


Adaptateur nunchuck

[[7]]

Adaptateur nunchuk.png

hc05

(module bluethooth maitre exclave) Robotchorus:hc05-1.jpg?200Robotchorus:hc05 2.jpg?200

pile 9volt

Robotchorus:pile 9v.jpg?200

impression 3d:
(led et boitier commande)

<color #fff200>__conçue pour ne pas arracher le fil de la nunchuk__</color> Arduino:stl robot.zip Robotchorus:boitier-commande.png?200 200px

coffret électrique

<note important>important</note> bien vérifier les dimensions pour la batterie suivant l'emplacement

Découpe a l'intérieur pour faire de la place mais attention si vous voulez garder l’étanchéité Robotchorus:coffret electrique.png?200 disponible en magasin de bricolage

<color #ff7f27>schéma branchement Arduino batterie motor shield</color> Robotchorus:sscanner 18062613060 1 .pdf

Intro

Nous avons deux HC-05 qui sont maîtres par défaut. Il faut d'abord configurer les deux HC-05 (l'un en maitre et l'autre en esclave avant de pouvoir les faire communiquer.

Cette procédure se passe en mode commande (AT mode).

Nous allons d'abord configurer l'esclave puis le maître.

Pour cela, réaliser les deux montages (maître et esclave en mode AT).

Schéma Esclave Mode AT

On peut brancher le module HC-05 sur 5V (et pas 3V3).

<note warning>Le key est connecté au 3.3V en mode AT</note>

Arduino:hc-05 slave modeat ok2.jpg?direct&600


Schéma Maître Mode AT

Arduino:hc-05 master modeat.jpg?direct&600


Code

<note warning>Avant de téléverser le programme sur la carte arduino, débrancher le module HC-05 de l'alimentation</note>

  1. include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup() {

 pinMode (10, INPUT);
 pinMode (11, OUTPUT);
 pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
 digitalWrite(9, HIGH);
 Serial.begin(38400);
 Serial.println("Enter AT commands:");
 BTSerial.begin(38400);  // HC-05 default speed in AT command more

}

void loop() {

 // Keep reading from HC-05 and send to Arduino Serial Monitor
 if (BTSerial.available())
   Serial.write(BTSerial.read());
 
 // Keep reading from Arduino Serial Monitor and send to HC-05
 if (Serial.available())
   BTSerial.write(Serial.read());

}


Configurer deux HC-05 master : un maitre et l'autre esclave

Source:http://blog.zakkemble.net/getting-bluetooth-modules-talking-to-each-other/

Configuration du maitre comme esclave

Reset to defaults: AT+ORGL

Clear any paired devices: AT+RMAAD

Set PIN: AT+PSWD=1234

Slave mode: AT+ROLE=0

Get the address of the device: AT+ADDR?

Now that you have the address you can skip the AT+INQ and AT+RNAME? parts for configuring the master.

Turn off the module, disconnect key from 3.3V and turn back on. <note warning>Eteindre la board, déconnecter le Key du 3.3V et rallumer la board</note>

Schema Esclave Mode COM

Arduino:hc-05 slave modecom ok2.jpg?direct&600

Configuration du maitre

Now, to get the master to connect to the slave module you will need to find the address of the slave. **Make sure the slave module is powered up** and enter these commands into the master module:

Reset to defaults: AT+ORGL

Clear any paired devices: AT+RMAAD

Master mode: AT+ROLE=1

Need to restart after changing role: AT+RESET

Allow connecting to any address: AT+CMODE=1

Inquire mode – Standard, stop after 5 devices found, (or) stop searching after 5 seconds: AT+INQM=0,5,5

Set PIN, should be the same as the slave: AT+PSWD=1234

Start SPP profile lib (needed to do any Bluetooth transmitting/receiving): AT+INIT Note: If it says Error:(17) then that means it’s already loaded, you can carry on.

Start searching: AT+INQ

A short list of devices found should appear, one of them will be the slave module.

The format of the output is as follows: +INQ:address,type,signal

Type can be ignored. The signal will be 7FFF since inquire is in standard mode, in RSSI mode you’ll get a load of the same device but with different signal levels which you don’t want at the moment.

Copy the address part of the devices found, for example 12:3:289431 and change the colons to commas – 12,3,289431. To find out which device is the slave module you will need to query each address for its name: AT+RNAME? <address>

Replace <address> with address of device like 12,3,289431

Response should be +RNAME:linvor if you’re using a normal slave module or +RNAME:HC05 if you’re using a master module as a slave.

Now you’ve got the address of the slave module you need to pair with it: AT+PAIR=<address>,<timeout> Note: If you are going to make the master connect to your phone then you need to set the timeout long enough for you to type in the PIN.

Bind address: AT+BIND=<address>

Only allow connecting to the bound address: AT+CMODE=0

And now to actually connect: AT+LINK=<address>

If successful the slave LED should be on solid and the master LED should have a heartbeat flash pattern.

The modules have now been configured! They should automatically connect to each other whenever possible.

A full list of commands for master modules can be found in the download below.

Sending data

Now, if you entered AT mode on the master module by connecting key to 3.3V before turning on the module, you will need to turn off the module, disconnect key (if not enough plug it to Ground) and turn it back on. If you connected key while the module was on then all you need to do is disconnect key.

Maître Mode COM

Arduino:hc-05 master modecom ok.jpg?direct&600


Envoyer et recevoir des données en Mode COM

If you open up 2 serial consoles (2 different Arduino IDE) and have one open the COM port to the slave and the other open the COM port to the master you should be able to type in one and it will appear in the other console, if that worked you just need to plug them in to your projects!


Sketchs pour envoyer des données depuis une variable (msg)

Source: https://www.instructables.com/id/How-to-Configure-HC-05-Bluetooth-Module-As-Master-/

Sketch maître

  1. include <SoftwareSerial.h>

//SoftwareSerial ArduinoSlave(2,3); SoftwareSerial ArduinoSlave(10, 11); // RX | TX //SoftwareSerial ArduinoSlave(10, 11); // RX | TX

String answer; String msg; void setup(){

Serial.begin(38400);
Serial.println("ENTER Commands:");
ArduinoSlave.begin(38400);
              

} void loop(){

//Read command from monitor
readSerialPort();

//Read answer from slave
 while (ArduinoSlave.available()) {
 delay(100);  
 if (ArduinoSlave.available() >0) {
   char c = ArduinoSlave.read();  //gets one byte from serial buffer
   answer += c; //makes the string readString
 }

}

//Send data to slave
if(msg!=""){
  Serial.print("Master sent : ");
  Serial.println(msg);
  ArduinoSlave.print(msg);
  msg="";
}
//Send answer to monitor
if(answer!=""){
  Serial.print("Slave received : ");
  Serial.println(answer);
  answer="";
}

} void readSerialPort(){ while (Serial.available()) {

 delay(10);  
 if (Serial.available() >0) {
   char c = Serial.read();  //gets one byte from serial buffer
   msg += c; //makes the string readString
 }

} Serial.flush(); }

Sketch esclave

  1. include <SoftwareSerial.h>

//SoftwareSerial ArduinoMaster(2,3); SoftwareSerial ArduinoMaster(10, 11); // RX | TX String msg; void setup(){

Serial.begin(38400);
ArduinoMaster.begin(38400);    

} void loop(){

readSerialPort();

// Send answer to master
if(msg!=""){
  Serial.print("Master sent : " );
  Serial.println(msg);
  ArduinoMaster.print(msg);
  msg=""; 
}

} void readSerialPort(){ while (ArduinoMaster.available()) {

 delay(100); 
 if (ArduinoMaster.available() >0) {
   char c = ArduinoMaster.read();  //gets one byte from serial buffer
   msg += c; //makes the string readString
 }

} ArduinoMaster.flush(); }


Photos montage

Arduino:img 4656.jpg?direct&600

Arduino:img 4654.jpg?direct&600

Arduino:img 4655.jpg?direct&600

Schemas trouvés en ligne

https://www.gme.cz/data/attachments/dsh.772-148.2.pdf

Arduino:img 4657.jpg?direct&600

Arduino:hc-05 connections.jpg?direct&600


AT commands=

Most useful AT commands are

AT : Ceck the connection.

AT+NAME : See default name

AT+ADDR : see default address

AT+VERSION : See version

AT+UART : See baudrate

AT+ROLE: See role of bt module(1=master/0=slave)

AT+RESET : Reset and exit AT mode

AT+ORGL : Restore factory settings

AT+PSWD: see default password

Circuit maitre : Nano+Nunchuck+BT

Test avec TEST_BLUETOOTH.ino

Role 1 attribué en bluetooth ok.


AT+BIND=>pour trouver l'adresse à laquelle il est lié

Role maître : +BIND:98d3:31:f41bcf (adresse esclave)

Circuit esclave Uno+Moteurs+BT

Role 0 attribué en bluetooth ok.


https://www.aranacorp.com/fr/votre-arduino-communique-avec-le-module-hc-05/


https://letmeknow.fr/blog/2013/10/09/tuto-commander-un-relais-en-bluetooth/

https://www.instructables.com/id/How-to-Configure-HC-05-Bluetooth-Module-As-Master-/

AT+STATE?

AT+IRQ

https://arduino.stackexchange.com/questions/52846/scan-bluetooth-devices-using-hc-05

https://cdn.instructables.com/ORIG/FI9/7NJR/IRXT0JIG/FI97NJRIRXT0JIG.pdf


https://www.youtube.com/watch?v=hyME1osgr7s


AT+RMAAD pour annuler pairing

https://cdn.instructables.com/ORIG/FI9/7NJR/IRXT0JIG/FI97NJRIRXT0JIG.pdf

https://www.instructables.com/id/HOW-TO-HC-05-Bluetooth-MODULE-AT-Commands-With-But/


AT+UART (config du baudrate)

http://sti2d-sin-isn.blogspot.com/2018/02/auto-connexion-de-deux-modules.html

https://electronics.stackexchange.com/questions/101572/hc-05-bluetooth-module-not-responding-to-certain-commands

The TUTORIAL with all steps

Attention à l'ordre dans lequel on branche/débranche le key Faire une AT+reset après avoir débranché le key (ou l'inverse, check last link

http://blog.zakkemble.net/getting-bluetooth-modules-talking-to-each-other/


set pin enable to low (GROUND) pour switcher en mode communication

essayer en laissant le pin key sur 3.3V (apres avoir éteint la board) pour switcher du mode AT

https://www.teachmemicro.com/hc-05-bluetooth-command-list/

https://arduino.stackexchange.com/questions/16954/problems-connecting-reliably-using-hc-05-as-bluetooth-master

https://forum.core-electronics.com.au/t/solved-how-could-i-take-my-hc05-module-out-of-at-command-mode-without-disconnecting-the-arduino/1792/5


http://forum.hobbycomponents.com/viewtopic.php?f=39&t=1567

Bluetooth+motor+joystick example

https://forum.arduino.cc/index.php?topic=413699.15

https://www.instructables.com/id/Wireless-Wii-Nunchuck-control-of-Arduino-projects/

Reconstruire un nombre en recevant ses éléments un par un

https://openclassrooms.com/forum/sujet/hc-06-et-arduino

// Variable globale (à placer en dehors du loop) int pwmval = 0;


// Partie traitement (à placer dans le loop) if ( Serial.available() ) {

   char c = Serial.read();
   if ( ( c >= '0' ) && ( c <= '9' ) ) {
       pwmval = ( ( pwmval * 10 ) + ( c - '0' ) );
   } else if ( c == 'x' ) {
       analogWrite(pinX, pwmval);
       pwmval = 0;
   } else if ( c == 'y' ) {
       analogWrite(pinY, pwmval);
       pwmval = 0;
   }

}

Librairie pour retrouver les données reçues

https://github.com/jlebunetel/WiiExpansion

code final

/*

  1. Product: DC Motor Driver 2x15A_lite
 # SKU    : DRI0018
 # Description:
 # Drive 2 motors with this DC Motor Driver module
 # Hardwares:
 1. Arduino UNO
 2. DC Motor Driver 2x15A_lite
 3. DC motors x2
 #Steps:
 1.Connect the DMotD_PWM & DMotG_PWM to UNO digital 5 & 6
 2.Connect the DMotD_EN & DMotG_EN to UNO digital 4 & 7
 3.Connect +5V & GND to UNO 5V & GND
  • /

//Bluetooth

  1. include <SoftwareSerial.h>

SoftwareSerial ArduinoMaster(10, 11); // RX | TX

//nunchuck+bluetooth int joyX; int joyY; int joyC; int joyZ;

int valeurs_joystick[4] = {0, 0, 0, 0}; int valeurs_joystick_precedent[4] = {0, 0, 0, 0};

//DC Motor Driver pins int VMotD = 5; //VMotD Speed Control mot droit int VMotG = 6; //VMotG Speed Control mot gauche int DMotG = 7; //DMotD Direction Control int DMotD = 4; //DMotD Direction Control

//infos moteurs boolean p;//détection d'un pivotement int smg;//sens moteur gauche int smd;//sens moteur droite int vmg;//vitesse moteur gauche int vmd;//vitesse moteur droite float b;//valeur(amplitude) du braquage int v1;//valeur vitesse moteur 1 int v2;//valeur vitesse moteur 2

int var [4] = {0, 0, 0, 0}; int k = 0;


void setup() {

 //motor driver
 int i;
 for (i = 4; i <= 7; i++)
   pinMode(i, OUTPUT);
 Serial.println("Run keyboard control");
 digitalWrite(VMotD, LOW);
 digitalWrite(VMotG, LOW);
 //bluetooth serial
 Serial.begin(38400);
 Serial.println("Bluetooth nunchuck esclave start");
 ArduinoMaster.begin(38400);

}




void loop() {

while (ArduinoMaster.available() > 0 ) {
  char car = ArduinoMaster.read();
 //  while (Serial.available() > 0 ) {
    // char car = Serial.read();

// Serial.print(car);

   switch (car) {
     case '\n':    // fin de données
       renvoi();
       execution();
       k = 0;
       break;
     case ';':     // séparateur
       k++;
       break;
     default:
       var[k] = (var[k] * 10) + (car - 48);
       break;
   }
  // delay(50);
 }
 delay(10);

}

void renvoi() {

 joyX = var[0];
 joyY = var[1];
 joyC = var[2];
 joyZ = var[3];
     Serial.print("Brut    ");
     Serial.print("joyX :");
     Serial.print(joyX);
     Serial.print("   joyY :");
     Serial.println(joyY);
     Serial.print("   joyC :");
     Serial.print(joyC);
     Serial.print("   joyZ :");
     Serial.println(joyZ);      
 for (k = 0; k < 4; k++) {
   Serial.println(var[k]);       // renvoi des valeurs reçues
   var[k] = 0;
 }
// delay(50);

}

void execution() { // execution ordre recu

// v1 = 0;
  //v2 = 0;
   int joyX1 = map(joyX, 26, 231, -255, +255);
   int joyY1 = map(joyY, 35, 226, -255, +255);
   joyX = constrain (joyX1, -255, +255);
   joyY = constrain (joyY1, -255, +255);
     Serial.print("Remappé   ");
     Serial.print("   joyX :");
     Serial.print(joyX);
     Serial.print("   joyY :");
     Serial.println(joyY);
 //Pour éviter de consommer du courant on attribue une plage neutre plus large que zéro
 if ((joyX < 32) && (joyX > -32)) {
   joyX = 0;
    Serial.print("   joyXX :");
     Serial.print(joyX);
 }
 if ((joyY < 25) && (joyY > -25)) { 
   joyY = 0;
   Serial.print("   joyYY :");
     Serial.println(joyY);
 }
 //détection du pivotement x
 if ((joyX != 0)&& (joyY == 0))  {
   p = 1;
 } else   p = 0;


 //calcul du sens de rotation des moteurs (attention les moteurs sont montés en miroir)
 if (p == 1) {
   if (joyX < 0) { //tourne à gauche
     smg = 0;
     smd = 0;
   } else { //tourne à droite
     smg = 1;
     smd = 1;
   }
 } else if (joyY < 0) { //recule
   smg = 0;
   smd = 1;
 } else { //avance
   smg = 1;
   smd = 0;
 }


 //calcul valeur du braquage  (amplitude du braquage)
 if (joyX < 0) {
   b = joyX * -1;
 } else {
   b = joyX;
 }
 //si pivotement (cad que le centre de rotation est entre les deux moteurs), les deux moteurs vont à la même vitesse
 if (p == 1) {
   vmg = b;
   vmd = b;
 }
 else {
   if (joyY < 0) {    //calcul de 2 vitesses v1 et v2 qui seront affectées au moteur
     
     v1 = joyY * -1;   //on calcule la valeur absolue de la vitesse moteur 1
   } 
   else { v1 = joyY; }
   Serial.print("v1 :");
   Serial.println(v1);
   Serial.print("v2 :");
   Serial.println(v2);
   v2 = v1 - (v1 * (b / 255));
   Serial.print("v1 :");
   Serial.println(v1);
   Serial.print("v2 :");
   Serial.println(v2);

// ajout ylc du 30/03/19

   /* compte tenu des moteurs (24v utilisés en 12v) il est nécéssaire de "doper" les vitesses qui leurs sont affectées
      lors des virages en affectant à la roue la plus rapide la vitesse maximale et en augmentant la vitesse de la roue
      la moins rapide dans la même proportion.           */
   float c = 255 / v1;
   v1 = 255;
   v2 = v2 * c;

// fin ajout ylc du 30/03/19

   // Affectation des vitesses de rotation des moteurs des moteurs selon la direction où aller (droite ou gauche)
  if ((joyX == 0) && (joyY == 0)) {
     v1 = 0;
     v2 = 0;            
   }
   if (joyX < 0) {
     vmg = v2;
     vmd = v1;
   }
   else {          
     vmg = v1;
     vmd = v2;     
   }
 
 /*  if (joyX < 0) {
     vmg = v2;
     vmd = v1;
   }
   else if (joyX > 0) {
     vmg = v1;
     vmd = v2;



   }
 else if ((joyX == 0)&& (joyY == 0)) {
     vmg = 0;
     vmd = 0;
     smg=0;
     smd=0;
   }
   */
   }
 Serial.print("vmg :");
 Serial.println(vmg);
 Serial.print("vmd :");
 Serial.println(vmd);
 Serial.print("p :");
 Serial.println(p);
 Serial.print("smg :");
 Serial.println(smg);
 Serial.print("smd :");
 Serial.println(smd);
 control_moteur();

}


////motor driver void control_moteur() { //Move forward

 analogWrite (VMotG, vmg);     //PWM Speed Control
 digitalWrite(DMotG, smg); //DMotD, direction control=p
 analogWrite (VMotD, vmd);
 digitalWrite(DMotD, smd);

}

Outils nécessaires

Coût

Délai estimé

Fichiers source

Étapes de fabrication pas à pas

Configuration du bluetooth

Durée de fabrication du prototype final