Skip to content

Commit

Permalink
update library
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefferson-Lopes committed Oct 26, 2023
1 parent 6f0b582 commit e6b6c4f
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 24 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Embedded system software CHANGELOG
# Firmware CHANGELOG

## v4.1.0
* multipurpose battery task
* fix bad int in speed calculation
* fix unintended double read on RPM interrupt
* add AV to this repo
* add battery level to AV

## v4.0.0
* move common_libs into the same repo
* add AFV to ECU Box
* add AV to ECU Box

## v3.1.0
* containerized tasks
Expand Down
4 changes: 2 additions & 2 deletions libs/library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "common_libs",
"version": "0.2.2",
"name": "libs",
"version": "1.2.2",
"description": "common libs for the Parahybaja's embedded system",
"keywords": ["esp32", "Parahybaja", "embedded_system"],
"authors": [
Expand Down
6 changes: 3 additions & 3 deletions libs/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
* @file definitions.h
* @author Jefferson Lopes ([email protected])
* @brief system's general types definitions and basic esp-now communication functions
* @version 1.0
* @date 2023-02-10
* @version 1.1
* @date 2023-10-26
*
* @copyright Copyright (c) 2023
*
* Version Modified By Date Comments
* ------- ------------- ---------- -----------
* 0.1.0 Jefferson L. 10/02/2023 first version
* 1.0.0 Jefferson L. 18/07/2023 move common_libs and rename a few modules
* 1.1.0 Jefferson L. 26/10/2023 remove Wire begin
*/

#ifndef __SYSTEM_H__
Expand Down Expand Up @@ -172,7 +173,6 @@ void init_system(void) {
Serial.begin(SERIAL_FREQ);
while (!Serial) {
}; // wait until is initialized
Wire.begin();
}

void init_espnow(void) {
Expand Down
36 changes: 29 additions & 7 deletions libs/task/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
* @file task_battery.h
* @author Jefferson Lopes ([email protected])
* @brief battery task, functions and configs
* @version 0.3
* @date 2023-02-20
* @version 1.3
* @date 2023-10-26
*
* @copyright Copyright (c) 2023
*
* Version Modified By Date Comments
* ------- ------------- ---------- -----------
* 1.3.0 Jefferson L. 26/10/2023 add queue and espnow option
*/

#ifndef __BATTERY_H__
Expand Down Expand Up @@ -45,12 +48,26 @@ void task_battery(void *arg){

battery_config_t* battery_config = (battery_config_t*)arg;

bool all_zeros = false;
uint8_t count;
float R1 = battery_config->R1;
float R2 = battery_config->R2;
uint8_t mac[6];
memcpy(mac, battery_config->mac, sizeof(mac));


// Loop through the array
for (int i = 0; i < 6; i++) {
if (mac[i] == 0) {
count++;
}
}

if (count == 6) {
all_zeros = true;
} else {
all_zeros = false;
}

// -----create local variables-----
uint32_t sum;
uint16_t adc_read;
Expand Down Expand Up @@ -87,8 +104,7 @@ void task_battery(void *arg){
// -----calculate voltage-----
voltage_read = (ADC_VOLTAGE * adc_read) / ADC_RESOLUTION;
voltage_bat = voltage_read / (R2 / (R1 + R2));
//bat.value = voltage_bat;
bat.value = 3.9;
bat.value = voltage_bat;

// -----convert to percent-----
#if (AS_PERCENT)
Expand All @@ -100,8 +116,14 @@ void task_battery(void *arg){
bat.value = ((bat.value - BAT_MIN) / (BAT_MAX - BAT_MIN)) * 100.0;
#endif

// -----send system data through esp-now-----
esp_now_send(mac, (uint8_t *) &bat, sizeof(sensor_t));
if(all_zeros) {
// -----send tilt data through queue-----
xQueueSend(qh_battery, &bat, pdMS_TO_TICKS(0));
}
else {
// -----send system data through esp-now-----
esp_now_send(mac, (uint8_t *) &bat, sizeof(sensor_t));
}

vTaskDelay(TASK_BATTERY_RATE_ms / portTICK_PERIOD_MS);
}
Expand Down
43 changes: 36 additions & 7 deletions libs/task/rollover.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
* @file task_rollover.h
* @author Jefferson Lopes ([email protected])
* @brief accelerometer task, functions and configs
* @version 0.2
* @date 2023-02-23
* @version 1.2
* @date 2023-10-26
*
* @copyright Copyright (c) 2023
*
* Version Modified By Date Comments
* ------- ------------- ---------- -----------
* 1.2.0 Jefferson L. 26/10/2023 add MPU calibration
*/

#ifndef __ROLLOVER_H__
Expand All @@ -32,9 +35,14 @@
* sensi = [16384,8192,4096,2048] bit/gravity
*/

// -----MPU6050 configs-----
float gyro_offset[] = {12.25, 1.92, 1.96};
float acc_offset[] = {-0.223, 0.028, -0.012};
// -----MPU offset-----
#define CALIB_ACC_X 0.531088 // usada para definir o zero do eixo x
#define CALIB_ACC_Y 0.045418 // usada para definir o zero do eixo y
#define CALIB_ACC_Z -0.308320 // usada para definir o zero do eixo z
#define CALIB_GYRO_X -1.591225 // usada para definir o zero do eixo x
#define CALIB_GYRO_Y -0.218293 // usada para definir o zero do eixo y
#define CALIB_GYRO_Z 0.441586 // usada para definir o zero do eixo z
#define CALIBRATE false

/**
* @brief MPU6050 rollover sensor task
Expand All @@ -57,6 +65,8 @@ void task_rollover(void *arg){
sensor_t temp = {AMBIENT_TEMP, 0.0};
MPU6050 mpu(Wire, MPU_ADDR);

Wire.begin(5, 18); // hot fix for GPIO burnout

#if DEBUG_MODE
// see the remaining space of this task
// always after create the variables
Expand All @@ -80,8 +90,27 @@ void task_rollover(void *arg){
} // stop everything if could not connect to MPU6050
log_i("Connected to MPU6050");

mpu.setGyroOffsets(gyro_offset[0], gyro_offset[1], gyro_offset[2]);
mpu.setAccOffsets(acc_offset[0], acc_offset[1], acc_offset[2]);
if (CALIBRATE) {
log_w("Calculating offsets, do not move MPU6050");
delay(1000);
mpu.calcOffsets(true, true); // gyro and accelero
log_w("Done!");
}
else {
log_w("Setting offsets");
mpu.setAccOffsets(CALIB_ACC_X, CALIB_ACC_Y, CALIB_ACC_Z);
mpu.setGyroOffsets(CALIB_GYRO_X, CALIB_GYRO_Y, CALIB_GYRO_Z);
}

log_d("offset acc: %f, %f, %f",
mpu.getAccXoffset(),
mpu.getAccYoffset(),
mpu.getAccZoffset());

log_d("offset gyro: %f, %f, %f",
mpu.getGyroXoffset(),
mpu.getGyroYoffset(),
mpu.getGyroZoffset());

// -----update timer-----
timer_send = millis();
Expand Down
9 changes: 6 additions & 3 deletions libs/task/speedometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
* @file task_speed.h
* @author Jefferson Lopes ([email protected])
* @brief
* @version 0.2
* @date 2023-02-19
* @version 0.3
* @date 2023-10-26
*
* @copyright Copyright (c) 2023
*
* Version Modified By Date Comments
* ------- ------------- ---------- -----------
* 0.3.0 Jefferson L. 26/10/2023 fix speed calculation
*/

#ifndef __SPEEDOMETER_H__
Expand Down Expand Up @@ -90,7 +93,7 @@ void task_speedometer(void *arg){
interrupts();

// -----calculate-----
float meters = (counter_spdmt_copy / WHEEL_EDGES) * WHEEL_CIRC;
float meters = (counter_spdmt_copy / float(WHEEL_EDGES)) * WHEEL_CIRC;
spdmt.value = meters / TASK_SPDMT_SEND_RATE_s; // in meter/second
spdmt.value *= ms2kmh;

Expand Down

0 comments on commit e6b6c4f

Please sign in to comment.