Compare commits
2 Commits
7f2af55e02
...
37b1b75d5f
Author | SHA1 | Date | |
---|---|---|---|
37b1b75d5f | |||
0ad8474d94 |
@ -4,6 +4,7 @@
|
||||
#include <math.h>
|
||||
|
||||
#include "Communication_chassis.h"
|
||||
#include "Communication_detection_adversaire.h"
|
||||
#include "ServerWeb.h"
|
||||
|
||||
|
||||
@ -107,6 +108,16 @@ void setup() {
|
||||
//}
|
||||
// MemPosition_X = 800;
|
||||
// MemPosition_Y = 800;
|
||||
struct detect_adv_reception_t detect_adv_reception;
|
||||
|
||||
while(1){
|
||||
Detect_adv_lire(&detect_adv_reception);
|
||||
char chaine[40];
|
||||
sprintf(chaine, "Distance: %d cm\n Distance: %d cm\n", detect_adv_reception.distance_cm[0],
|
||||
detect_adv_reception.distance_cm[11]);
|
||||
affiche_msg("Scan_Detect_adversaire", chaine);
|
||||
}
|
||||
|
||||
affichage_standard_init();
|
||||
|
||||
//M5.Lcd.setCursor(10, 200);M5.Lcd.print("cmd :");
|
||||
|
20
Cerveau/Communication_chassis.h
Normal file
20
Cerveau/Communication_chassis.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef CHASSIS_H
|
||||
#define CHASSSI_H
|
||||
|
||||
#define I2C_SLAVE_chassi 0x55
|
||||
|
||||
struct chassis_reception_t {
|
||||
unsigned char status;
|
||||
};
|
||||
|
||||
struct chassis_emission_t {
|
||||
unsigned char status;
|
||||
int translation_x_mm, translation_y_mm, rotation_z_rad;
|
||||
int vitesse, acceleration;
|
||||
};
|
||||
|
||||
void Scan_chassis(struct chassis_reception_t * chassis_reception);
|
||||
void send_Chassis(struct chassis_emission_t * chassis_emission);
|
||||
void send_Chassis_RAZ(void);
|
||||
|
||||
#endif
|
61
Cerveau/Communication_chassis.ino
Normal file
61
Cerveau/Communication_chassis.ino
Normal file
@ -0,0 +1,61 @@
|
||||
//#include "Chassis.h"
|
||||
#include <Arduino.h>
|
||||
#include <HardwareSerial.h>
|
||||
|
||||
|
||||
/// @brief Lit l'état du chassis en I2C
|
||||
void Scan_chassis(struct chassis_reception_t * chassis_reception){
|
||||
unsigned char tampon2[14];
|
||||
//(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée)
|
||||
error = I2C_lire_registre(I2C_SLAVE_chassi, 0, tampon2, 12);
|
||||
if (error !=0){
|
||||
Err_Chassi_com =1;IndexErr = 2;
|
||||
affiche_erreur("Scan_Chassi", "Erreur I2C");
|
||||
while(1);
|
||||
}else{
|
||||
Serial.println("I2C OK");
|
||||
Err_Chassi_com =0;
|
||||
IndexErr = 0;
|
||||
|
||||
Mvt_finit = (MOUVEMENT_FINI == tampon2[0]);
|
||||
chassis_reception->status = tampon2[0];
|
||||
}
|
||||
}
|
||||
|
||||
void send_Chassis(struct chassis_emission_t * chassis_emission){
|
||||
//if(nbr_essai<=10){
|
||||
// Prévient le chassis d'un nouveau mouvement avec le 2eme bit du premier Octet
|
||||
Mot[0] = MOUVEMENT_EN_COURS;
|
||||
//y*=-1;
|
||||
//y = y*direction;
|
||||
Mot[1] = chassis_emission->translation_x_mm >>8;
|
||||
Mot[2] = chassis_emission->translation_x_mm;
|
||||
Mot[3] = chassis_emission->translation_y_mm >>8;
|
||||
Mot[4] = chassis_emission->translation_y_mm;
|
||||
//Serial.println(y);
|
||||
Mot[5] = chassis_emission->rotation_z_rad >>8;
|
||||
Mot[6] = chassis_emission->rotation_z_rad;
|
||||
Mot[7] = chassis_emission->vitesse >>8; Mot[8] = chassis_emission->vitesse;
|
||||
Mot[9] = chassis_emission->acceleration >>8;
|
||||
Mot[10] = chassis_emission->acceleration;
|
||||
|
||||
error = I2C_ecrire_registre(I2C_SLAVE_chassi, 0, Mot, 11);
|
||||
if (error !=0){Err_Cha_send =1; IndexErr = 5;}
|
||||
else{Err_Cha_send =0;IndexErr = 0;}
|
||||
if(error==0){ //si pas d'erreur de transmission alors RAZ des valeurs
|
||||
nbr_essai ++;
|
||||
cmd_chassi_x = 0;
|
||||
cmd_chassi_y = 0;
|
||||
Cmd_Angle = 0;
|
||||
vit = 0;
|
||||
acc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void send_Chassis_RAZ(){
|
||||
uint8_t RAZ_Message[11]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
error = I2C_ecrire_registre(I2C_SLAVE_chassi, 0, RAZ_Message, 11);
|
||||
}
|
12
Cerveau/Communication_detection_adversaire.h
Normal file
12
Cerveau/Communication_detection_adversaire.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef DETEC_ADV_H
|
||||
#define DETEC_ADV_H
|
||||
|
||||
#define I2C_SLAVE_detect_adv 0x18
|
||||
|
||||
struct detect_adv_reception_t {
|
||||
unsigned char distance_cm[12];
|
||||
};
|
||||
|
||||
void Detect_adv_lire(struct detect_adv_reception_t * detect_adv_reception);
|
||||
|
||||
#endif
|
18
Cerveau/Communication_detection_adversaire.ino
Normal file
18
Cerveau/Communication_detection_adversaire.ino
Normal file
@ -0,0 +1,18 @@
|
||||
//#include "Chassis.h"
|
||||
#include <Arduino.h>
|
||||
#include <HardwareSerial.h>
|
||||
|
||||
|
||||
/// @brief Lit les capteurs VL53L1X
|
||||
void Detect_adv_lire(struct detect_adv_reception_t * detect_adv_reception){
|
||||
unsigned char tampon2[14];
|
||||
//(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée)
|
||||
error = I2C_lire_registre(I2C_SLAVE_detect_adv, 0, detect_adv_reception->distance_cm, 12);
|
||||
if (error !=0){
|
||||
affiche_erreur("Scan_Detect_adversaire", "Erreur I2C");
|
||||
while(1);
|
||||
}else{
|
||||
Serial.println("I2C OK");
|
||||
|
||||
}
|
||||
}
|
@ -26,7 +26,9 @@ uint8_t I2C_lire_registre(int adresse_i2c, uint adresse_registre, unsigned char
|
||||
|
||||
WIRE.requestFrom(adresse_i2c, taille_donnees + 1);
|
||||
// ceci contient l'adresse
|
||||
Wire.readBytes(&temp, 1);
|
||||
if(adresse_i2c == I2C_SLAVE_chassi){
|
||||
Wire.readBytes(&temp, 1);
|
||||
}
|
||||
// Et ceci les données
|
||||
Wire.readBytes(donnees_recues, taille_donnees);
|
||||
return status;
|
||||
|
9
Cerveau/ServerWeb.h
Normal file
9
Cerveau/ServerWeb.h
Normal file
@ -0,0 +1,9 @@
|
||||
#define WEB_DEPLACEMENT_RELATIF 1
|
||||
#define WEB_DEPLACEMENT_ABSOLU 2
|
||||
|
||||
void Web_init(void);
|
||||
bool Web_nouveau_message(void);
|
||||
int Web_type_requete(void);
|
||||
void Web_gestion(void);
|
||||
struct chassis_emission_t Web_get_donnees(void);
|
||||
|
101
Cerveau/ServerWeb.ino
Normal file
101
Cerveau/ServerWeb.ino
Normal file
@ -0,0 +1,101 @@
|
||||
#include <Arduino.h>
|
||||
#include <WebServer.h>
|
||||
|
||||
//#include "Chassis.h"
|
||||
//#include "ServerWeb.h"
|
||||
|
||||
int Web_nouvelle_entree;
|
||||
int type_requete;
|
||||
|
||||
struct chassis_emission_t chassis_emission_web;
|
||||
|
||||
#define FORM \
|
||||
"<!DOCTYPE html>\n" \
|
||||
"<html>\n" \
|
||||
"<head>\n" \
|
||||
"<meta charset=\"UTF-8\">\n" \
|
||||
"<title>A simple form</title>\n" \
|
||||
"</head>\n" \
|
||||
"<body>\n" \
|
||||
"<form action=\"/form\" method=\"post\">\n" \
|
||||
"<br>" \
|
||||
"<label for=\"X\">X : en mm</label>\n" \
|
||||
"<br>" \
|
||||
"<input type=\"text\" id=\"X\" name=\"X\">\n" \
|
||||
"<br>" \
|
||||
"<label for=\"Y\">Y : en mm</label>\n" \
|
||||
"<br>" \
|
||||
"<input type=\"text\" id=\"Y\" name=\"Y\">\n" \
|
||||
"<br>" \
|
||||
"<label for=\"R\">Rotation : en degres</label>\n" \
|
||||
"<br>" \
|
||||
"<input type=\"text\" id=\"R\" name=\"R\">\n" \
|
||||
"<br>" \
|
||||
"<label for=\"V\">Vitesse : </label>\n" \
|
||||
"<br>" \
|
||||
"<input type=\"text\" id=\"V\" name=\"V\" value=\"2000\">\n" \
|
||||
"<br>" \
|
||||
"<br>" \
|
||||
"<label for=\"A\">Accel : </label>\n" \
|
||||
"<br>" \
|
||||
"<input type=\"text\" id=\"A\" name=\"A\"value=\"1500\">\n" \
|
||||
"<br>" \
|
||||
"<br>" \
|
||||
"<input type=\"submit\" value=\" Vas-Y \">\n" \
|
||||
"<br>" \
|
||||
"<br>" \
|
||||
"<input type=\"reset\" value=\"Reset\">\n" \
|
||||
"<br>" \
|
||||
"<br>" \
|
||||
"<input type=\"submit\" value=\" STOP \">\n" \
|
||||
"</form>\n" \
|
||||
"</body>\n" \
|
||||
"</html>\n"
|
||||
|
||||
WebServer server(80);
|
||||
|
||||
void Web_init(){
|
||||
server.begin();
|
||||
server.on("/form", handleForm);
|
||||
}
|
||||
|
||||
bool Web_nouveau_message(){
|
||||
if(Web_nouvelle_entree){
|
||||
Web_nouvelle_entree = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Web_type_requete(){
|
||||
return type_requete;
|
||||
}
|
||||
|
||||
void Web_gestion(){
|
||||
server.handleClient();
|
||||
}
|
||||
|
||||
struct chassis_emission_t Web_get_donnees(){
|
||||
return chassis_emission_web;
|
||||
}
|
||||
|
||||
void handleForm() {
|
||||
String message;
|
||||
type_requete = WEB_DEPLACEMENT_RELATIF;
|
||||
message += FORM;
|
||||
server.send(200, "text/html", message);
|
||||
String myString0 = server.arg("X"); //positon de cmd en X mm
|
||||
// x= myString0.toInt() * coef_mvt/10;
|
||||
chassis_emission_web.translation_x_mm = myString0.toInt();
|
||||
String myString1 = server.arg("Y"); //positon de cmd en Y mm
|
||||
// y= myString1.toInt() * coef_mvt/10;
|
||||
chassis_emission_web.translation_y_mm = myString1.toInt();
|
||||
String myString2 = server.arg("R"); //positon de cmd en Rotation Deg °
|
||||
chassis_emission_web.rotation_z_rad = myString2.toInt() * 13.88888;
|
||||
String myString3 = server.arg("V"); // Vitesse de cmd en
|
||||
chassis_emission_web.vitesse = myString3.toInt();
|
||||
String myString4 = server.arg("A"); // Acceleration de cmd
|
||||
chassis_emission_web.acceleration = myString4.toInt();
|
||||
Web_nouvelle_entree=1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user