Skip to content

Commit 3facf94

Browse files
committed
CR157 + CR156 + Pitot Virtual fix
1 parent 93920f0 commit 3facf94

9 files changed

Lines changed: 64 additions & 32 deletions

File tree

docs/Settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5644,7 +5644,7 @@ Defines rotation rate on PITCH axis that UAV will try to archive on max. stick d
56445644

56455645
### pitot_hardware
56465646

5647-
Selection of pitot hardware.
5647+
Selection of pitot hardware. VIRTUAL only works if a GPS is enabled.
56485648

56495649
| Default | Min | Max |
56505650
| --- | --- | --- |

src/main/blackbox/blackbox.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ typedef struct blackboxMainState_s {
504504
int16_t gyroPeaksYaw[DYN_NOTCH_PEAK_COUNT];
505505

506506
int16_t accADC[XYZ_AXIS_COUNT];
507-
int16_t accVib;
507+
uint16_t accVib; // CR157
508508
int16_t attitude[XYZ_AXIS_COUNT];
509509
int32_t debug[DEBUG32_VALUE_COUNT];
510510
int16_t motor[MAX_SUPPORTED_MOTORS];
@@ -1642,7 +1642,8 @@ static void loadMainState(timeUs_t currentTimeUs)
16421642
blackboxCurrent->axisPID_D[i] = axisPID_D[i];
16431643
blackboxCurrent->axisPID_F[i] = axisPID_F[i];
16441644
blackboxCurrent->gyroADC[i] = lrintf(gyro.gyroADCf[i]);
1645-
blackboxCurrent->accADC[i] = lrintf(acc.accADCf[i] * acc.dev.acc_1G);
1645+
// blackboxCurrent->accADC[i] = constrain(lrintf(acc.accADCf[i] * acc.dev.acc_1G), -32678, 32767);
1646+
blackboxCurrent->accADC[i] = 100 * lrintf(acc.accADCf[i]); // CR157
16461647
blackboxCurrent->gyroRaw[i] = lrintf(gyro.gyroRaw[i]);
16471648

16481649
#ifdef USE_DYNAMIC_FILTERS
@@ -1668,7 +1669,8 @@ static void loadMainState(timeUs_t currentTimeUs)
16681669
blackboxCurrent->mcVelAxisOutput[i] = lrintf(nav_pids->vel[i].output_constrained);
16691670
}
16701671
}
1671-
blackboxCurrent->accVib = lrintf(accGetVibrationLevel() * acc.dev.acc_1G);
1672+
// blackboxCurrent->accVib = constrain(lrintf(accGetVibrationLevel() * acc.dev.acc_1G), 0, 65535);
1673+
blackboxCurrent->accVib = 100 * lrintf(accGetVibrationLevel()); // CR157
16721674

16731675
if (STATE(FIXED_WING_LEGACY)) {
16741676

src/main/fc/cli.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4104,13 +4104,14 @@ static void cliStatus(char *cmdline)
41044104
#endif // for if at32
41054105
#endif // for SITL
41064106

4107-
cliPrintLinef("Sensor status: GYRO=%s, ACC=%s, MAG=%s, BARO=%s, RANGEFINDER=%s, OPFLOW=%s, GPS=%s",
4107+
cliPrintLinef("Sensor status: GYRO=%s, ACC=%s, MAG=%s, BARO=%s, RANGEFINDER=%s, OPFLOW=%s, PITOT=%s, GPS=%s",
41084108
hardwareSensorStatusNames[getHwGyroStatus()],
41094109
hardwareSensorStatusNames[getHwAccelerometerStatus()],
41104110
hardwareSensorStatusNames[getHwCompassStatus()],
41114111
hardwareSensorStatusNames[getHwBarometerStatus()],
41124112
hardwareSensorStatusNames[getHwRangefinderStatus()],
41134113
hardwareSensorStatusNames[getHwOpticalFlowStatus()],
4114+
hardwareSensorStatusNames[getHwPitotmeterStatus()],
41144115
hardwareSensorStatusNames[getHwGPSStatus()]
41154116
);
41164117

src/main/fc/settings.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ groups:
667667
condition: USE_PITOT
668668
members:
669669
- name: pitot_hardware
670-
description: "Selection of pitot hardware."
670+
description: "Selection of pitot hardware. VIRTUAL only works if a GPS is enabled."
671671
default_value: "NONE"
672672
table: pitot_hardware
673673
- name: pitot_lpf_milli_hz

src/main/io/osd.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6163,7 +6163,7 @@ textAttributes_t osdGetSystemMessage(char *buff, size_t buff_size, bool isCenter
61636163
char messageBuf[MAX(SETTING_MAX_NAME_LENGTH, OSD_MESSAGE_LENGTH + 1)];
61646164

61656165
/* WARNING: ensure number of messages returned does not exceed messages array size
6166-
* Messages array set 1 larger than maximum expected message count of 6 */
6166+
* Messages array set 1 larger than maximum expected message count of 7 */
61676167
const char *messages[8];
61686168
unsigned messageCount = 0;
61696169

@@ -6347,12 +6347,21 @@ textAttributes_t osdGetSystemMessage(char *buff, size_t buff_size, bool isCenter
63476347
} else if (FLIGHT_MODE(HEADFREE_MODE)) {
63486348
messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_HEADFREE);
63496349
}
6350-
if (FLIGHT_MODE(NAV_ALTHOLD_MODE) && !navigationRequiresAngleMode()) {
6351-
/* If ALTHOLD is separately enabled for multirotor together with ANGL/HORIZON/ACRO modes
6352-
* then ANGL/HORIZON/ACRO are indicated by the OSD_FLYMODE field.
6353-
* In this case indicate ALTHOLD is active via a system message */
6354-
6355-
messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_ALTITUDE_HOLD);
6350+
if (FLIGHT_MODE(NAV_ALTHOLD_MODE)) { // CR156
6351+
if (posControl.flags.isTerrainFollowEnabled) {
6352+
if (posControl.flags.estAglStatus == EST_TRUSTED) {
6353+
messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_SURFACE_OK);
6354+
} else {
6355+
messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_SURFACE_BAD);
6356+
}
6357+
} else if (!navigationRequiresAngleMode()) {
6358+
/* If ALTHOLD is separately enabled for multirotor together with ANGL/HORIZON/ACRO modes
6359+
* then ANGL/HORIZON/ACRO are indicated by the OSD_FLYMODE field.
6360+
* In this case indicate ALTHOLD is active via a system message */
6361+
6362+
messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_ALTITUDE_HOLD);
6363+
}
6364+
// CR156
63566365
}
63576366
}
63586367
}

