Merge branch 'nebbian-feature-sonar-flight-mode-no-baro'

This commit is contained in:
Dominic Clifton 2014-09-26 13:40:10 +01:00
commit 1182f67b70
9 changed files with 78 additions and 21 deletions

View File

@ -99,7 +99,7 @@ void mixerUseConfigs(servoParam_t *servoConfToUse, flight3DConfig_t *flight3DCon
master_t masterConfig; // master config struct with data independent from profiles master_t masterConfig; // master config struct with data independent from profiles
profile_t *currentProfile; // profile config struct profile_t *currentProfile; // profile config struct
static const uint8_t EEPROM_CONF_VERSION = 79; static const uint8_t EEPROM_CONF_VERSION = 80;
static void resetAccelerometerTrims(flightDynamicsTrims_t *accelerometerTrims) static void resetAccelerometerTrims(flightDynamicsTrims_t *accelerometerTrims)
{ {

View File

@ -40,6 +40,7 @@ typedef enum {
HEADFREE_MODE = (1 << 6), HEADFREE_MODE = (1 << 6),
AUTOTUNE_MODE = (1 << 7), AUTOTUNE_MODE = (1 << 7),
PASSTHRU_MODE = (1 << 8), PASSTHRU_MODE = (1 << 8),
SONAR_MODE = (1 << 9),
} flightModeFlags_e; } flightModeFlags_e;
extern uint16_t flightModeFlags; extern uint16_t flightModeFlags;

View File

@ -62,7 +62,7 @@
#include "config/config_profile.h" #include "config/config_profile.h"
#include "config/config_master.h" #include "config/config_master.h"
#ifdef BARO #if defined(BARO) || defined(SONAR)
static int16_t initialThrottleHold; static int16_t initialThrottleHold;
static void multirotorAltHold(void) static void multirotorAltHold(void)
@ -83,7 +83,7 @@ static void multirotorAltHold(void)
rcCommand[THROTTLE] = constrain(initialThrottleHold + BaroPID, masterConfig.escAndServoConfig.minthrottle, masterConfig.escAndServoConfig.maxthrottle); rcCommand[THROTTLE] = constrain(initialThrottleHold + BaroPID, masterConfig.escAndServoConfig.minthrottle, masterConfig.escAndServoConfig.maxthrottle);
} }
} else { } else {
// slow alt changes for apfags // slow alt changes, mostly used for aerial photography
if (abs(rcCommand[THROTTLE] - initialThrottleHold) > currentProfile->alt_hold_deadband) { if (abs(rcCommand[THROTTLE] - initialThrottleHold) > currentProfile->alt_hold_deadband) {
// set velocity proportional to stick movement +100 throttle gives ~ +50 cm/s // set velocity proportional to stick movement +100 throttle gives ~ +50 cm/s
setVelocity = (rcCommand[THROTTLE] - initialThrottleHold) / 2; setVelocity = (rcCommand[THROTTLE] - initialThrottleHold) / 2;
@ -119,16 +119,34 @@ void updateAltHold(void)
void updateAltHoldState(void) void updateAltHoldState(void)
{ {
// Baro alt hold activate // Baro alt hold activate
if (rcOptions[BOXBARO]) { if (!rcOptions[BOXBARO]) {
if (!FLIGHT_MODE(BARO_MODE)) {
ENABLE_FLIGHT_MODE(BARO_MODE);
AltHold = EstAlt;
initialThrottleHold = rcCommand[THROTTLE];
errorVelocityI = 0;
BaroPID = 0;
}
} else {
DISABLE_FLIGHT_MODE(BARO_MODE); DISABLE_FLIGHT_MODE(BARO_MODE);
return;
}
if (!FLIGHT_MODE(BARO_MODE)) {
ENABLE_FLIGHT_MODE(BARO_MODE);
AltHold = EstAlt;
initialThrottleHold = rcCommand[THROTTLE];
errorVelocityI = 0;
BaroPID = 0;
}
}
void updateSonarAltHoldState(void)
{
// Sonar alt hold activate
if (!rcOptions[BOXSONAR]) {
DISABLE_FLIGHT_MODE(SONAR_MODE);
return;
}
if (!FLIGHT_MODE(SONAR_MODE)) {
ENABLE_FLIGHT_MODE(SONAR_MODE);
AltHold = EstAlt;
initialThrottleHold = rcCommand[THROTTLE];
errorVelocityI = 0;
BaroPID = 0; // TODO: Change naming of BaroPID to "AltPID" as this is used by both sonar and baro
} }
} }

View File

@ -18,4 +18,5 @@
void updateAltHold(void); void updateAltHold(void);
void updateAltHoldState(void); void updateAltHoldState(void);
void updateSonarAltHoldState(void);

View File

@ -372,7 +372,8 @@ int16_t calculateThrottleAngleCorrection(uint8_t throttle_correction_value)
return lrintf(throttle_correction_value * sinf(angle / (900.0f * M_PI / 2.0f))); return lrintf(throttle_correction_value * sinf(angle / (900.0f * M_PI / 2.0f)));
} }
#ifdef BARO #if defined(BARO) || defined(SONAR)
// 40hz update rate (20hz LPF on acc) // 40hz update rate (20hz LPF on acc)
#define BARO_UPDATE_FREQUENCY_40HZ (1000 * 25) #define BARO_UPDATE_FREQUENCY_40HZ (1000 * 25)
@ -453,6 +454,7 @@ void calculateEstimatedAltitude(uint32_t currentTime)
previousTime = currentTime; previousTime = currentTime;
#ifdef BARO
if (!isBaroCalibrationComplete()) { if (!isBaroCalibrationComplete()) {
performBaroCalibrationCycle(); performBaroCalibrationCycle();
vel = 0; vel = 0;
@ -460,6 +462,9 @@ void calculateEstimatedAltitude(uint32_t currentTime)
} }
BaroAlt = baroCalculateAltitude(); BaroAlt = baroCalculateAltitude();
#else
BaroAlt = 0;
#endif
#ifdef SONAR #ifdef SONAR
tiltAngle = calculateTiltAngle(&inclination); tiltAngle = calculateTiltAngle(&inclination);
@ -496,9 +501,11 @@ void calculateEstimatedAltitude(uint32_t currentTime)
accSum_reset(); accSum_reset();
#ifdef BARO
if (!isBaroCalibrationComplete()) { if (!isBaroCalibrationComplete()) {
return; return;
} }
#endif
if (sonarAlt > 0 && sonarAlt < 200) { if (sonarAlt > 0 && sonarAlt < 200) {
// the sonar has the best range // the sonar has the best range

View File

@ -40,6 +40,7 @@ typedef enum {
BOXOSD, BOXOSD,
BOXTELEMETRY, BOXTELEMETRY,
BOXAUTOTUNE, BOXAUTOTUNE,
BOXSONAR,
CHECKBOX_ITEM_COUNT CHECKBOX_ITEM_COUNT
} boxId_e; } boxId_e;

View File

@ -169,6 +169,7 @@ static const box_t const boxes[] = {
{ BOXOSD, "OSD SW;", 19 }, { BOXOSD, "OSD SW;", 19 },
{ BOXTELEMETRY, "TELEMETRY;", 20 }, { BOXTELEMETRY, "TELEMETRY;", 20 },
{ BOXAUTOTUNE, "AUTOTUNE;", 21 }, { BOXAUTOTUNE, "AUTOTUNE;", 21 },
{ BOXSONAR, "SONAR;", 22 },
{ CHECKBOX_ITEM_COUNT, NULL, 0xFF } { CHECKBOX_ITEM_COUNT, NULL, 0xFF }
}; };
@ -456,6 +457,11 @@ void mspInit(serialConfig_t *serialConfig)
activeBoxIds[activeBoxIdCount++] = BOXAUTOTUNE; activeBoxIds[activeBoxIdCount++] = BOXAUTOTUNE;
#endif #endif
if (feature(FEATURE_SONAR)){
activeBoxIds[activeBoxIdCount++] = BOXSONAR;
}
memset(mspPorts, 0x00, sizeof(mspPorts)); memset(mspPorts, 0x00, sizeof(mspPorts));
openAllMSPSerialPorts(serialConfig); openAllMSPSerialPorts(serialConfig);
@ -513,6 +519,7 @@ static bool processOutCommand(uint8_t cmdMSP)
rcOptions[BOXOSD] << BOXOSD | rcOptions[BOXOSD] << BOXOSD |
rcOptions[BOXTELEMETRY] << BOXTELEMETRY | rcOptions[BOXTELEMETRY] << BOXTELEMETRY |
rcOptions[BOXAUTOTUNE] << BOXAUTOTUNE | rcOptions[BOXAUTOTUNE] << BOXAUTOTUNE |
IS_ENABLED(FLIGHT_MODE(SONAR_MODE)) << BOXSONAR |
IS_ENABLED(ARMING_FLAG(ARMED)) << BOXARM; IS_ENABLED(ARMING_FLAG(ARMED)) << BOXARM;
for (i = 0; i < activeBoxIdCount; i++) { for (i = 0; i < activeBoxIdCount; i++) {
int flag = (tmp & (1 << activeBoxIds[i])); int flag = (tmp & (1 << activeBoxIds[i]));

View File

@ -377,10 +377,12 @@ typedef enum {
#endif #endif
#ifdef BARO #ifdef BARO
UPDATE_BARO_TASK, UPDATE_BARO_TASK,
CALCULATE_ALTITUDE_TASK,
#endif #endif
#ifdef SONAR #ifdef SONAR
UPDATE_SONAR_TASK, UPDATE_SONAR_TASK,
#endif
#if defined(BARO) || defined(SONAR)
CALCULATE_ALTITUDE_TASK,
#endif #endif
UPDATE_GPS_TASK, UPDATE_GPS_TASK,
UPDATE_DISPLAY_TASK UPDATE_DISPLAY_TASK
@ -408,9 +410,20 @@ void executePeriodicTasks(void)
baroUpdate(currentTime); baroUpdate(currentTime);
} }
break; break;
#endif
#if defined(BARO) || defined(SONAR)
case CALCULATE_ALTITUDE_TASK: case CALCULATE_ALTITUDE_TASK:
#if defined(BARO) && !defined(SONAR)
if (sensors(SENSOR_BARO) && isBaroReady()) { if (sensors(SENSOR_BARO) && isBaroReady()) {
#endif
#if defined(BARO) && defined(SONAR)
if ((sensors(SENSOR_BARO) && isBaroReady()) || sensors(SENSOR_SONAR)) {
#endif
#if !defined(BARO) && defined(SONAR)
if (sensors(SENSOR_SONAR)) {
#endif
calculateEstimatedAltitude(currentTime); calculateEstimatedAltitude(currentTime);
} }
break; break;
@ -558,7 +571,7 @@ void processRx(void)
void loop(void) void loop(void)
{ {
static uint32_t loopTime; static uint32_t loopTime;
#ifdef BARO #if defined(BARO) || defined(SONAR)
static bool haveProcessedAnnexCodeOnce = false; static bool haveProcessedAnnexCodeOnce = false;
#endif #endif
@ -575,6 +588,16 @@ void loop(void)
} }
} }
#endif #endif
#ifdef SONAR
// the 'annexCode' initialses rcCommand, updateAltHoldState depends on valid rcCommand data.
if (haveProcessedAnnexCodeOnce) {
if (sensors(SENSOR_SONAR)) {
updateSonarAltHoldState();
}
}
#endif
} else { } else {
// not processing rx this iteration // not processing rx this iteration
executePeriodicTasks(); executePeriodicTasks();
@ -592,7 +615,7 @@ void loop(void)
previousTime = currentTime; previousTime = currentTime;
annexCode(); annexCode();
#ifdef BARO #if defined(BARO) || defined(SONAR)
haveProcessedAnnexCodeOnce = true; haveProcessedAnnexCodeOnce = true;
#endif #endif
@ -606,13 +629,12 @@ void loop(void)
} }
#endif #endif
#ifdef BARO #if defined(BARO) || defined(SONAR)
if (sensors(SENSOR_BARO)) { if (sensors(SENSOR_BARO) || sensors(SENSOR_SONAR)) {
if (FLIGHT_MODE(BARO_MODE)) { if (FLIGHT_MODE(BARO_MODE) || FLIGHT_MODE(SONAR_MODE)) {
updateAltHold(); updateAltHold();
} }
} }
#endif #endif
if (currentProfile->throttle_correction_value && (FLIGHT_MODE(ANGLE_MODE) || FLIGHT_MODE(HORIZON_MODE))) { if (currentProfile->throttle_correction_value && (FLIGHT_MODE(ANGLE_MODE) || FLIGHT_MODE(HORIZON_MODE))) {

View File

@ -406,8 +406,8 @@ static void detectBaro()
return; return;
} }
#endif #endif
sensorsClear(SENSOR_BARO);
#endif #endif
sensorsClear(SENSOR_BARO);
} }
void reconfigureAlignment(sensorAlignmentConfig_t *sensorAlignmentConfig) void reconfigureAlignment(sensorAlignmentConfig_t *sensorAlignmentConfig)