Skip to content
Open
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
8 changes: 8 additions & 0 deletions WST-FC/configuration_preprocesor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Import("env")
use_bt = env.GetProjectOption("use_bluestack", "no")

if use_bt == "yes":
env.Append(CPPDEFINES=["USE_BLUEPAD32"])
env.Append(PIOPLATFORMPACKAGES=[
"framework-arduinoespressif32@https://github.com/maxgerhardt/pio-framework-bluepad32/archive/refs/heads/main.zip"
])
6 changes: 4 additions & 2 deletions WST-FC/include/CommunicationModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
#include "communicationModules\CommunicationWiFiUDPModule.h"
#include "communicationModules\CommunicationESPNowModule.h"
#include "communicationModules\CommunicationSerialModule.h"
#include "communicationModules\CommunicationGamepadModule.h"
#if (COMMUNICATION_METHOD == 3)
#include "communicationModules\CommunicationGamepadModule.h"
#endif

class CommunicationModule
{
private:
DroneControlData *sharedData;
ICommunicationInterface *communicationInterface;
std::vector<ICommunicationInterface*> communicationInterfaces;
wl_status_t connectionStatus{WL_IDLE_STATUS};
DroneStatus *droneStatus;

Expand Down
17 changes: 12 additions & 5 deletions WST-FC/include/Configuration.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#ifndef CONFIGURATION_H
#define CONFIGURATION_H

#define VEHICLE_TYPE_AIRBOAT
#define VEHICLE_TYPE_TANK

#define WIFI_SSID "AutisticDrones"
#define WIFI_PASSWORD "Autyzm2137"
#define UDP_CONTROLL_PORT 4210
#define MAX_ROGUE_TIME 1000
#define MIN_RSSI -80
#define COMMUNICATION_METHOD 3
#define TELEMETRY_TIME 1000

#define USE_WIFI_UDP
//#define USE_ESP_NOW
#define USE_SERIAL
//#define USE_GAMEPAD

enum DroneStatus
{
WORKS,
Expand All @@ -28,4 +29,10 @@ enum DroneStatus
#define WG_PEER_PUBLIC_KEY "KLUCZ_PUBLICZNY_SERWERA="
#endif

#if defined(USE_WIFI_UDP) || defined(USE_ESP_NOW)
#define WIFI_SSID "HPLOVER"
#define WIFI_PASSWORD "Autyzm2137!"
#define UDP_CONTROLL_PORT 4210
#endif

#endif
16 changes: 16 additions & 0 deletions WST-FC/include/DroneFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef DRONEFACTORY_H
#define DRONEFACTORY_H

#include <Arduino.h>
#include <vector>
#include "SensorsModule.h"
#include "modules/IModule.h"
#include "IMixer.h"

class DroneFactory
{
public:
static IMixer* BuildVehicle(SensorsModule& sensorsModule, std::vector<IModule*>& modules);
};

#endif
92 changes: 92 additions & 0 deletions WST-FC/include/SystemRegistry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#ifndef SYSTEM_REGISTRY_H
#define SYSTEM_REGISTRY_H

#include <Arduino.h>
#include <vector>

enum ParamType {
PARAM_INT,
PARAM_FLOAT,
PARAM_DOUBLE,
PARAM_BOOL
};

struct ConfigParam {
const char* name;
void* ptr;
ParamType type;
};

class SystemRegistry {
private:
std::vector<ConfigParam> params;
SystemRegistry() {}

public:
static SystemRegistry& GetInstance() {
static SystemRegistry instance;
return instance;
}

void Register(const char* name, void* ptr, ParamType type)
{
params.push_back({name, ptr, type});
}

bool SetValue(const char* name, const char* valueStr)
{
for(const auto& param : params)
{
if(strcmp(param.name, name) == 0)
{
switch (param.type) {
case PARAM_INT:
*(int*)param.ptr = atoi(valueStr);
break;
case PARAM_FLOAT:
*(float*)param.ptr = atof(valueStr);
break;
case PARAM_DOUBLE:
*(double*)param.ptr = atof(valueStr);
break;
case PARAM_BOOL:
*(bool*)param.ptr = (atoi(valueStr) > 0);
break;
}
Serial.println("Value SET");
return true;
}
}
Serial.println("There is no such variable");
return false;
}

void ReturnAllRegistryNames()
{
for(const auto& param : params)
{
Serial.print(param.name);
Serial.print(": ");

switch (param.type) {
case PARAM_INT:
Serial.println(*(int*)param.ptr);
break;
case PARAM_FLOAT:
Serial.println(*(float*)param.ptr);
break;
case PARAM_DOUBLE:
Serial.println(*(double*)param.ptr);
break;
case PARAM_BOOL:
Serial.println(*(bool*)param.ptr);
break;
default:
Serial.println("UNSUPPORTED_TYPE");
break;
}
}
}
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
class CommunicationESPNowModule : public ICommunicationInterface{
private:
static CommunicationESPNowModule* instance;
DroneControlData *sharedData;
unsigned long lastUpdate{0};
DroneStatus *droneStatus;
ulong lastDataTime = 0;
uint8_t broadcastAddress[6] {0xEC,0x64,0xC9,0xC4,0xA2,0x1A};
public:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef COMMUNICATIONGAMEPADMODULE_H
#define COMMUNICATIONGAMEPADMODULE_H

#ifdef USE_BLUEPAD32
#include "DroneData.h"
#include "ICommunicationInterface.h"
#include "Configuration.h"
Expand All @@ -9,8 +9,6 @@

class CommunicationGamepadModule : public ICommunicationInterface {
private:
DroneControlData *sharedData;
DroneStatus *droneStatus;
GamepadPtr myGamepad = nullptr;

public:
Expand All @@ -27,4 +25,5 @@ class CommunicationGamepadModule : public ICommunicationInterface {
static void onConnectedGamepad(GamepadPtr gp);
static void onDisconnectedGamepad(GamepadPtr gp);
};
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@

class CommunicationSerialModule : public ICommunicationInterface{
private:
DroneControlData *sharedData;
unsigned long lastUpdate{0};
DroneStatus *droneStatus;
long lastDataTime = 0;
uint8_t inputBuffer[sizeof(DroneControlData)];
uint8_t inputBuffer[128];

const uint8_t HEADER_BYTE_1 = 0x44; // 'D'
const uint8_t HEADER_BYTE_2 = 0x43; // 'C'
public:
CommunicationSerialModule(DroneControlData *dataPtr, DroneStatus *status);
void Init() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
#endif
class CommunicationWiFiUDPModule : public ICommunicationInterface{
private:
DroneControlData *sharedData;
WiFiUDP udp;
unsigned int localPort{0};
char packetBuffer[255];

unsigned long lastUpdate{0};
int8_t rssi{0};
wl_status_t connectionStatus{WL_IDLE_STATUS};
DroneStatus *droneStatus;

IPAddress remoteIP;
unsigned int remotePort {0};
Expand Down
39 changes: 39 additions & 0 deletions WST-FC/include/communicationModules/ICommunicationInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,46 @@
#define ICOMMUNICATIONINTERFACE

#include "../SensorsData.h"
#include "SystemRegistry.h"
#include "Configuration.h"
class ICommunicationInterface{
protected:
DroneControlData *sharedData;
DroneStatus *droneStatus;
unsigned long lastUpdate{0};

void ParseIncomingBytes(uint8_t* buffer, size_t len)
{
if (sharedData == nullptr || len < 2) return;

if (len == sizeof(DroneControlData))
{
memcpy(sharedData, buffer, sizeof(DroneControlData));
lastUpdate = millis();
}
else if (buffer[0] == 'S' && buffer[1] == 'E' && buffer[2] == 'T')
{
if (len < 64) buffer[len] = '\0';
else buffer[63] = '\0';

char* str = (char*)buffer;
char* cmd = strtok(str, " ");
char* paramName = strtok(NULL, " ");
char* valueStr = strtok(NULL, " ");

if (paramName != nullptr && valueStr != nullptr)
{
SystemRegistry::GetInstance().SetValue(paramName, valueStr);
}
}
else if (buffer[0] == 'G' && buffer[1] == 'E' && buffer[2] == 'T')
{
if (len < 64) buffer[len] = '\0';
else buffer[63] = '\0';
SystemRegistry::GetInstance().ReturnAllRegistryNames();
}
}

public:
virtual ~ICommunicationInterface(){}
virtual void Init();
Expand Down
2 changes: 1 addition & 1 deletion WST-FC/include/modules/CameraModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
#define XCLK_FREQ_HZ 20000000
#define JPEG_QUALITY 25
#define JPEG_QUALITY 45
#define FB_COUNT 2
#define PART_BOUNDARY "123456789000000000000987654321"

Expand Down
47 changes: 23 additions & 24 deletions WST-FC/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
; 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
[platformio]
description = Advanced, gloriously over-engineered, and fundamentally unreasonable take on making things move. It is an open-source framework built to prove that the sweet spot of engineering lies exactly where "genuinely useful" meets "utterly insane."

[env]
platform = espressif32
platform_packages =
framework-arduinoespressif32@https://github.com/maxgerhardt/pio-framework-bluepad32/archive/refs/heads/main.zip
framework = arduino
monitor_speed = 115200
extra_scripts = pre:configuration_preprocesor.py
use_bluestack = no
monitor_echo = yes
monitor_filters = send_on_enter
build_flags = -DCORE_DEBUG_LEVEL=5
lib_deps =
adafruit/Adafruit MPU6050@^2.2.6
adafruit/DHT sensor library@^1.4.6
madhephaestus/ESP32Servo@^3.0.9
br3ttb/PID@^1.2.1
adafruit/Adafruit ADXL345@^1.3.4
adafruit/Adafruit Unified Sensor@^1.1.14
ciniml/WireGuard-ESP32 @ ^0.1.5
adafruit/Adafruit MPU6050@^2.2.6
adafruit/DHT sensor library@^1.4.6
madhephaestus/ESP32Servo@^3.0.9
br3ttb/PID@^1.2.1
adafruit/Adafruit ADXL345@^1.3.4
adafruit/Adafruit Unified Sensor@^1.1.14
ciniml/WireGuard-ESP32 @ ^0.1.5

[env:esp32doit-devkit-v1]
board = esp32doit-devkit-v1
build_flags =
-D CORE_DEBUG_LEVEL=3
board_build.partitions = huge_app.csv

[env:esp32-c3-super-mini]
board = esp32-c3-devkitm-1
build_flags =
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
-D CORE_DEBUG_LEVEL=0
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1

[env:esp32cam]
board = esp32cam
board = esp32cam
platform_packages =
framework-arduinoespressif32
framework = arduino
build_flags =
-D BOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
Loading