Skip to content
Open

a #2

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions BREDA-main/BREDA-main/BREDA/Almacenamiento.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void SD_file_open()

file_select_name();
String newName = String(file_number) + file_data_name;
String newName2 = String(file_number) + file_pressure_name;

Serial.println("Abriendo archivo...");
if (!file_data.open(newName.c_str(), O_RDWR | O_CREAT))
Expand Down Expand Up @@ -72,6 +73,8 @@ void SD_file_open()
RB_data.begin(&file_data);
Serial.println("RingBuf iniciado");
// ...

// el archivo de presión no lo necesitamos, en cualquier caso sería lo mismo que el de datos normales pero con sus propias variables
#endif
}

Expand Down Expand Up @@ -110,18 +113,23 @@ void SD_file_data_update()

// Cell data
RB_data.print(", ");
RB_data.print(thrust, 5);
RB_data.print(thrust, DEC); // DEC == 10, base decimal

// Transducer data (Average)
RB_data.print(", ");
/*
if (transducer_counter > 0)
{
RB_data.print(transducer_avg / transducer_counter, 5);
}
else
{
RB_data.print(0.0, 5);
}
}*/

// Transducer data (NO Average)
RB_data.print(", ");
RB_data.print(pressure, DEC); // la función print con ints determina base, no decimales

transducer_avg = 0;
transducer_counter = 0;

Expand All @@ -131,7 +139,7 @@ void SD_file_data_update()
RB_data.print(tempADC[i]);
}

for (int i = 0; i < 14; ++i)
for (int i = 0; i < 9; ++i)
{
RB_data.print(", ");
RB_data.print(tempTP[i]);
Expand Down
16 changes: 13 additions & 3 deletions BREDA-main/BREDA-main/BREDA/BREDA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void setup()

ADC_config(ADC1, false);
ADC_config(ADC2, false);
ADC_config(ADC3, false);
ADC_config(ADC3, true);
ADC_config(ADC4, true);

performance_started();
Expand All @@ -143,19 +143,24 @@ void loop()
if (RB_data.bytesUsed() >= 512 && !file_data.isBusy())
{
RB_data.writeOut(512);
flush_counter++;
}

#if TRANSDUCER == 1
if (RB_pressure.bytesUsed() >= 512 && !file_pressure.isBusy())
{
RB_pressure.writeOut(512);
flush_counter++;
}
#endif

if (++flush_counter >= 5000)
if (flush_counter >= 100)
{
flush_counter = 0;
file_data.flush();
digitalWrite(PIN_LED_RED, HIGH);
LED2_status = true;
LED2_millis = millis();
#if TRANSDUCER == 1
file_pressure.flush();
#endif
Expand Down Expand Up @@ -186,10 +191,15 @@ void loop()
}

// Turns on and off the led each second
if (millis() > LED_time + LED_timer)
if (millis() > (LED_time + LED_timer))
{
LED_time = millis();
LED_status = !LED_status;
digitalWrite(PIN_LED_GREEN, LED_status);
}
if ((millis() > (LED2_millis + LED_timer)) && LED2_status)
{
LED2_status = false;
digitalWrite(PIN_LED_RED, LOW);
}
}
8 changes: 6 additions & 2 deletions BREDA-main/BREDA-main/BREDA/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ uint32_t serial_timer = 1000;
uint32_t transducer_timer = 200;
uint32_t transducer_timerOffset = 0;
uint32_t LED_timer = 500;
unsigned long LED2_millis;
bool LED2_status = false;

// Performance
bool performance_status = false;
Expand Down Expand Up @@ -128,10 +130,11 @@ const float TP_const = ((vref / int24max) * 1000000) / 4; // constante para esca
volatile float tempTP[14] = {0}; // array que almacena las temperaturas de los termopares
volatile int32_t tempTP_raw[14] = {0}; // array que almacena las temperaturas de los termopares
volatile float tempADC[4] = {0}; // array que almacena las temperaturas de los ADC
volatile float thrust = 0; // almacena el valor del empuje
volatile int32_t thrust = 0; // almacena el valor del empuje
volatile int32_t prev_thrust = 1; // almacena el valor del empuje anterior

