First commit

This commit is contained in:
Mauricio GM 2024-07-30 11:59:11 -06:00
commit 59691b660a
14 changed files with 738 additions and 0 deletions

5
PyroBot-Bombero/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

10
PyroBot-Bombero/.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

View File

@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

View File

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

View File

@ -0,0 +1,16 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
madhephaestus/ESP32Servo@^3.0.5

View File

@ -0,0 +1,329 @@
#include <Arduino.h>
#include <esp_now.h>
#include <WiFi.h>
#include <ESP32Servo.h>
#define SIGNAL_TIMEOUT 1000 // Tiempo de espera de la señal en mili segundos, reiniciar los datos si no hay señal
unsigned long lastRecvTime = 0;
#define SERVO_X_PIN 17 // Pin servo motor 1
#define SERVO_Y_PIN 16 // Pin servo motor 2
#define SERVO_A_PIN 18 // Pin servo motor 3
Servo xServo; // Crear un objeto/control servo 1
Servo yServo; // Crear un objeto/control servo 2
Servo aServo; // Crear un objeto/control servo 2
uint8_t posx = 90; // Pin pos eje x
uint8_t posy = 90; // Pin pos eje y
uint8_t posyr = 0; // Pin pos eje y (compensar)
uint8_t posa = 1; // Pin pos altura
int humo = 13;
int buss = 12;
int rojo = 25;
int verde = 26;
int azul = 27;
int m11 = 33;
int m12 = 32;
int m21 = 21;
int m22 = 19;
int mod = 0;
int modold = 0;
int modnew;
uint8_t broadcastAddress[] = {0xB0, 0xA7, 0x32, 0x22, 0x7D, 0x6C}; //B0:A7:32:22:7D:6C - Direccion MAC del Control
// Estructura para enviar datos
// Debe coincidir la esctructura del emisor
typedef struct struct_message {
int lxAxisValue;
int lyAxisValue;
int rxAxisValue;
int ryAxisValue;
int switch1Value;
int switch2Value;
int switch3Value;
int switch4Value;
int switch5Value;
int switch6Value;
int sensorhumo;
int conexion;
int m;
int d;
} struct_message;
struct_message data;
// Llamada de funicion para recibir y enviar datos
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
if (status == ESP_NOW_SEND_FAIL)
{
digitalWrite(rojo,255);
digitalWrite(verde,0);
digitalWrite(azul,0);
digitalWrite(m11,LOW);
digitalWrite(m12,LOW);
digitalWrite(m21,LOW);
digitalWrite(m22,LOW);
digitalWrite(buss,LOW);
}
else{
digitalWrite(rojo,0);
digitalWrite(verde,255);
digitalWrite(azul,0);
}
Serial.print("\r\nMaster packet sent:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}
void setInputDefaultValues()
{
data.switch1Value = LOW;
data.switch2Value = LOW;
data.switch3Value = LOW;
data.switch4Value = LOW;
data.switch5Value = LOW;
data.switch6Value = LOW;
digitalWrite(m11,LOW);
digitalWrite(m12,LOW);
digitalWrite(m21,LOW);
digitalWrite(m22,LOW);
}
void mapAndWriteValues()
{
//xServo.write(map(data.lxAxisValue, 126, 0, 0, 180));
//yServo.write(map(data.ryAxisValue, 126, 0, 0, 180));
uint8_t LStickX = data.lxAxisValue + 128;
uint8_t RStickY = data.ryAxisValue + 128;
uint8_t LStickY = data.lyAxisValue + 128;
uint8_t RStickX = data.rxAxisValue + 128;
uint8_t up = data.switch4Value;
uint8_t down = data.switch3Value;
modnew = data.switch1Value;
//Seleccion de modo
if((modnew == 1) && (modold == 0) ){
if (mod == 0){
mod = 1;
}
else{
mod = 0;
}
}
if ((data.lxAxisValue) || (data.ryAxisValue) || (data.switch3Value) || (data.switch4Value) || (data.lyAxisValue) || (data.rxAxisValue)) {
if ((LStickX < 135 && LStickX <= 255 && posx < 150) && (mod == 1) ) {
posx++;
}
if ((LStickX > 200 && posx > 30) && (mod == 1) ) {
posx--;
}
if ((RStickY < 135 && RStickY <= 255 && posy < 130 && posa < 30) && (mod == 1) ) {
posy++;
}
if ((RStickY < 135 && RStickY <= 255 && posy < 181 && posa > 30) && (mod == 1) ) {
posy++;
}
if ((RStickY > 200 && posy > 30) && (mod == 1) ) {
posy--;
}
if ((up == 1 && posa < 80) && (mod == 1) ) {
posa++;
}
if ((down == 1 && posa >= 1) && (mod == 1) ) {
posa--;
}
if ((RStickX < 135 && RStickX <= 255) && (mod == 0) ) {
digitalWrite(m11,LOW);
digitalWrite(m12,HIGH);
digitalWrite(m21,HIGH);
digitalWrite(m22,LOW);
Serial.println("Izquierda");
}
if ((RStickX > 200) && (mod == 0) ) {
digitalWrite(m11,HIGH);
digitalWrite(m12,LOW);
digitalWrite(m21,LOW);
digitalWrite(m22,HIGH);
Serial.println("Derecha");
}
if ((LStickY < 135 && LStickY <= 255) && (mod == 0) ) {
digitalWrite(m11,LOW);
digitalWrite(m12,HIGH);
digitalWrite(m21,LOW);
digitalWrite(m22,HIGH);
Serial.println("Atras");
}
if ((LStickY > 200) && (mod == 0) ) {
digitalWrite(m11,HIGH);
digitalWrite(m12,LOW);
digitalWrite(m21,HIGH);
digitalWrite(m22,LOW);
Serial.println("Avanzar");
}
if ((LStickY < 200 && LStickY > 130) && (RStickX < 200 && RStickX > 130) && (mod == 0) ){
digitalWrite(m11,LOW);
digitalWrite(m12,LOW);
digitalWrite(m21,LOW);
digitalWrite(m22,LOW);
digitalWrite(buss,LOW);
}
}
if((posy > 130 && posa < 30) && (mod == 1) ){
posyr = posy-130;
posy = posy - posyr;
yServo.write(posy);
}
if((mod == 1) ){
yServo.write(posy);
xServo.write(posx);
aServo.write(posa);
}
/*
char inputValuesString[100];
sprintf(inputValuesString,
"%3d,%3d,%3d,%3d,%3d,%3d,%3d",
posx,
posy,
posa,
LStickX,
RStickY,
up,
down);
Serial.println(inputValuesString);
*/
//digitalWrite(led1, data.switch1Value);
/*
digitalWrite(rojo,255);
digitalWrite(verde,255);
digitalWrite(azul,255);
*/
}
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&data, incomingData, sizeof(data));
mapAndWriteValues();
lastRecvTime = millis();
/*
Serial.print("\r\nBytes recibidos: ");
Serial.println(len);
Serial.print("From slave: ");
char inputValuesString[100];
sprintf(inputValuesString,
"%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d",
data.lxAxisValue,
data.lyAxisValue,
data.rxAxisValue,
data.ryAxisValue,
data.switch1Value,
data.switch2Value,
data.switch3Value,
data.switch4Value,
data.switch5Value,
data.switch6Value);
Serial.println(inputValuesString);
*/
}
void setUpPinModes()
{
xServo.attach(SERVO_X_PIN); // Declarar pin del servo 1
yServo.attach(SERVO_Y_PIN); // Declarar pin del servo 2
aServo.attach(SERVO_A_PIN); // Declarar pin del servo 2
pinMode(humo, OUTPUT);
pinMode(buss, OUTPUT);
pinMode(rojo, OUTPUT);
pinMode(verde, OUTPUT);
pinMode(azul, OUTPUT);
pinMode(m11, OUTPUT);
pinMode(m12, OUTPUT);
pinMode(m21, OUTPUT);
pinMode(m22, OUTPUT);
setInputDefaultValues();
mapAndWriteValues();
}
void setup() {
setUpPinModes();
Serial.begin(115200);
// Configurar placa como estacion de red WI-FI
WiFi.mode(WIFI_STA);
// Inicia ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println(F("Error initializing ESP-NOW"));
return;
}
Serial.print(F("Transceiver initialized : "));
Serial.println(WiFi.macAddress());
// Definiir funciones de llamda
esp_now_register_send_cb(OnDataSent);
esp_now_register_recv_cb(OnDataRecv);
// Registrar peer
esp_now_peer_info_t peerInfo;
memset(&peerInfo, 0, sizeof(peerInfo));
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
// Añadir peer
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
Serial.println(F("Failed to add peer"));
return;
}
}
void loop() {
modold=modnew;
//Checar si la señal se pierde
unsigned long now = millis();
if ( now - lastRecvTime > SIGNAL_TIMEOUT )
{
setInputDefaultValues();
mapAndWriteValues();
}
// Establecer valores para enviar
data.sensorhumo = 10;
data.conexion = 1;
data.m = 0;
data.d = 1;
// Enviar mensajes via ESP-NOW
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &data, sizeof(data));
delay(10);
//Codigo Sensor de humo/gas
if (data.sensorhumo >= 1220) {
digitalWrite(humo, HIGH);
} else {
digitalWrite(humo,LOW);
}
}

