Skip to content

Commit 16faa43

Browse files
Merge pull request #3795 from iNavFlight/de_opflow_fixes
Optic flow & surface improvements
2 parents a260c77 + f800eb4 commit 16faa43

File tree

18 files changed

+108
-58
lines changed

18 files changed

+108
-58
lines changed

src/main/fc/cli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static const char * const *sensorHardwareNames[] = {
188188
#else
189189
NULL,
190190
#endif
191-
#ifdef USE_OPTICAL_FLOW
191+
#ifdef USE_OPFLOW
192192
table_opflow_hardware,
193193
#else
194194
NULL,

src/main/fc/fc_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ void FAST_CODE NOINLINE taskGyro(timeUs_t currentTimeUs) {
635635
/* Update actual hardware readings */
636636
gyroUpdate();
637637

638-
#ifdef USE_OPTICAL_FLOW
638+
#ifdef USE_OPFLOW
639639
if (sensors(SENSOR_OPFLOW)) {
640640
opflowGyroUpdateCallback((timeUs_t)currentDeltaTime + (gyroUpdateUs - currentTimeUs));
641641
}

src/main/fc/fc_msp.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
542542
break;
543543

544544
case MSP2_INAV_OPTICAL_FLOW:
545-
#ifdef USE_OPTICAL_FLOW
545+
#ifdef USE_OPFLOW
546546
sbufWriteU8(dst, opflow.rawQuality);
547547
sbufWriteU16(dst, RADIANS_TO_DEGREES(opflow.flowRate[X]));
548548
sbufWriteU16(dst, RADIANS_TO_DEGREES(opflow.flowRate[Y]));
@@ -1062,7 +1062,7 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
10621062
sbufWriteU8(dst, gyroConfig()->gyro_align);
10631063
sbufWriteU8(dst, accelerometerConfig()->acc_align);
10641064
sbufWriteU8(dst, compassConfig()->mag_align);
1065-
#ifdef USE_OPTICAL_FLOW
1065+
#ifdef USE_OPFLOW
10661066
sbufWriteU8(dst, opticalFlowConfig()->opflow_align);
10671067
#else
10681068
sbufWriteU8(dst, 0);
@@ -1178,7 +1178,7 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
11781178
#else
11791179
sbufWriteU8(dst, 0);
11801180
#endif
1181-
#ifdef USE_OPTICAL_FLOW
1181+
#ifdef USE_OPFLOW
11821182
sbufWriteU8(dst, opticalFlowConfig()->opflow_hardware);
11831183
#else
11841184
sbufWriteU8(dst, 0);
@@ -1252,6 +1252,12 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
12521252
sbufWriteU16(dst, 0);
12531253
sbufWriteU16(dst, 0);
12541254
#endif
1255+
1256+
#ifdef USE_OPFLOW
1257+
sbufWriteU16(dst, opticalFlowConfig()->opflow_scale * 256);
1258+
#else
1259+
sbufWriteU16(dst, 0);
1260+
#endif
12551261
break;
12561262

12571263
case MSP_POSITION_ESTIMATION_CONFIG:
@@ -1948,7 +1954,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
19481954
#else
19491955
sbufReadU8(src);
19501956
#endif
1951-
#ifdef USE_OPTICAL_FLOW
1957+
#ifdef USE_OPFLOW
19521958
opticalFlowConfigMutable()->opflow_align = sbufReadU8(src);
19531959
#else
19541960
sbufReadU8(src);
@@ -2080,7 +2086,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
20802086
#else
20812087
sbufReadU8(src); // rangefinder hardware
20822088
#endif
2083-
#ifdef USE_OPTICAL_FLOW
2089+
#ifdef USE_OPFLOW
20842090
opticalFlowConfigMutable()->opflow_hardware = sbufReadU8(src);
20852091
#else
20862092
sbufReadU8(src); // optical flow hardware
@@ -2163,6 +2169,11 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
21632169
sbufReadU16(src);
21642170
sbufReadU16(src);
21652171
sbufReadU16(src);
2172+
#endif
2173+
#ifdef USE_OPFLOW
2174+
if (dataSize >= 20) {
2175+
opticalFlowConfigMutable()->opflow_scale = sbufReadU16(src) / 256.0f;
2176+
}
21662177
#endif
21672178
} else
21682179
return MSP_RESULT_ERROR;
@@ -2205,6 +2216,15 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
22052216
return MSP_RESULT_ERROR;
22062217
break;
22072218

2219+
#ifdef USE_OPFLOW
2220+
case MSP2_INAV_OPFLOW_CALIBRATION:
2221+
if (!ARMING_FLAG(ARMED))
2222+
opflowStartCalibration();
2223+
else
2224+
return MSP_RESULT_ERROR;
2225+
break;
2226+
#endif
2227+
22082228
case MSP_EEPROM_WRITE:
22092229
if (!ARMING_FLAG(ARMED)) {
22102230
writeEEPROM();

src/main/fc/fc_tasks.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void taskUpdateRangefinder(timeUs_t currentTimeUs)
203203
}
204204
#endif
205205

206-
#ifdef USE_OPTICAL_FLOW
206+
#ifdef USE_OPFLOW
207207
void taskUpdateOpticalFlow(timeUs_t currentTimeUs)
208208
{
209209
if (!sensors(SENSOR_OPFLOW))
@@ -324,7 +324,7 @@ void fcTasksInit(void)
324324
setTaskEnabled(TASK_CMS, feature(FEATURE_OSD) || feature(FEATURE_DASHBOARD));
325325
#endif
326326
#endif
327-
#ifdef USE_OPTICAL_FLOW
327+
#ifdef USE_OPFLOW
328328
setTaskEnabled(TASK_OPFLOW, sensors(SENSOR_OPFLOW));
329329
#endif
330330
#ifdef USE_VTX_CONTROL
@@ -511,7 +511,7 @@ cfTask_t cfTasks[TASK_COUNT] = {
511511
},
512512
#endif
513513

514-
#ifdef USE_OPTICAL_FLOW
514+
#ifdef USE_OPFLOW
515515
[TASK_OPFLOW] = {
516516
.taskName = "OPFLOW",
517517
.taskFunc = taskUpdateOpticalFlow,

src/main/fc/settings.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ groups:
261261
- name: PG_OPFLOW_CONFIG
262262
type: opticalFlowConfig_t
263263
headers: ["sensors/opflow.h"]
264-
condition: USE_OPTICAL_FLOW
264+
condition: USE_OPFLOW
265265
members:
266266
- name: opflow_hardware
267267
table: opflow_hardware

src/main/msp/msp_protocol_v2_inav.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@
6060

6161
#define MSP2_PID 0x2030
6262
#define MSP2_SET_PID 0x2031
63+
64+
#define MSP2_INAV_OPFLOW_CALIBRATION 0x2032

src/main/navigation/navigation_pos_estimator_flow.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
extern navigationPosEstimator_t posEstimator;
4747

48-
#ifdef USE_OPTICAL_FLOW
48+
#ifdef USE_OPFLOW
4949
/**
5050
* Read optical flow topic
5151
* Function is called by OPFLOW task as soon as new update is available
@@ -63,7 +63,7 @@ void updatePositionEstimator_OpticalFlowTopic(timeUs_t currentTimeUs)
6363

6464
bool estimationCalculateCorrection_XY_FLOW(estimationContext_t * ctx)
6565
{
66-
#if defined(USE_RANGEFINDER) && defined(USE_OPTICAL_FLOW)
66+
#if defined(USE_RANGEFINDER) && defined(USE_OPFLOW)
6767
if (!((ctx->newFlags & EST_FLOW_VALID) && (ctx->newFlags & EST_SURFACE_VALID) && (ctx->newFlags & EST_Z_VALID))) {
6868
return false;
6969
}

src/main/scheduler/scheduler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ typedef enum {
9898
#ifdef USE_CMS
9999
TASK_CMS,
100100
#endif
101-
#ifdef USE_OPTICAL_FLOW
101+
#ifdef USE_OPFLOW
102102
TASK_OPFLOW,
103103
#endif
104104
#ifdef USE_UAV_INTERCONNECT

src/main/sensors/diagnostics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ hardwareSensorStatus_e getHwGPSStatus(void)
192192

193193
hardwareSensorStatus_e getHwOpticalFlowStatus(void)
194194
{
195-
#if defined(USE_OPTICAL_FLOW)
195+
#if defined(USE_OPFLOW)
196196
if (detectedSensors[SENSOR_INDEX_OPFLOW] != OPFLOW_NONE) {
197197
if (opflowIsHealthy()) {
198198
return HW_SENSOR_OK;

src/main/sensors/initialisation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bool sensorsAutodetect(void)
7474
rangefinderInit();
7575
#endif
7676

77-
#ifdef USE_OPTICAL_FLOW
77+
#ifdef USE_OPFLOW
7878
opflowInit();
7979
#endif
8080

0 commit comments

Comments
 (0)