-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f0b582
commit e6b6c4f
Showing
6 changed files
with
85 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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__ | ||
|
@@ -172,7 +173,6 @@ void init_system(void) { | |
Serial.begin(SERIAL_FREQ); | ||
while (!Serial) { | ||
}; // wait until is initialized | ||
Wire.begin(); | ||
} | ||
|
||
void init_espnow(void) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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__ | ||
|
@@ -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; | ||
|
@@ -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) | ||
|
@@ -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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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__ | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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__ | ||
|
@@ -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; | ||
|
||
|