View File

@ -0,0 +1,11 @@
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html

5
PyroBot-Control/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

10
PyroBot-Control/.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

View File

@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

View File

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

View File

@ -0,0 +1,14 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino

View File

@ -0,0 +1,157 @@
#include <Arduino.h>
#include <esp_now.h>
#include <WiFi.h>
uint8_t broadcastAddress[] = {0xB0, 0xA7, 0x32, 0x22, 0x60, 0x98}; // B0:A7:32:22:60:98
int con = 25;
int gas = 26;
int modm = 2;
int modd = 4;
// Estructura para enviar datos
// Debe coincidir la estructura del receptor
typedef struct struct_message {
int lxAxisValue;
int lyAxisValue;
int rxAxisValue;
int ryAxisValue;
int switch1Value;
int switch2Value;
int switch3Value;
int switch4Value;
int switch5Value;
int switch6Value;
int sensorhumo;
int conexion;
int m;
int d;
} struct_message;
struct_message data;
int mapAndAdjustJoystickDeadBandValues(int value, bool reverse)
{
if (value >= 2200)
{
value = map(value, 2200, 4095, 63, 126);
}
else if (value <= 1800)
{
value = (value == 0 ? 0 : map(value, 1800, 0, 63, 0));
}
else
{
value = 63;
}
if (reverse)
{
value = 126 - value;
}
return value;
}
// Llamada de funcion para recibir y enviar datos
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
if (status == ESP_NOW_SEND_FAIL)
{
digitalWrite(con, LOW);
digitalWrite(modd, LOW);
digitalWrite(modm, LOW);
digitalWrite(gas,LOW);
}
Serial.print("\r\nMaster packet sent:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail" );
}
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&data, incomingData, sizeof(data));
Serial.print("\r\nBytes recibidos: ");
Serial.println(len);
Serial.print("From slave: ");
char inputValuesString[100];
sprintf(inputValuesString,
"%3d,%3d,%3d,%3d",
data.sensorhumo,
data.conexion,
data.m,
data.d);
Serial.println(inputValuesString);
if (data.conexion == 1) {
digitalWrite(con, HIGH);
}
if (data.d == 1) {
digitalWrite(modd, HIGH);
}
if (data.sensorhumo >= 1220) {
digitalWrite(gas, HIGH);
delay(100);
digitalWrite(gas, LOW);
delay(100);
} else {
digitalWrite(gas,LOW);
}
}
void setup() {
Serial.begin(115200);
pinMode(gas, OUTPUT);
pinMode(con, OUTPUT);
pinMode(modm, OUTPUT);
pinMode(modd, OUTPUT);
// Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
// Iniciar ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println(F("Error initializing ESP-NOW"));
return;
}
Serial.print(F("Transceiver initialized : "));
Serial.println(WiFi.macAddress());
// Definir funciones de llamada
esp_now_register_send_cb(OnDataSent);
esp_now_register_recv_cb(OnDataRecv);
// Registrar peer
esp_now_peer_info_t peerInfo;
memset(&peerInfo, 0, sizeof(peerInfo));
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
// Añadir peer
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
Serial.println(F("Failed to add peer"));
return;
}
pinMode(15,INPUT_PULLUP);
pinMode(16,INPUT_PULLUP);
pinMode(17,INPUT_PULLUP);
pinMode(18,INPUT_PULLUP);
pinMode(19,INPUT_PULLUP);
pinMode(21,INPUT_PULLUP);
}
void loop() {
// Establecer valores para enviar
data.lxAxisValue = mapAndAdjustJoystickDeadBandValues(analogRead(32), false);
data.lyAxisValue = mapAndAdjustJoystickDeadBandValues(analogRead(33), false);
data.rxAxisValue = mapAndAdjustJoystickDeadBandValues(analogRead(34), false);
data.ryAxisValue = mapAndAdjustJoystickDeadBandValues(analogRead(35), false);
data.switch1Value = !digitalRead(15);
data.switch2Value = !digitalRead(16);
data.switch3Value = !digitalRead(17);
data.switch4Value = !digitalRead(18);
data.switch5Value = !digitalRead(19);
data.switch6Value = !digitalRead(21);
// Mandar mensajes via ESP-NOW
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &data, sizeof(data));
delay(10);
}

View File

@ -0,0 +1,11 @@
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html