src/main/io/osd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
#define OSD_MSG_ANGLEHOLD_PITCH "(ANGLEHOLD PITCH)"
124124
#define OSD_MSG_ANGLEHOLD_LEVEL "(ANGLEHOLD LEVEL)"
125125
#define OSD_MSG_MOVE_STICKS "MOVE STICKS TO ABORT"
126+
#define OSD_MSG_SURFACE_OK "(SURFACE)" // CR156
127+
#define OSD_MSG_SURFACE_BAD "(!SURFACE INOP!)" // CR156
126128
#define OSD_MSG_TOILET_BOWL "!MAG BAD>FIX ATTEMPTED!" // CR141
127129
// #define OSD_MSG_POSEST_DEGRADED "!POSITION ACCURACY POOR!" // CR142
128130

src/main/navigation/navigation_multicopter.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,15 @@ bool isMulticopterLandingDetected(void)
902902
* Detection active during Failsafe only if throttle below mid hover throttle
903903
* and WP mission not active (except landing states).
904904
* Also active in non autonomous flight modes but only when thottle low */
905-
bool startCondition = (navGetCurrentStateFlags() & (NAV_CTL_LAND | NAV_CTL_EMERG))
906-
|| (FLIGHT_MODE(FAILSAFE_MODE) && !FLIGHT_MODE(NAV_WP_MODE) && !isMulticopterThrottleAboveMidHover())
907-
|| (!navigationIsFlyingAutonomousMode() && throttleStickIsLow());
905+
// CR156
906+
bool throttleLowCheckAllowed = !navigationIsFlyingAutonomousMode();
907+
if (posControl.flags.isTerrainFollowEnabled) {
908+
throttleLowCheckAllowed = throttleLowCheckAllowed && posControl.flags.estAglStatus == EST_TRUSTED && posControl.actualState.agl.pos.z < 10.0f;
909+
}
910+
// CR156
911+
bool startCondition = (navGetCurrentStateFlags() & (NAV_CTL_LAND | NAV_CTL_EMERG)) ||
912+
(FLIGHT_MODE(FAILSAFE_MODE) && !FLIGHT_MODE(NAV_WP_MODE) && !isMulticopterThrottleAboveMidHover()) ||
913+
(throttleLowCheckAllowed && throttleStickIsLow()); // CR156
908914
// CR137
909915
if (FLIGHT_MODE(NAV_RTH_MODE)) {
910916
startCondition = startCondition && posControl.actualState.abs.pos.z < 3000;

src/main/sensors/acceleration.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,8 @@ void accUpdate(void)
586586
// calc difference from this sample and 5hz filtered value, square and filter at 2hz
587587
const float accDiff = acc.accADCf[axis] - accFloorFilt;
588588
acc.accVibeSq[axis] = pt1FilterApply(&accVibeFilter[axis], accDiff * accDiff);
589-
acc.accVibe = fast_fsqrtf(acc.accVibeSq[X] + acc.accVibeSq[Y] + acc.accVibeSq[Z]);
590589
}
590+
acc.accVibe = fast_fsqrtf(acc.accVibeSq[X] + acc.accVibeSq[Y] + acc.accVibeSq[Z]); // CR157
591591