// File
String general_file_header = "Time, Thrust, Pressure, ADC1_Temp, ADC2_Temp, ADC3_Temp, ADC4_Temp, TP_1, TP_2, TP_3, TP_4, TP_5, TP_6, TP_7, TP_8, TP_9, TP_10, TP_11, TP_12, TP_13, TP_14";
String general_file_header = "Time, Thrust, Pressure, ADC1_Temp, ADC2_Temp, ADC3_Temp, ADC4_Temp, TP_1, TP_2, TP_3, TP_4, TP_5, TP_6, TP_7, TP_8, TP_9";
String pressure_file_header = "Time, Chamber_Pressure, Raw_Transducer";
uint8_t file_number = 0;

Expand All @@ -158,6 +161,7 @@ volatile uint32_t transducer_counter_offset = 0;
volatile uint32_t transducer_freq = 0;

volatile int16_t transducer_raw = 0;
volatile int16_t pressure = 0;
volatile float transducer_avg = 0;
volatile float transducer_pressure = 0;

Expand Down
26 changes: 13 additions & 13 deletions BREDA-main/BREDA-main/BREDA/Funciones.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,25 @@ void send_sensor_data()

// Timestamp en milisegundos (4 bytes - uint32_t)
uint32_t timestamp = millis();
memcpy(&buffer[idx], &timestamp, 4);
idx += 4;
memcpy(&buffer[idx], &timestamp, sizeof(timestamp));
idx += sizeof(timestamp);

// Thrust/Empuje (2 bytes - multiplicar × 100 para 2 decimales)
int16_t thrust_int = (int16_t)(thrust * 100.0f);
memcpy(&buffer[idx], &thrust_int, 2);
idx += 2;
// Thrust/Empuje (4 bytes - multiplicar × 100 para 2 decimales)
int32_t thrust_int = (int32_t)(thrust * 100.0f);
memcpy(&buffer[idx], &thrust_int, sizeof(thrust_int));
idx += sizeof(thrust_int);

// 10 Temperaturas de termopares (20 bytes - multiplicar × 100)
for (int i = 0; i < 10; i++)
// 9 Temperaturas de termopares (18 bytes - multiplicar × 100)
for (int i = 0; i < 9; i++)
{
int16_t temp_int = (int16_t)(tempTP[i] * 100.0f);
memcpy(&buffer[idx], &temp_int, 2);
idx += 2;
memcpy(&buffer[idx], &temp_int, sizeof(temp_int));
idx += sizeof(temp_int);
}

// Transductor raw (2 bytes - dato crudo del ADC)
memcpy(&buffer[idx], &transducer_raw, 2);
idx += 2;
// Transductor presión (2 bytes - dato crudo del ADC)
memcpy(&buffer[idx], &pressure, sizeof(pressure));
idx += sizeof(pressure);

interrupts();

