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
9 changes: 9 additions & 0 deletions src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ main_sources(COMMON_SRC
drivers/opflow/opflow_virtual.c
drivers/opflow/opflow_virtual.h

drivers/aoa/aoa.h
drivers/aoa/aoa_virtual.c
drivers/aoa/aoa_virtual.h

drivers/osd.c
drivers/osd.h
drivers/persistent.c
Expand Down Expand Up @@ -368,6 +372,8 @@ main_sources(COMMON_SRC
io/gimbal_serial.h
io/headtracker_msp.c
io/headtracker_msp.h
io/aoa_msp.c

io/osd_dji_hd.c
io/osd_dji_hd.h
io/lights.c
Expand Down Expand Up @@ -589,6 +595,9 @@ main_sources(COMMON_SRC
sensors/barometer.h
sensors/pitotmeter.c
sensors/pitotmeter.h
sensors/aoa.c
sensors/aoa.h

sensors/rangefinder.c
sensors/rangefinder.h
sensors/opflow.c
Expand Down
1 change: 1 addition & 0 deletions src/main/build/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ typedef enum {
DEBUG_GPS,
DEBUG_LULU,
DEBUG_SBUS2,
DEBUG_AOA,
DEBUG_COUNT // also update debugModeNames in cli.c
} debugType_e;

Expand Down
4 changes: 3 additions & 1 deletion src/main/config/parameter_group_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@
#define PG_GEOZONE_CONFIG 1042
#define PG_GEOZONES 1043
#define PG_GEOZONE_VERTICES 1044
#define PG_INAV_END PG_GEOZONE_VERTICES
#define PG_AOA_CONFIG 1045
#define PG_AOA_CONTROL_CONFIG 1046
#define PG_INAV_END PG_AOA_CONTROL_CONFIG

// OSD configuration (subject to change)
//#define PG_OSD_FONT_CONFIG 2047
Expand Down
51 changes: 51 additions & 0 deletions src/main/drivers/aoa/aoa.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* This file is part of INAV Project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU General Public License Version 3, as described below:
*
* This file is free software: you may copy, redistribute and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

#pragma once

#include <stdint.h>
#include <stdbool.h>
#include "common/time.h"
#include "drivers/io.h"
#include "drivers/bus.h"

// AOA values are in decidegrees, typical range is -600 to +600 (-60.0° to +60.0°)
// Use values outside valid range for special states
#define AOA_NO_NEW_DATA (INT16_MAX) // No new data available from sensor
#define AOA_OUT_OF_RANGE (1810) // Measurement out of valid range (181.0°)
#define AOA_HARDWARE_FAILURE (1811) // Hardware failure detected

struct aoaDev_s;

typedef void (*aoaOpInitFuncPtr)(struct aoaDev_s * dev);
typedef void (*aoaOpStartFuncPtr)(struct aoaDev_s * dev);
typedef void (*aoaOpReadFuncPtr)(struct aoaDev_s * dev, int16_t * aoa, int16_t * sideslip);

typedef struct aoaDev_s {
busDevice_t * busDev;
timeMs_t delayMs;
aoaOpInitFuncPtr init;
aoaOpStartFuncPtr update;
aoaOpReadFuncPtr read;
} aoaDev_t;
71 changes: 71 additions & 0 deletions src/main/drivers/aoa/aoa_virtual.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* This file is part of INAV Project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU General Public License Version 3, as described below:
*
* This file is free software: you may copy, redistribute and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

#include <stdbool.h>
#include <stdint.h>
#include <string.h>

#include <platform.h>

#include "build/build_config.h"

#include "common/utils.h"

#include "drivers/aoa/aoa_virtual.h"

static const virtualAoaVTable_t * highLevelDeviceVTable = NULL;

static void virtualAoaInit(aoaDev_t * dev)
{
UNUSED(dev);
return highLevelDeviceVTable->init();
}

static void virtualAoaUpdate(aoaDev_t * dev)
{
UNUSED(dev);
return highLevelDeviceVTable->update();
}
Comment on lines +39 to +49
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

3. Void return expression 🐞 Bug ≡ Correctness

virtualAoaInit/virtualAoaUpdate are declared void but use `return
highLevelDeviceVTable->...()` which is not valid ISO C and can fail compilation (or at least emit
warnings) on stricter toolchains.
Agent Prompt
### Issue description
`virtualAoaInit()` and `virtualAoaUpdate()` are `void` functions but currently use `return highLevelDeviceVTable->init();` / `return highLevelDeviceVTable->update();`, which is not valid ISO C and may break builds on stricter embedded toolchains.

### Issue Context
These functions are part of the newly added AOA virtual device adapter and are called through the AOA device vtable.

### Fix Focus Areas
- src/main/drivers/aoa/aoa_virtual.c[39-49]

### Expected fix
Change to simple calls:
- `highLevelDeviceVTable->init(); return;` (or just call without `return`)
- `highLevelDeviceVTable->update(); return;`

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


static void virtualAoaRead(aoaDev_t * dev, int16_t * aoa, int16_t * sideslip)
{
UNUSED(dev);
highLevelDeviceVTable->read(aoa, sideslip);
}

bool virtualAoaDetect(aoaDev_t * dev, const virtualAoaVTable_t * vtable)
{
if (vtable && vtable->detect()) {

highLevelDeviceVTable = vtable;
dev->delayMs = AOA_VIRTUAL_TASK_PERIOD_MS;
dev->init = &virtualAoaInit;
dev->update = &virtualAoaUpdate;
dev->read = &virtualAoaRead;

return true;
}

return false;
}
38 changes: 38 additions & 0 deletions src/main/drivers/aoa/aoa_virtual.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file is part of INAV Project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU General Public License Version 3, as described below:
*
* This file is free software: you may copy, redistribute and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

#pragma once

#include "drivers/aoa/aoa.h"

#define AOA_VIRTUAL_TASK_PERIOD_MS 30

typedef struct virtualAoaVTable_s {
bool (*detect)(void);
void (*init)(void);
void (*update)(void);
void (*read)(int16_t * aoa, int16_t * sideslip);
} virtualAoaVTable_t;

bool virtualAoaDetect(aoaDev_t * dev, const virtualAoaVTable_t * vtable);
6 changes: 6 additions & 0 deletions src/main/drivers/osd_symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@
#define SYM_GFORCE_Y 0xBE // 190 Gforce Y
#define SYM_GFORCE_Z 0xBF // 191 Gforce Z

#ifdef USE_AOA
#define SYM_AOA_UP 0x17 // up
#define SYM_AOA_DOWN 0x1B // down
#define SYM_AOA 0x41 // A
#endif

#define SYM_BARO_TEMP 0xC0 // 192
#define SYM_IMU_TEMP 0xC1 // 193
#define SYM_TEMP 0xC2 // 194 Thermometer icon
Expand Down
19 changes: 14 additions & 5 deletions src/main/fc/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ static const char *debugModeNames[DEBUG_COUNT] = {
"HEADTRACKER",
"GPS",
"LULU",
"SBUS2"
"SBUS2",
"AOA"
};

/* Sensor names (used in lookup tables for *_hardware settings and in status
Expand All @@ -234,10 +235,10 @@ static const char *const gyroNames[] = {

// sync this with sensors_e
static const char * const sensorTypeNames[] = {
"GYRO", "ACC", "BARO", "MAG", "RANGEFINDER", "PITOT", "OPFLOW", "GPS", "GPS+MAG", NULL
"GYRO", "ACC", "BARO", "MAG", "RANGEFINDER", "PITOT", "OPFLOW", "AOA", "GPS", "GPS+MAG", NULL
};

#define SENSOR_NAMES_MASK (SENSOR_GYRO | SENSOR_ACC | SENSOR_BARO | SENSOR_MAG | SENSOR_RANGEFINDER | SENSOR_PITOT | SENSOR_OPFLOW)
#define SENSOR_NAMES_MASK (SENSOR_GYRO | SENSOR_ACC | SENSOR_BARO | SENSOR_MAG | SENSOR_RANGEFINDER | SENSOR_PITOT | SENSOR_OPFLOW | SENSOR_AOA)

static const char * const hardwareSensorStatusNames[] = {
"NONE", "OK", "UNAVAILABLE", "FAILING"
Expand Down Expand Up @@ -271,6 +272,11 @@ static const char * const *sensorHardwareNames[] = {
#else
NULL,
#endif
#ifdef USE_AOA
table_aoa_hardware,
#else
NULL,
#endif
};

static void cliPrint(const char *str)
Expand Down Expand Up @@ -4142,14 +4148,17 @@ static void cliStatus(char *cmdline)
#endif // for if at32
#endif // for SITL

cliPrintLinef("Sensor status: GYRO=%s, ACC=%s, MAG=%s, BARO=%s, RANGEFINDER=%s, OPFLOW=%s, GPS=%s",
cliPrintLinef(
"Sensor status: GYRO=%s, ACC=%s, MAG=%s, BARO=%s, RANGEFINDER=%s, "
"OPFLOW=%s, GPS=%s, AOA=%s",
hardwareSensorStatusNames[getHwGyroStatus()],
hardwareSensorStatusNames[getHwAccelerometerStatus()],
hardwareSensorStatusNames[getHwCompassStatus()],
hardwareSensorStatusNames[getHwBarometerStatus()],
hardwareSensorStatusNames[getHwRangefinderStatus()],
hardwareSensorStatusNames[getHwOpticalFlowStatus()],
hardwareSensorStatusNames[getHwGPSStatus()]
hardwareSensorStatusNames[getHwGPSStatus()],
hardwareSensorStatusNames[getHwAoaStatus()]
);

#ifdef USE_ESC_SENSOR
Expand Down
18 changes: 18 additions & 0 deletions src/main/fc/fc_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
#include "io/vtx_string.h"
#include "io/gps_private.h" //for MSP_SIMULATOR
#include "io/headtracker_msp.h"
#include "io/aoa.h"

#include "io/osd/custom_elements.h"

Expand Down Expand Up @@ -129,6 +130,7 @@
#include "sensors/compass.h"
#include "sensors/gyro.h"
#include "sensors/opflow.h"
#include "sensors/aoa.h"
#include "sensors/temperature.h"
#include "sensors/esc_sensor.h"

Expand Down Expand Up @@ -1396,6 +1398,11 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
#else
sbufWriteU8(dst, 0);
#endif
#ifdef USE_AOA
sbufWriteU8(dst, aoaConfig()->aoa_hardware);
#else
sbufWriteU8(dst, 0);
#endif
#ifdef USE_OPFLOW
sbufWriteU8(dst, opticalFlowConfig()->opflow_hardware);
#else
Expand Down Expand Up @@ -2582,6 +2589,11 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
#else
sbufReadU8(src); // rangefinder hardware
#endif
#ifdef USE_AOA
aoaConfigMutable()->aoa_hardware = sbufReadU8(src);
#else
sbufReadU8(src); // aoa hardware
#endif
#ifdef USE_OPFLOW
opticalFlowConfigMutable()->opflow_hardware = sbufReadU8(src);
#else
Expand Down Expand Up @@ -4467,6 +4479,12 @@ static mspResult_e mspProcessSensorCommand(uint16_t cmdMSP, sbuf_t *src)
break;
#endif

#if defined(USE_AOA_MSP)
case MSP2_SENSOR_AOA:
mspAoaReceiveNewData(sbufPtr(src));
break;
#endif

#if (defined(USE_HEADTRACKER) && defined(USE_HEADTRACKER_MSP))
case MSP2_SENSOR_HEADTRACKER:
mspHeadTrackerReceiverNewData(sbufPtr(src), dataSize);
Expand Down
29 changes: 28 additions & 1 deletion src/main/fc/fc_tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
#include "sensors/pitotmeter.h"
#include "sensors/rangefinder.h"
#include "sensors/opflow.h"
#include "sensors/aoa.h"

#include "telemetry/telemetry.h"
#include "telemetry/sbus2.h"
Expand Down Expand Up @@ -268,6 +269,21 @@ void taskUpdateOpticalFlow(timeUs_t currentTimeUs)
}
#endif

#ifdef USE_AOA
void taskUpdateAoa(timeUs_t currentTimeUs)
{
if (!sensors(SENSOR_AOA))
return;

const uint32_t newDeadline = aoaUpdate();
if (newDeadline != 0) {
rescheduleTask(TASK_SELF, newDeadline);
}

aoaProcess();
}
#endif

#ifdef USE_DASHBOARD
void taskDashboardUpdate(timeUs_t currentTimeUs)
{
Expand Down Expand Up @@ -414,6 +430,9 @@ void fcTasksInit(void)
#ifdef USE_OPFLOW
setTaskEnabled(TASK_OPFLOW, sensors(SENSOR_OPFLOW));
#endif
#ifdef USE_AOA
setTaskEnabled(TASK_AOA, sensors(SENSOR_AOA));
#endif
#ifdef USE_VTX_CONTROL
#if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP) || defined(USE_VTX_MSP)
setTaskEnabled(TASK_VTXCTRL, true);
Expand Down Expand Up @@ -671,7 +690,15 @@ cfTask_t cfTasks[TASK_COUNT] = {
[TASK_OPFLOW] = {
.taskName = "OPFLOW",
.taskFunc = taskUpdateOpticalFlow,
.desiredPeriod = TASK_PERIOD_HZ(100), // I2C/SPI sensor will work at higher rate and accumulate, UART sensor will work at lower rate w/o accumulation
.desiredPeriod = TASK_PERIOD_HZ(100),
.staticPriority = TASK_PRIORITY_MEDIUM,
},
#endif
#ifdef USE_AOA
[TASK_AOA] = {
.taskName = "AOA",
.taskFunc = taskUpdateAoa,
.desiredPeriod = TASK_PERIOD_MS(100),
.staticPriority = TASK_PRIORITY_MEDIUM,
},
#endif
Expand Down
Loading