592592
// Filter acceleration
593593
for (int axis = 0; axis < XYZ_AXIS_COUNT; axis++) {
@@ -599,7 +599,6 @@ void accUpdate(void)
599599
acc.accADCf[axis] = accNotchFilterApplyFn(accNotchFilter[axis], acc.accADCf[axis]);
600600
}
601601
}
602-
603602
}
604603

605604
// Record extremes: min/max for each axis and acceleration vector modulus

src/main/sensors/pitotmeter.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,30 @@ bool pitotDetect(pitotDev_t *dev, uint8_t pitotHardwareToUse)
134134
FALLTHROUGH;
135135

136136
case PITOT_VIRTUAL:
137-
#if defined(USE_WIND_ESTIMATOR) && defined(USE_PITOT_VIRTUAL)
138-
if ((pitotHardwareToUse != PITOT_AUTODETECT) && virtualPitotDetect(dev)) {
139-
pitotHardware = PITOT_VIRTUAL;
140-
break;
141-
}
142-
#endif
143-
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
144137
if (pitotHardwareToUse != PITOT_AUTODETECT) {
138+
#if defined(USE_WIND_ESTIMATOR) && defined(USE_PITOT_VIRTUAL)
139+
if (virtualPitotDetect(dev)) {
140+
pitotHardware = PITOT_VIRTUAL;
141+
break;
142+
}
143+
#endif
144+
requestedSensors[SENSOR_INDEX_PITOT] = PITOT_NONE;
145145
break;
146146
}
147+
147148
FALLTHROUGH;
149+
// case PITOT_VIRTUAL:
150+
// #if defined(USE_WIND_ESTIMATOR) && defined(USE_PITOT_VIRTUAL)
151+
// if ((pitotHardwareToUse != PITOT_AUTODETECT) && virtualPitotDetect(dev)) {
152+
// pitotHardware = PITOT_VIRTUAL;
153+
// break;
154+
// }
155+
// #endif
156+
// /* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
157+
// if (pitotHardwareToUse != PITOT_AUTODETECT) {
158+
// break;
159+
// }
160+
// FALLTHROUGH;
148161

149162
case PITOT_MSP:
150163
#ifdef USE_PITOT_MSP
@@ -240,29 +253,29 @@ STATIC_PROTOTHREAD(pitotThread)
240253
if ( pitot.lastSeenHealthyMs == 0 ) {
241254
if (pitot.dev.start(&pitot.dev)) {
242255
pitot.lastSeenHealthyMs = millis();
243-
}
256+
}
244257
}
245258

246259
if ( (millis() - pitot.lastSeenHealthyMs) >= US2MS(pitot.dev.delay)) {
247260
if (pitot.dev.get(&pitot.dev)) // read current data
248261
pitot.lastSeenHealthyMs = millis();
249262

250263
if (pitot.dev.start(&pitot.dev)) // init for next read
251-
pitot.lastSeenHealthyMs = millis();
264+
pitot.lastSeenHealthyMs = millis();
252265
}
253266

254267

255268
pitot.dev.calculate(&pitot.dev, &pitotPressureTmp, &pitotTemperatureTmp);
256269

257270
#ifdef USE_SIMULATOR
258271
if (SIMULATOR_HAS_OPTION(HITL_AIRSPEED)) {
259-
pitotPressureTmp = sq(simulatorData.airSpeed) * SSL_AIR_DENSITY / 20000.0f + SSL_AIR_PRESSURE;
272+
pitotPressureTmp = sq(simulatorData.airSpeed) * SSL_AIR_DENSITY / 20000.0f + SSL_AIR_PRESSURE;
260273
}
261274
#endif
262275
#if defined(USE_PITOT_FAKE)
263-
if (pitotmeterConfig()->pitot_hardware == PITOT_FAKE) {
264-
pitotPressureTmp = sq(fakePitotGetAirspeed()) * SSL_AIR_DENSITY / 20000.0f + SSL_AIR_PRESSURE;
265-
}
276+
if (pitotmeterConfig()->pitot_hardware == PITOT_FAKE) {
277+
pitotPressureTmp = sq(fakePitotGetAirspeed()) * SSL_AIR_DENSITY / 20000.0f + SSL_AIR_PRESSURE;
278+
}
266279
#endif
267280
ptYield();
268281

@@ -297,7 +310,7 @@ STATIC_PROTOTHREAD(pitotThread)
297310
}
298311

299312
#if defined(USE_PITOT_FAKE)
300-
if (pitotmeterConfig()->pitot_hardware == PITOT_FAKE) {
313+
if (pitotmeterConfig()->pitot_hardware == PITOT_FAKE) {
301314
pitot.airSpeed = fakePitotGetAirspeed();
302315
}
303316
#endif

0 commit comments

Comments
 (0)