Expand Down
23 changes: 17 additions & 6 deletions BREDA-main/BREDA-main/BREDA/Termopares.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ float TP_polynom(int32_t raw) {
// ADC Configuration
//-------------------------------------------------

void ADC_config(MCP3564& adc, bool ID_ADC4) {
void ADC_config(MCP3564& adc, bool especial) {
uint8_t conf[1];

// Configuro el registro 1 (Pag 92 de la data sheet)
if (ID_ADC4)
conf[0] = B00011000; // ADC4 tiene menos Oversampling porque no tiene tanta velocidad de reloj
if (especial)
conf[0] = B00011100; // ADC4 tiene menos Oversampling porque no tiene tanta velocidad de reloj
else
conf[0] = B00100000;
adc.writeReg(conf, MCP3564_ADR_CONFIG1);

// Configuro el registro 2 (Pag 93 de la data sheet)
conf[0] = B10011001;
conf[0] = B10011011;
adc.writeReg(conf, MCP3564_ADR_CONFIG2);

// Configuro el registro 3 (Pag 94 de la data sheet)
Expand All @@ -62,7 +62,7 @@ void ADC_config(MCP3564& adc, bool ID_ADC4) {

// Configuro el registro del modo SCAN (Pag 97 de la data sheet)
uint16_t channelMask = 0;
if (ID_ADC4)
if (especial)
channelMask = B00011011 << 8; // ADC4 no tiene el CH4-CH5 activado
else
channelMask = B00011111 << 8;
Expand Down Expand Up @@ -118,7 +118,7 @@ void ADC2_IRQ() { // declara la funcion de lectura del IRQ
tempTP_raw[chID + 4] = temp;
tempTP[chID + 4] = TP_polynom(temp) + tempADC[0];
}
}
}

void ADC3_IRQ() { // declara la funcion de lectura del IRQ

Expand All @@ -130,6 +130,15 @@ void ADC3_IRQ() { // declara la funcion de lectura del IRQ

if (chID == 4) // temperatura interna
tempADC[2] = internalTemp_const * vref * temp - 269.13; // guarda la temperatura del ADC1 en la posición primera del array
else if (chID == 1) { // celula de carga
temp = ((temp + 320.85) / 218.10) * 9.81;
if (prev_thrust != 0) {
thrust = int32_t((temp + prev_thrust) / 2);
}else {
thrust = temp;
}
prev_thrust = temp;
}
else
{
tempTP_raw[chID + 8] = temp;
Expand All @@ -147,8 +156,10 @@ void ADC4_IRQ() { // declara la funcion de lectura del IRQ

if (chID == 4) // temperatura interna
tempADC[3] = internalTemp_const * vref * temp - 269.13; // guarda la temperatura del ADC1 en la posición primera del array
/*
else if (chID == 3) // celula de carga
thrust = temp;
*/
else
{
tempTP_raw[chID + 12] = temp;
Expand Down
5 changes: 3 additions & 2 deletions BREDA-main/BREDA-main/BREDA/Transductor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ void transducer_measure()
++transducer_counter_offset;
}

transducer_pressure = (transducer_raw - transducer_offset) * transducer_const;

//transducer_pressure = (transducer_raw - transducer_offset) * transducer_const;
pressure = transducer_raw;

transducer_avg += transducer_pressure;
++transducer_counter;
++transducer_freq;
Expand Down
2 changes: 1 addition & 1 deletion BREDA-main/Esp_relay/ordenador/ordenador.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ERROR_PIN 13
#define BUFFER_SIZE 30

uint8_t relayMAC[] = {0x08, 0xD1, 0xF9, 0xCE, 0x16, 0x14}; // 08:d1:f9:ce:16:14
uint8_t relayMAC[] = {0xD4, 0xE9, 0xF4, 0xF9, 0x32, 0x18}; // d4:e9:f4:f9:32:18

typedef struct {
uint8_t sync1;
Expand Down
22 changes: 16 additions & 6 deletions BREDA-main/Esp_relay/relay/relay.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include <esp_now.h>
#include <WiFi.h>
#include <esp_wifi.h>
#include <esp_timer.h>
#include <esp_timer.h>

#define ERROR_PIN 13
#define PIN_IGNICION 33
#define COMANDO_IGNICION 0x04
#define IGNICION_DURACION_MS 5000

uint8_t ordenadorMAC[] = {0x94, 0xE6, 0x86, 0x44, 0x9E, 0xC4};
uint8_t ordenadorMAC[] = {0xD4, 0xE9, 0xF4, 0xFA, 0xA2, 0xF4};

typedef struct {
uint8_t sync1;
Expand All @@ -20,8 +21,10 @@ typedef struct {
} PacketComando;

PacketData paquete;
volatile bool paquete_listo = false;
volatile bool enviar_ahora = false;
volatile bool paquete_listo = false;
volatile bool enviar_ahora = false;
volatile bool ignicion_activa = false;
unsigned long ignicion_tiempo = 0;

void IRAM_ATTR timer_callback(void* arg) {
enviar_ahora = true;
Expand All @@ -41,6 +44,8 @@ void onDataRecv(const esp_now_recv_info *recv_info, const uint8_t *incomingData,

if (cmd.comando == COMANDO_IGNICION) {
digitalWrite(PIN_IGNICION, HIGH);
ignicion_activa = true;
ignicion_tiempo = millis();
} else {
Serial.write(cmd.comando);
}
Expand Down Expand Up @@ -79,10 +84,15 @@ void setup() {
};
esp_timer_handle_t timer_handle;
esp_timer_create(&timer_args, &timer_handle);
esp_timer_start_periodic(timer_handle, 12500);
esp_timer_start_periodic(timer_handle, 12500);
}

void loop() {
if (ignicion_activa && (millis() - ignicion_tiempo >= IGNICION_DURACION_MS)) {
digitalWrite(PIN_IGNICION, LOW);
ignicion_activa = false;
}

if (Serial.available() >= 2) {
uint8_t byte1 = Serial.read();

Expand Down Expand Up @@ -116,7 +126,7 @@ void loop() {

paquete.sync1 = 0xFE;
paquete.sync2 = 0xFB;
paquete_listo = true;
paquete_listo = true;
}

if (enviar_ahora) {
Expand Down