Răsfoiți Sursa

+ Updated core funcitonality

xnecas 5 zile în urmă
părinte
comite
61ac84e13c

+ 5 - 1
CMakeLists.txt

@@ -7,7 +7,11 @@ add_compile_definitions(
     ARDUINO_USB_CDC_ON_BOOT=1
 )
 
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error")
+
 include($ENV{IDF_PATH}/tools/cmake/project.cmake)
 # "Trim" the build. Include the minimal set of components, main, and anything it depends on.
 idf_build_set_property(MINIMAL_BUILD ON)
-project(bat-sense)
+
+project(bat-sense)

+ 11 - 52
README.md

@@ -1,53 +1,12 @@
-| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 | ESP32-S31 | Linux |
-| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- | --------- | ----- |
 
-# Hello World Example
-
-Starts a FreeRTOS task to print "Hello World".
-
-(See the README.md file in the upper level 'examples' directory for more information about examples.)
-
-## How to use example
-
-Follow detailed instructions provided specifically for this example.
-
-Select the instructions depending on Espressif chip installed on your development board:
-
-- [ESP32 Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/stable/get-started/index.html)
-- [ESP32-S2 Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/get-started/index.html)
-
-
-## Example folder contents
-
-The project **hello_world** contains one source file in C language [hello_world_main.c](main/hello_world_main.c). The file is located in folder [main](main).
-
-ESP-IDF projects are built using CMake. The project build configuration is contained in `CMakeLists.txt` files that provide set of directives and instructions describing the project's source files and targets (executable, library, or both).
-
-Below is short explanation of remaining files in the project folder.
-
-```
-├── CMakeLists.txt
-├── pytest_hello_world.py      Python script used for automated testing
-├── main
-│   ├── CMakeLists.txt
-│   └── hello_world_main.c
-└── README.md                  This is the file you are currently reading
-```
-
-For more information on structure and contents of ESP-IDF projects, please refer to Section [Build System](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html) of the ESP-IDF Programming Guide.
-
-## Troubleshooting
-
-* Program upload failure
-
-    * Hardware connection is not correct: run `idf.py -p PORT monitor`, and reboot your board to see if there are any output logs.
-    * The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again.
-
-## Technical support and feedback
-
-Please use the following feedback channels:
-
-* For technical queries, go to the [esp32.com](https://esp32.com/) forum
-* For a feature request or bug report, create a [GitHub issue](https://github.com/espressif/esp-idf/issues)
-
-We will get back to you as soon as possible.
+| Purpose                                  | Field                                     | Original Value   | Modified value          | Method     |
+|:--                                       |:--                                        | :--              | :--                     |:--         |
+| For correctly running Arduino component  | CONFIG_FREERTOS_HZ                        |100               | 1000                    | manually   |
+| For creating setup() & loop()            | AUTOSTART_ARDUINO                         |No                | Yes                     | menuconfig |
+| For disabling idle task watchdog         | CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0      |Yes               | No                      | menuconfig | 
+| For suppressing bootloader info messages | CONFIG_BOOTLOADER_LOG_LEVEL               |Info              | Error                   | menuconfig |
+| For suppressing general info messages    | CONFIG_LOG_DEFAULT_LEVEL                  |Info              | Error                   | menuconfig |
+| For compiler optimization                | COMPILER_OPTIMIZATION                     |-Og               | -O2                     | menuconfig |
+| For mbedTLS optimization                 | MBEDTLS_COMPILER_OPTIMIZATION             |-Os               | -O2                     | menuconfig |
+| For faster flash read                    | ESPTOOLPY_FLASHMODE                       | DIO              | QIO                     | menuconfig |
+| For disabling Wifi remote lib            | ESP_WIFI_REMOTE_ENABLED                   | Yes              | No                      | menuconfig |

+ 1 - 1
components/arduino

@@ -1 +1 @@
-Subproject commit 96b3d0ef8de2b6a90d36fd84f06d4acbfea091dd
+Subproject commit e518da106ae3d7a96870feb2fca7d9dabb2b2c66

+ 1 - 1
main/lib/nbus

@@ -1 +1 @@
-Subproject commit 6c083eb7dfdd3c16ab29004bbdb07b496fb2d3d9
+Subproject commit e9b7467eb6ff75439065fbc2244bfd9aaf4c4280

+ 1 - 1
main/lib/wireless-serial-for-esp32

@@ -1 +1 @@
-Subproject commit 8829dc0554a1a7b7667c5b3f1868ee02404c5a37
+Subproject commit ac2ff3e5da0fa5d3885ea6856c0a60d757289e3e

+ 0 - 233
main/src/acc.txt

@@ -1,233 +0,0 @@
-
-#include "Arduino.h"
-
-#include "ICM_20948.h" // Click here to get the library: http://librarymanager/All#SparkFun_ICM_20948_IMU
-
-//#define USE_SPI       // Uncomment this to use SPI
-
-#define SERIAL_PORT Serial
-
-#define SPI_PORT SPI // Your desired SPI port.       Used only when "USE_SPI" is defined
-
-
-#define CS_PIN 8     // Which pin you connect CS to. Used only when "USE_SPI" is defined
-#define MISO_PIN 7
-#define SCLK_PIN 6
-#define MOSI_PIN 5
-
-#define USE_SPI 1
-// On the SparkFun 9DoF IMU breakout the default is 1, and when the ADR jumper is closed the value becomes 0
-#define AD0_VAL 1
-
-#ifdef USE_SPI
-ICM_20948_SPI myICM; // If using SPI create an ICM_20948_SPI object
-#else
-ICM_20948_I2C myICM; // Otherwise create an ICM_20948_I2C object
-#endif
-
-
-void printScaledAGMT(ICM_20948_SPI *sensor);
-void printFormattedFloat(float val, uint8_t leading, uint8_t decimals);
-
-void setup()
-{
-
-  SERIAL_PORT.begin(115200);
-  while (!SERIAL_PORT)
-  {
-  };
-
-#ifdef USE_SPI
-  SPI_PORT.begin(SCLK_PIN, MISO_PIN, MOSI_PIN);
-#else
-  WIRE_PORT.begin();
-  WIRE_PORT.setClock(400000);
-#endif
-
-  //myICM.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
-
-  bool initialized = false;
-  while (!initialized)
-  {
-
-#ifdef USE_SPI
-    myICM.begin(CS_PIN, SPI_PORT);
-#else
-    myICM.begin(WIRE_PORT, AD0_VAL);
-#endif
-
-    SERIAL_PORT.print(F("Initialization of the sensor returned: "));
-    SERIAL_PORT.println(myICM.statusString());
-    if (myICM.status != ICM_20948_Stat_Ok)
-    {
-      SERIAL_PORT.println("Trying again...");
-      delay(500);
-    }
-    else
-    {
-      initialized = true;
-    }
-  }
-}
-
-void loop()
-{
-
-  if (myICM.dataReady())
-  {
-    myICM.getAGMT();         // The values are only updated when you call 'getAGMT'
-                             //    printRawAGMT( myICM.agmt );     // Uncomment this to see the raw values, taken directly from the agmt structure
-    printScaledAGMT(&myICM); // This function takes into account the scale settings from when the measurement was made to calculate the values with units
-    delay(30);
-  }
-  else
-  {
-    SERIAL_PORT.println("Waiting for data");
-    delay(500);
-  }
-}
-
-// Below here are some helper functions to print the data nicely!
-
-void printPaddedInt16b(int16_t val)
-{
-  if (val > 0)
-  {
-    SERIAL_PORT.print(" ");
-    if (val < 10000)
-    {
-      SERIAL_PORT.print("0");
-    }
-    if (val < 1000)
-    {
-      SERIAL_PORT.print("0");
-    }
-    if (val < 100)
-    {
-      SERIAL_PORT.print("0");
-    }
-    if (val < 10)
-    {
-      SERIAL_PORT.print("0");
-    }
-  }
-  else
-  {
-    SERIAL_PORT.print("-");
-    if (abs(val) < 10000)
-    {
-      SERIAL_PORT.print("0");
-    }
-    if (abs(val) < 1000)
-    {
-      SERIAL_PORT.print("0");
-    }
-    if (abs(val) < 100)
-    {
-      SERIAL_PORT.print("0");
-    }
-    if (abs(val) < 10)
-    {
-      SERIAL_PORT.print("0");
-    }
-  }
-  SERIAL_PORT.print(abs(val));
-}
-
-void printRawAGMT(ICM_20948_AGMT_t agmt)
-{
-  SERIAL_PORT.print("RAW. Acc [ ");
-  printPaddedInt16b(agmt.acc.axes.x);
-  SERIAL_PORT.print(", ");
-  printPaddedInt16b(agmt.acc.axes.y);
-  SERIAL_PORT.print(", ");
-  printPaddedInt16b(agmt.acc.axes.z);
-  SERIAL_PORT.print(" ], Gyr [ ");
-  printPaddedInt16b(agmt.gyr.axes.x);
-  SERIAL_PORT.print(", ");
-  printPaddedInt16b(agmt.gyr.axes.y);
-  SERIAL_PORT.print(", ");
-  printPaddedInt16b(agmt.gyr.axes.z);
-  SERIAL_PORT.print(" ], Mag [ ");
-  printPaddedInt16b(agmt.mag.axes.x);
-  SERIAL_PORT.print(", ");
-  printPaddedInt16b(agmt.mag.axes.y);
-  SERIAL_PORT.print(", ");
-  printPaddedInt16b(agmt.mag.axes.z);
-  SERIAL_PORT.print(" ], Tmp [ ");
-  printPaddedInt16b(agmt.tmp.val);
-  SERIAL_PORT.print(" ]");
-  SERIAL_PORT.println();
-}
-
-void printFormattedFloat(float val, uint8_t leading, uint8_t decimals)
-{
-  float aval = abs(val);
-  if (val < 0)
-  {
-    SERIAL_PORT.print("-");
-  }
-  else
-  {
-    SERIAL_PORT.print(" ");
-  }
-  for (uint8_t indi = 0; indi < leading; indi++)
-  {
-    uint32_t tenpow = 0;
-    if (indi < (leading - 1))
-    {
-      tenpow = 1;
-    }
-    for (uint8_t c = 0; c < (leading - 1 - indi); c++)
-    {
-      tenpow *= 10;
-    }
-    if (aval < tenpow)
-    {
-      SERIAL_PORT.print("0");
-    }
-    else
-    {
-      break;
-    }
-  }
-  if (val < 0)
-  {
-    SERIAL_PORT.print(-val, decimals);
-  }
-  else
-  {
-    SERIAL_PORT.print(val, decimals);
-  }
-}
-
-#ifdef USE_SPI
-void printScaledAGMT(ICM_20948_SPI *sensor)
-{
-#else
-void printScaledAGMT(ICM_20948_I2C *sensor)
-{
-#endif
-  SERIAL_PORT.print("Scaled. Acc (mg) [ ");
-  printFormattedFloat(sensor->accX(), 5, 2);
-  SERIAL_PORT.print(", ");
-  printFormattedFloat(sensor->accY(), 5, 2);
-  SERIAL_PORT.print(", ");
-  printFormattedFloat(sensor->accZ(), 5, 2);
-  SERIAL_PORT.print(" ], Gyr (DPS) [ ");
-  printFormattedFloat(sensor->gyrX(), 5, 2);
-  SERIAL_PORT.print(", ");
-  printFormattedFloat(sensor->gyrY(), 5, 2);
-  SERIAL_PORT.print(", ");
-  printFormattedFloat(sensor->gyrZ(), 5, 2);
-  SERIAL_PORT.print(" ], Mag (uT) [ ");
-  printFormattedFloat(sensor->magX(), 5, 2);
-  SERIAL_PORT.print(", ");
-  printFormattedFloat(sensor->magY(), 5, 2);
-  SERIAL_PORT.print(", ");
-  printFormattedFloat(sensor->magZ(), 5, 2);
-  SERIAL_PORT.print(" ], Tmp (C) [ ");
-  printFormattedFloat(sensor->temp(), 5, 2);
-  SERIAL_PORT.print(" ]");
-  SERIAL_PORT.println();
-}

+ 0 - 62
main/src/bme.txt

@@ -1,62 +0,0 @@
-#include <Arduino.h>
-
-// hw includes
-#include <Wire.h>
-
-// MAPPING
-#define I2C0_SCL  4
-#define I2C0_SDA  3
-
-#define BME280_ADDR   0X76
-
-TwoWire I2CBus0(0);
-
-
-#include <Adafruit_Sensor.h>
-#include <Adafruit_BME280.h>
-
-Adafruit_BME280 bme; // I2C
-//Adafruit_BME280 bme(BME_CS); // hardware SPI
-//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
-
-unsigned long delayTime = 1000;
-void printValues();
-
-void setup()
-{
- Serial.begin(9600);
-
-
-  I2CBus0.setPins(I2C0_SDA, I2C0_SCL);
-
-
-   unsigned status;
-    
-    // default settings
-    status = bme.begin(BME280_ADDR, &I2CBus0);
-    delayTime = 1000;
-}
-
-void loop() { 
-    printValues();
-    delay(delayTime);
-}
-
-
-void printValues() {
-    Serial.print("Temperature = ");
-    Serial.print(bme.readTemperature());
-    Serial.println(" °C");
-
-    Serial.print("Pressure = ");
-
-    Serial.print(bme.readPressure() / 100.0F);
-    Serial.println(" hPa");
-
-    Serial.print("Humidity = ");
-    Serial.print(bme.readHumidity());
-    Serial.println(" %");
-
-    Serial.println();
-}
-

+ 26 - 0
main/src/bridge.txt

@@ -0,0 +1,26 @@
+//#include "BleSerial/Client/BleSerialClient.h"
+#include "EspNowSerial/EspNowSerial.h"
+#include "Arduino.h"
+#include "InterSerialBridge/InterSerialBridge.h"
+
+
+
+EspNowSerial EnSerial;
+uint8_t peer_address[] = {0x9c, 0x9e, 0x6e, 0xe0, 0x87, 0xf4};
+
+InterSerialBridge<1024> Inter(Serial, EnSerial);
+
+
+void setup() 
+{
+    Serial.begin(921600);
+
+    EnSerial.begin(11, false);
+    EnSerial.add_peer(peer_address);
+  
+}
+
+void loop() 
+{
+  Inter.loop_callback();
+}

+ 3 - 2
main/src/config/app_config.h

@@ -10,8 +10,9 @@
 #include <cstdint>
 
 // Timing Values
-#define APP_LOOP_TIMEOUT_MS    10
-#define APP_CLEAR_DELAY_MS    200 
+#define APP_ERR_DELAY_MS        1000
+#define APP_LOOP_TIMEOUT_MS        3
+#define APP_CLEAR_DELAY_MS       200 
 
 // Return Flags
 #define APP_ALWAYS_READY        1

+ 4 - 1
main/src/config/hardware_config.h

@@ -7,10 +7,13 @@
 #ifndef _HARDWARE_CONFIG_H_
 #define _HARDWARE_CONFIG_H_
 
-
 // Serial Baud
 #define SERIAL_BAUD           921600
 
+// Esp Now Serial
+#define ENSERIAL_ADDRESS      {0x9c, 0x9e, 0x6e, 0xe0, 0x7c, 0x68}
+#define ENSERIAL_CHANNEL      11
+
 // I2C #0
 #define I2C0_BUS              Wire
 #define I2C0_SCL              4

+ 14 - 21
main/src/data_acquirer/data_acquirer.cpp

@@ -102,23 +102,20 @@ void read_env_task(void *params)
 
 void read_tof_data(tof_data_t &data)
 {
-    bool data_ready = false;
-    
     if (in_continuous_mode)
     {
-        data_ready = tof_data_reg.read(data.payload);
+        data.data_ready = tof_data_reg.read(data.payload);
     }
     else
     {
-        data_ready = _read_tof(data.payload);
+        data.data_ready = _read_tof(data.payload);
     }
 
-    if (data_ready == 0)
+    if (data.data_ready == 0)
     {
-        data.payload.x = 0;
-        data.payload.y = 0;
-        data.payload.z = 0;
-        data.data_ready = 1;
+        data.payload.x = APP_TOF_NAN;
+        data.payload.y = APP_TOF_NAN;
+        data.payload.z = APP_TOF_NAN;
     }
 }
 
@@ -140,13 +137,12 @@ void read_imu_data(imu_data_t &data)
 
     if (data.data_ready == false)
     {
-        data.payload.ax = 0;
-        data.payload.ay = 0;
-        data.payload.az = 0;
-        data.payload.gx = 0;
-        data.payload.gy = 0;
-        data.payload.gz = 0;
-        data.data_ready = 1;
+        data.payload.ax = APP_ACC_NAN;
+        data.payload.ay = APP_ACC_NAN;
+        data.payload.az = APP_ACC_NAN;
+        data.payload.gx = APP_GYR_NAN;
+        data.payload.gy = APP_GYR_NAN;
+        data.payload.gz = APP_GYR_NAN;
     }
 }
 
@@ -165,11 +161,8 @@ void read_env_data(env_data_t &data)
     
     if (data.data_ready == 0)
     {
-        data.payload.temp = 0;
-        data.payload.hum = 0;
-        data.data_ready = 1;
+        data.payload.temp = APP_TMP_NAN;
+        data.payload.hum = APP_HUM_NAN;
     }
-
-    
 }
 

+ 8 - 2
main/src/device/device.cpp

@@ -6,6 +6,12 @@ esp_err_t Device::hardware_init()
   Serial.begin(SERIAL_BAUD);
   I2C0_BUS.setPins(I2C0_SDA, I2C0_SCL);
   SPI0_BUS.begin(SPI0_SCLK, SPI0_MISO, SPI0_MOSI);
+  
+  // Begin EspNowSerial
+  EnSerial.begin(ENSERIAL_CHANNEL, false);
+  
+  uint8_t peer_address[] = ENSERIAL_ADDRESS;
+  EnSerial.add_peer(peer_address);
 
   // IMU Init
   Imu.begin(SPI0_CS, SPI0_BUS);
@@ -22,8 +28,8 @@ ICM_20948_smplrt_t mySmplrt;
 // 2. Vypočítajte a zadajte delič (Divider)
 // Vzorec: Sample Rate = 1125 / (1 + Divider)
 // Príklad pre ~100 Hz: 1125 / (1 + 10) = 102.2 Hz
-mySmplrt.a = 4; // Delič pre akcelerometer
-mySmplrt.g = 4; // Delič pre gyroskop
+mySmplrt.a = 1; // Delič pre akcelerometer
+mySmplrt.g = 1; // Delič pre gyroskop
 
 // 3. (Aktivujte DLPF - bez toho delič nefunguje!)
 Imu.enableDLPF(ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr, true);

+ 3 - 0
main/src/device/device.h

@@ -13,6 +13,8 @@
 #include <Adafruit_Sensor.h>
 #include <Adafruit_BME280.h>
 
+#include "EspNowSerial/EspNowSerial.h"
+
 class Device
 {
 public:
@@ -21,6 +23,7 @@ public:
     UltraSonicDistanceSensor TofZ{HCSR04_TRIG_Z, HCSR04_ECHO_Z};            ///< tof  z-sensor
     ICM_20948_SPI Imu;                                                      ///< imu sensor
     Adafruit_BME280 Env;                                                    ///< environmental sensor
+    EspNowSerial EnSerial;                                                  ///< esp-now serial handler
 
     /**
      * @brief Initialize hardware.

+ 12 - 11
main/src/main.cpp

@@ -15,20 +15,21 @@
 // Application Config
 #include "master_config.h"
 
-#include "EspNowSerial/EspNowSerial.h"
-
-EspNowSerial EnSerial;
-//uint8_t peer_address[] = {0x54, 0x32, 0x04, 0x03, 0x2a, 0x78}; //C6
-uint8_t peer_address[] = {0x9c, 0x9e, 0x6e, 0xe0,0x7c, 0x68}; //C3+
-NbusLoopEsp32 loop_driver(EnSerial, 10);
-
+// nbus loop driver
+NbusLoopEsp32 loop_driver(Dev.EnSerial, APP_LOOP_TIMEOUT_MS);
 
 void setup()
 {
-  Dev.hardware_init();
-
-  EnSerial.begin(11, false);
-  EnSerial.add_peer(peer_address);
+  
+  // initialize HW
+  if (Dev.hardware_init() != ESP_OK)
+  {
+    while (true)
+    {
+      Serial.println("Error: Device is not initialized!");
+      delay(APP_ERR_DELAY_MS);
+    }
+  }
 
   // initialize nBus stack
   nbus_init(getAppdrvDriver(), nbus_platform_init(&loop_driver));

+ 5 - 0
main/src/nbus_app_driver/nbus_app_driver.cpp

@@ -93,6 +93,11 @@ uint8_t appdrv_getData(uint8_t sensor_index, uint8_t *data)
             data_size = _write_sensor_values(data, data_size, HUM_ID, &env_data.payload.hum, APP_HUM_VCNT);
     }
 
+    if (!tof_data.data_ready && !imu_data.data_ready && !env_data.data_ready)
+    {
+        return 0;
+    }
+    
     counter++;
 
     return data_size;

+ 50 - 0
main/src/slave.txt

@@ -0,0 +1,50 @@
+// Arduino Core
+#include <Arduino.h>
+
+// nBus Core
+#include "nbus_app.h"
+#include "memory_dummy.h"
+
+// nBus ESP32 Platform Driver
+#include "NbusSlaveDriver/nbus_app_interface_esp32.h"
+#include "NbusLoopDriver/NbusLoopEsp32.h"
+
+// nBus Application Driver
+#include "nbus_app_driver/nbus_app_driver.h"
+
+// Application Config
+#include "master_config.h"
+
+// nbus loop driver
+NbusLoopEsp32 loop_driver(Dev.EnSerial, APP_LOOP_TIMEOUT_MS);
+
+void setup()
+{
+  
+  // initialize HW
+  if (Dev.hardware_init() != ESP_OK)
+  {
+    while (true)
+    {
+      Serial.println("Error: Device is not initialized!");
+      delay(APP_ERR_DELAY_MS);
+    }
+  }
+
+  // initialize nBus stack
+  nbus_init(getAppdrvDriver(), nbus_platform_init(&loop_driver));
+  nbus_init_memory_driver(getDummyMemDriver());
+  nbus_init_app(NULL, NULL);
+
+  // initialize measuring tasks
+  xTaskCreate(read_tof_task, TASK_TOF_NAME, TASK_TOF_STACK_DEPTH, NULL, TASK_TOF_PRIORITY, NULL);
+  xTaskCreate(read_imu_task, TASK_IMU_NAME, TASK_IMU_STACK_DEPTH, NULL, TASK_IMU_PRIORITY, NULL);
+  xTaskCreate(read_env_task, TASK_ENV_NAME, TASK_ENV_STACK_DEPTH, NULL, TASK_ENV_PRIORITY, NULL);
+}
+
+void loop()
+{
+  // run nBus
+  nbus_stack();
+  nbus_platform_loop();
+}