Ce petit robot mobile roulant à entraînement différentiel, à construire soi-même, se pilote par WiFi, avec un ordiphone (téléphone portable) par exemple.
Il se compose :
Nomenclature :
9 | 2 | Bracelet élastique (pneu) | Ø 80 × 5 | |
8 | 1 | Boîtier à piles avec interrupteur | 4 piles AAA/LR3 | |
7 | 2 | Servomoteur à rotation continue | FS90R | |
6 | 1 | Carte Wemos D1 mini | ||
5 | 2 | Roue | PLA | |
4 | 1 | Bouchon | PLA | |
3 | 1 | Bille | PLA | |
2 | 1 | Appui | PLA | |
1 | 1 | Châssis | PLA | |
REP. | NB. | DESIGNATION | MATIERE | OBS. |
---|
Ces éléments ayant été modélisés avec SolidWorks (version 2019), il s'agit maintenant de les assembler pour s'assurer que le montage sera possible. Pour commencer :
#include <ESP8266WiFi.h> #include <ESP8266mDNS.h> #include <Servo.h> const char* ssid = "ROBOT_DIFFERENTIEL"; const char* password = ""; // mot de passe avec soit 0 caractères soit 8 ou plus const char* hote = "ihm"; // taper http://ihm.local dans la barre d'adresses du navigateur IPAddress local_IP(192,168,0,222); IPAddress gateway(192,168,4,9); IPAddress subnet(255,255,255,0); WiFiServer server(80); Servo servogauche; Servo servodroit; int etat = 0; void setup() { Serial.begin(9600); delay(50); Serial.println(""); WiFi.softAPConfig(local_IP, gateway, subnet); Serial.println("Point d'accès Wifi configuré"); WiFi.softAP(ssid,password); Serial.println("Point d'accès Wifi démarré"); Serial.print("Adresse IP du point d'accès Wifi : "); Serial.println(WiFi.softAPIP()); MDNS.begin(hote); Serial.println("Multicast DNS démarré"); server.begin(); Serial.println("Serveur Web démarré"); Serial.println(""); } void loop() { // Vérifier si le client est connecté WiFiClient client = server.available(); if (!client) { return; } // Attendre jusqu'à ce que le client envoie sa requête Serial.println("Nouveau client"); while (!client.available()) { delay(100); } // Lire la première ligne de la requête String request = client.readStringUntil('\r'); Serial.println(request); client.flush(); // Analyser la requête if (request.indexOf("avance") != -1) { etat = 1; } else if (request.indexOf("recule") != -1) { etat = 2; } else if (request.indexOf("gauche") != -1) { etat = 3; } else if (request.indexOf("droite") != -1) { etat = 4; } else { etat = 0; } // Agir sur le système servogauche.attach(5); servodroit.attach(4); if (etat == 0) { servogauche.detach(); servodroit.detach(); } if (etat == 1) { servogauche.write(10); servodroit.write(170); } if (etat == 2) { servogauche.write(170); servodroit.write(10); } if (etat == 3) { servogauche.write(170); servodroit.write(170); } if (etat == 4) { servogauche.write(10); servodroit.write(10); } // Retourner au client l'IHM String html = "HTTP/1.1 200 OK\n" "Content-Type: text/html\n\n" "<!DOCTYPE html>" "<html>" "<head>" "<meta charset=\"utf-8\">" "<style>" "body { background-color:#163; text-align:center; }" "h1 { color:#cfc; }" "div { line-height:0px; }" "svg { width:150px; height:150px; }" "a:hover { opacity:0.8; }" "</style>" "</head>" "<body>" "<h1>Le robot "; if (etat == 0) html += "est à l'arrêt"; if (etat == 1) html += "avance"; if (etat == 2) html += "recule"; if (etat == 3) html += "vire à gauche"; if (etat == 4) html += "vire à droite"; html += ".</h1>" "<div>" "<a href=\"/avance\"><svg viewBox=\"0 0 100 100\">" "<path d=\"M 12 100 C 36 83 64 83 88 100 C 149 -33 -49 -33 12 100\" fill=\"#cfc\"/>" "<path d=\"M 35 65 L 50 25 L 65 65\"/>" "</svg></a>" "<br>" "<a href=\"/gauche\"><svg viewBox=\"0 0 100 100\">" "<path d=\"M 100 12 C 83 36 83 64 100 88 C -33 149 -33 -49 100 12\" fill=\"#cfc\"/>" "<path d=\"M 65 35 L 25 50 L 65 65\"/>" "</svg></a><a href=\"/arrete\"><svg viewBox=\"0 0 100 100\">" "<circle cx=\"50\" cy=\"50\" r=\"50\" fill=\"#cfc\"/>" "<path d=\"M 35 35 H 65 V 65 H 35\"/>" "</svg></a><a href=\"/droite\"><svg viewBox=\"0 0 100 100\">" "<path d=\"M 0 12 C 133 -49 133 149 0 88 C 17 64 17 36 0 12\" fill=\"#cfc\"/>" "<path d=\"M 35 35 L 75 50 L 35 65\"/>" "</svg></a>" "<br>" "<a href=\"/recule\"><svg viewBox=\"0 0 100 100\">" "<path d=\"M 12 0 C 36 17 64 17 88 0 C 149 133 -49 133 12 0\" fill=\"#cfc\"/>" "<path d=\"M 35 35 L 50 75 L 65 35\"/>" "</svg></a>" "</div>" "</body>" "</html>\r\n"; client.print(html); delay(100); Serial.println("Client déconnecté\n"); }