Hello everyone,
I am looking for someone who can help me create a logigram/organigram for the code I have developed for a bipedal robot. If you have experience in this area and are interested in assisting, please let me know. I am willing to compensate for your time and expertise.
Thank you!
Best regards,
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <Servo.h>
// Configuration Wi-Fi
const char* ssid = "BipedRobot"; // Nom du réseau Wi-Fi
const char* password = "password123"; // Mot de passe
// Serveur web
ESP8266WebServer server(80);
// Déclaration des servos
Servo servoRight, servoRight2, servoLeft, servoLeft2, servoMiddle, servoNuts;
// Interface HTML avec cases
String pageHTML = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
<title>Robot Control</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}
.controls {
display: grid;
grid-template-rows: 1fr 1fr 1fr 1fr 1fr;
grid-template-columns: 1fr 1fr 1fr;
gap: 40px;
}
button {
font-size: 60px;
width: 250px;
height: 250px;
border: none;
border-radius: 30px;
background-color: #007bff;
color: white;
cursor: pointer;
box-shadow: 0px 10px 15px rgba(0, 0, 0, 0.4);
}
button:hover {
background-color: #0056b3;
}
.btn-0 { grid-row: 2; grid-column: 2; }
.btn-1 { grid-row: 1; grid-column: 2; }
.btn-2 { grid-row: 2; grid-column: 3; }
.btn-3 { grid-row: 2; grid-column: 1; }
.btn-4 { grid-row: 3; grid-column: 2; }
</style>
</head>
<body>
<div class="controls">
<button class="btn-1" onclick="sendCommand('1')">Z</button>
<button class="btn-3" onclick="sendCommand('3')">Q</button>
<button class="btn-0" onclick="sendCommand('0')">S</button>
<button class="btn-2" onclick="sendCommand('2')">D</button>
<button class="btn-4" onclick="sendCommand('4')">N</button>
</div>
<script>
function sendCommand(command) {
fetch(`/${command}`).catch(err => console.error(err));
}
</script>
</body>
</html>
)rawliteral";
// Variables pour gérer l'état de la boucle MoveForward
bool moveForwardActive = false;
unsigned long motorRightStartTime = 0;
unsigned long motorRight2StartTime = 0;
unsigned long motorLeftStartTime = 0;
unsigned long motorLeft2StartTime = 0;
unsigned long pauseStartTime = 0;
bool motorRightRunning = false;
bool motorRight2Running = false;
bool motorLeftRunning = false;
bool motorLeft2Running = false;
bool inPause = false;
// Durées et vitesses des servos
const unsigned long durationRight = 940;
const unsigned long durationRight2 = 1000;
const unsigned long durationLeft = 750;
const unsigned long durationLeft2 = 750;
const int speedRight = 150;
const int speedRight2 = 150;
const int speedLeft = 30;
const int speedLeft2 = 30;
// Fonction pour gérer les actions
void handleCase(int caseNumber) {
switch(caseNumber) {
case 0:
moveForwardActive = false; // Désactiver le mouvement en avant
NeutralState();
break;
case 1:
moveForwardActive = true;
break;
case 2:
RightRotation();
break;
case 3:
LeftRotation();
break;
case 4:
RemoveNuts();
break;
default:
Serial.println("Case inconnue");
break;
}
server.send(200, "text/plain", "Commande exécutée : Case " + String(caseNumber));
}
// Fonction de position neutre
void NeutralState() {
// Neutral state : Servos à leur position neutre (90°)
servoRight.write(90);
servoRight2.write(90);
servoLeft.write(90);
servoLeft2.write(90);
servoMiddle.write(90);
servoNuts.write(90); // servoNuts à 90° pour le neutre
}
// Fonction pour avancer
void MoveForward() {
if (!moveForwardActive) return;
unsigned long currentMillis = millis();
if (!motorRightRunning && !motorRight2Running && !motorLeftRunning && !motorLeft2Running && !inPause) {
motorRightStartTime = motorRight2StartTime = motorLeftStartTime = motorLeft2StartTime = currentMillis;
motorRightRunning = motorRight2Running = motorLeftRunning = motorLeft2Running = true;
servoRight.write(speedRight);
servoRight2.write(speedRight2);
servoLeft.write(speedLeft);
servoLeft2.write(speedLeft2);
}
if (motorRightRunning && (currentMillis - motorRightStartTime >= durationRight)) {
servoRight.write(90);
motorRightRunning = false;
}
if (motorRight2Running && (currentMillis - motorRight2StartTime >= durationRight2)) {
servoRight2.write(90);
motorRight2Running = false;
}
if (motorLeftRunning && (currentMillis - motorLeftStartTime >= durationLeft)) {
servoLeft.write(90);
motorLeftRunning = false;
}
if (motorLeft2Running && (currentMillis - motorLeft2StartTime >= durationLeft2)) {
servoLeft2.write(90);
motorLeft2Running = false;
pauseStartTime = currentMillis;
inPause = true;
}
if (inPause && (currentMillis - pauseStartTime >= 3000)) {
inPause = false;
}
}
// Fonction pour la rotation à droite
void RightRotation() {
// RightRotation : Rotation à droite
servoMiddle.write(10); // Maintenir en position neutre
}
// Fonction pour la rotation à gauche
void LeftRotation() {
// LeftRotation : Rotation à gauche
servoMiddle.write(170);
}
// Fonction pour retirer les écrous
void RemoveNuts() {
// Déplacer le servo à 180°
servoNuts.write(180);
delay(5000); // Attendre 5 secondes
// Revenir à la position initiale (0°)
servoNuts.write(0);
delay(1000); // Attendre encore 1 seconde
// Indiquer que l'action est terminée
Serial.println("Action terminée. Appuyez sur 'N' pour recommencer.");
}
void setup() {
Serial.begin(115200);
// Initialiser les servos
servoRight.attach(D0);
servoRight2.attach(D1);
servoLeft.attach(D2);
servoLeft2.attach(D3);
servoMiddle.attach(D4);
servoNuts.attach(D5);
// Configurer les servos en position initiale
NeutralState(); // Mettre les servos en position neutre au démarrage
// Configurer l'ESP8266 comme point d'accès
WiFi.softAP(ssid, password);
Serial.println("Wi-Fi créé : " + String(ssid));
Serial.println("Adresse IP : " + WiFi.softAPIP().toString());
// Configurer les routes du serveur
server.on("/", []() {
server.send(200, "text/html", pageHTML);
});
server.on("/0", []() { handleCase(0); });
server.on("/1", []() { handleCase(1); });
server.on("/2", []() { handleCase(2); });
server.on("/3", []() { handleCase(3); });
server.on("/4", []() { handleCase(4); });
// Démarrer le serveur web
server.begin();
Serial.println("Serveur web démarré.");
}
void loop() {
server.handleClient();
MoveForward();
}