fw_pos_ctrl_l1 var naming consistency and effc++

This commit is contained in:
Daniel Agar
2016-07-12 13:45:32 -04:00
committed by Lorenz Meier
parent ebce725720
commit de14418e93
14 changed files with 256 additions and 171 deletions
+1
View File
@@ -23,6 +23,7 @@ find \
src/modules/controllib_test \ src/modules/controllib_test \
src/modules/dataman \ src/modules/dataman \
src/modules/fw_att_control \ src/modules/fw_att_control \
src/modules/fw_pos_control_l1 \
src/modules/gpio_led \ src/modules/gpio_led \
src/modules/land_detector \ src/modules/land_detector \
src/modules/local_position_estimator \ src/modules/local_position_estimator \
+3
View File
@@ -78,6 +78,9 @@ class BlockParam : public BlockParamBase
public: public:
BlockParam(Block *block, const char *name, BlockParam(Block *block, const char *name,
bool parent_prefix = true, T *extern_address = NULL); bool parent_prefix = true, T *extern_address = NULL);
BlockParam(const BlockParam &) = delete;
BlockParam &operator=(const BlockParam &) = delete;
T get(); T get();
void commit(); void commit();
void set(T val); void set(T val);
+2
View File
@@ -66,6 +66,8 @@ public:
_TASmin(3.0f), _TASmin(3.0f),
_TAS_dem(0.0f), _TAS_dem(0.0f),
_TAS_dem_last(0.0f), _TAS_dem_last(0.0f),
_EAS_dem(0.0f),
_hgt_dem(0.0f),
_hgt_dem_in_old(0.0f), _hgt_dem_in_old(0.0f),
_hgt_dem_adj(0.0f), _hgt_dem_adj(0.0f),
_hgt_dem_adj_last(0.0f), _hgt_dem_adj_last(0.0f),
+4 -2
View File
@@ -55,7 +55,10 @@ class __EXPORT LaunchDetector : public control::SuperBlock
{ {
public: public:
LaunchDetector(); LaunchDetector();
~LaunchDetector(); LaunchDetector(const LaunchDetector &) = delete;
LaunchDetector operator=(const LaunchDetector &) = delete;
virtual ~LaunchDetector();
void reset(); void reset();
void update(float accel_x); void update(float accel_x);
@@ -80,7 +83,6 @@ private:
control::BlockParamInt launchdetection_on; control::BlockParamInt launchdetection_on;
control::BlockParamFloat throttlePreTakeoff; control::BlockParamFloat throttlePreTakeoff;
}; };
} }
+2
View File
@@ -58,6 +58,8 @@ enum LaunchDetectionResult {
class LaunchMethod class LaunchMethod
{ {
public: public:
virtual ~LaunchMethod() {};
virtual void update(float accel_x) = 0; virtual void update(float accel_x) = 0;
virtual LaunchDetectionResult getLaunchDetected() const = 0; virtual LaunchDetectionResult getLaunchDetected() const = 0;
virtual void reset() = 0; virtual void reset() = 0;
+1 -1
View File
@@ -35,7 +35,7 @@ px4_add_module(
MAIN fw_pos_control_l1 MAIN fw_pos_control_l1
STACK_MAIN 1200 STACK_MAIN 1200
COMPILE_FLAGS COMPILE_FLAGS
-Os -Os -Weffc++
SRCS SRCS
fw_pos_control_l1_main.cpp fw_pos_control_l1_main.cpp
landingslope.cpp landingslope.cpp
File diff suppressed because it is too large Load Diff
@@ -46,6 +46,19 @@
#include <unistd.h> #include <unistd.h>
#include <mathlib/mathlib.h> #include <mathlib/mathlib.h>
Landingslope::Landingslope() :
_landing_slope_angle_rad(0.0f),
_flare_relative_alt(0.0f),
_motor_lim_relative_alt(0.0f),
_H1_virt(0.0f),
_H0(0.0f),
_d1(0.0f),
_flare_constant(0.0f),
_flare_length(0.0f),
_horizontal_slope_displacement(0.0f)
{
}
void Landingslope::update(float landing_slope_angle_rad_new, void Landingslope::update(float landing_slope_angle_rad_new,
float flare_relative_alt_new, float flare_relative_alt_new,
float motor_lim_relative_alt_new, float motor_lim_relative_alt_new,
+1 -1
View File
@@ -60,7 +60,7 @@ private:
void calculateSlopeValues(); void calculateSlopeValues();
public: public:
Landingslope() {} Landingslope();
~Landingslope() {} ~Landingslope() {}
@@ -41,7 +41,8 @@
#include "limitoverride.h" #include "limitoverride.h"
namespace fwPosctrl { namespace fwPosctrl
{
bool LimitOverride::applyOverride(BlockOutputLimiter &outputLimiterThrottle, bool LimitOverride::applyOverride(BlockOutputLimiter &outputLimiterThrottle,
BlockOutputLimiter &outputLimiterPitch) BlockOutputLimiter &outputLimiterPitch)
@@ -52,14 +53,17 @@ bool LimitOverride::applyOverride(BlockOutputLimiter &outputLimiterThrottle,
outputLimiterThrottle.setMin(overrideThrottleMin); outputLimiterThrottle.setMin(overrideThrottleMin);
ret = true; ret = true;
} }
if (overrideThrottleMaxEnabled) { if (overrideThrottleMaxEnabled) {
outputLimiterThrottle.setMax(overrideThrottleMax); outputLimiterThrottle.setMax(overrideThrottleMax);
ret = true; ret = true;
} }
if (overridePitchMinEnabled) { if (overridePitchMinEnabled) {
outputLimiterPitch.setMin(overridePitchMin); outputLimiterPitch.setMin(overridePitchMin);
ret = true; ret = true;
} }
if (overridePitchMaxEnabled) { if (overridePitchMaxEnabled) {
outputLimiterPitch.setMax(overridePitchMax); outputLimiterPitch.setMax(overridePitchMax);
ret = true; ret = true;
@@ -72,17 +72,29 @@ public:
BlockOutputLimiter &outputLimiterPitch); BlockOutputLimiter &outputLimiterPitch);
/* Functions to enable or disable the override */ /* Functions to enable or disable the override */
void enableThrottleMinOverride(float value) { enable(&overrideThrottleMinEnabled, void enableThrottleMinOverride(float value)
&overrideThrottleMin, value); } {
enable(&overrideThrottleMinEnabled,
&overrideThrottleMin, value);
}
void disableThrottleMinOverride() { disable(&overrideThrottleMinEnabled); } void disableThrottleMinOverride() { disable(&overrideThrottleMinEnabled); }
void enableThrottleMaxOverride(float value) { enable(&overrideThrottleMaxEnabled, void enableThrottleMaxOverride(float value)
&overrideThrottleMax, value); } {
enable(&overrideThrottleMaxEnabled,
&overrideThrottleMax, value);
}
void disableThrottleMaxOverride() { disable(&overrideThrottleMaxEnabled); } void disableThrottleMaxOverride() { disable(&overrideThrottleMaxEnabled); }
void enablePitchMinOverride(float value) { enable(&overridePitchMinEnabled, void enablePitchMinOverride(float value)
&overridePitchMin, value); } {
enable(&overridePitchMinEnabled,
&overridePitchMin, value);
}
void disablePitchMinOverride() { disable(&overridePitchMinEnabled); } void disablePitchMinOverride() { disable(&overridePitchMinEnabled); }
void enablePitchMaxOverride(float value) { enable(&overridePitchMaxEnabled, void enablePitchMaxOverride(float value)
&overridePitchMax, value); } {
enable(&overridePitchMaxEnabled,
&overridePitchMax, value);
}
void disablePitchMaxOverride() { disable(&overridePitchMaxEnabled); } void disablePitchMaxOverride() { disable(&overridePitchMaxEnabled); }
protected: protected:
+20 -6
View File
@@ -44,7 +44,8 @@
#include <lib/geo/geo.h> #include <lib/geo/geo.h>
#include <stdio.h> #include <stdio.h>
namespace fwPosctrl { namespace fwPosctrl
{
mTecs::mTecs() : mTecs::mTecs() :
SuperBlock(NULL, "MT"), SuperBlock(NULL, "MT"),
@@ -106,7 +107,8 @@ int mTecs::updateAltitudeSpeed(float flightPathAngle, float altitude, float alti
/* Debug output */ /* Debug output */
if (_counter % 10 == 0) { if (_counter % 10 == 0) {
debug("***"); debug("***");
debug("updateAltitudeSpeed: altitudeSp %.4f, altitude %.4f, altitude filtered %.4f, flightPathAngleSp %.4f", (double)altitudeSp, (double)altitude, (double)altitudeFiltered, (double)flightPathAngleSp); debug("updateAltitudeSpeed: altitudeSp %.4f, altitude %.4f, altitude filtered %.4f, flightPathAngleSp %.4f",
(double)altitudeSp, (double)altitude, (double)altitudeFiltered, (double)flightPathAngleSp);
} }
#if defined(__PX4_NUTTX) #if defined(__PX4_NUTTX)
@@ -167,6 +169,7 @@ int mTecs::updateFlightPathAngleAcceleration(float flightPathAngle, float flight
!PX4_ISFINITE(airspeedFiltered) || !PX4_ISFINITE(accelerationLongitudinalSp) || !PX4_ISFINITE(mode)) { !PX4_ISFINITE(airspeedFiltered) || !PX4_ISFINITE(accelerationLongitudinalSp) || !PX4_ISFINITE(mode)) {
return -1; return -1;
} }
/* time measurement */ /* time measurement */
updateTimeMeasurement(); updateTimeMeasurement();
@@ -179,9 +182,11 @@ int mTecs::updateFlightPathAngleAcceleration(float flightPathAngle, float flight
/* calculate values (energies) */ /* calculate values (energies) */
float flightPathAngleError = flightPathAngleSp - flightPathAngleFiltered; float flightPathAngleError = flightPathAngleSp - flightPathAngleFiltered;
float airspeedDerivative = 0.0f; float airspeedDerivative = 0.0f;
if(_airspeedDerivative.getDt() > 0.0f) {
if (_airspeedDerivative.getDt() > 0.0f) {
airspeedDerivative = _airspeedDerivative.update(airspeedFiltered); airspeedDerivative = _airspeedDerivative.update(airspeedFiltered);
} }
float airspeedDerivativeNorm = airspeedDerivative / CONSTANTS_ONE_G; float airspeedDerivativeNorm = airspeedDerivative / CONSTANTS_ONE_G;
float airspeedDerivativeSp = accelerationLongitudinalSp; float airspeedDerivativeSp = accelerationLongitudinalSp;
float airspeedDerivativeNormSp = airspeedDerivativeSp / CONSTANTS_ONE_G; float airspeedDerivativeNormSp = airspeedDerivativeSp / CONSTANTS_ONE_G;
@@ -200,9 +205,11 @@ int mTecs::updateFlightPathAngleAcceleration(float flightPathAngle, float flight
/* Debug output */ /* Debug output */
if (_counter % 10 == 0) { if (_counter % 10 == 0) {
debug("totalEnergyRateSp %.2f, totalEnergyRate %.2f, totalEnergyRateError %.2f totalEnergyRateError2 %.2f airspeedDerivativeNorm %.4f", debug("totalEnergyRateSp %.2f, totalEnergyRate %.2f, totalEnergyRateError %.2f totalEnergyRateError2 %.2f airspeedDerivativeNorm %.4f",
(double)totalEnergyRateSp, (double)totalEnergyRate, (double)totalEnergyRateError, (double)totalEnergyRateError2, (double)airspeedDerivativeNorm); (double)totalEnergyRateSp, (double)totalEnergyRate, (double)totalEnergyRateError, (double)totalEnergyRateError2,
(double)airspeedDerivativeNorm);
debug("energyDistributionRateSp %.2f, energyDistributionRate %.2f, energyDistributionRateError %.2f energyDistributionRateError2 %.2f", debug("energyDistributionRateSp %.2f, energyDistributionRate %.2f, energyDistributionRateError %.2f energyDistributionRateError2 %.2f",
(double)energyDistributionRateSp, (double)energyDistributionRate, (double)energyDistributionRateError, (double)energyDistributionRateError2); (double)energyDistributionRateSp, (double)energyDistributionRate, (double)energyDistributionRateError,
(double)energyDistributionRateError2);
} }
/* Check airspeed: if below safe value switch to underspeed mode (if not in land or takeoff mode) */ /* Check airspeed: if below safe value switch to underspeed mode (if not in land or takeoff mode) */
@@ -213,15 +220,19 @@ int mTecs::updateFlightPathAngleAcceleration(float flightPathAngle, float flight
/* Set special output limiters if we are not in MTECS_MODE_NORMAL */ /* Set special output limiters if we are not in MTECS_MODE_NORMAL */
BlockOutputLimiter *outputLimiterThrottle = &_controlTotalEnergy.getOutputLimiter(); BlockOutputLimiter *outputLimiterThrottle = &_controlTotalEnergy.getOutputLimiter();
BlockOutputLimiter *outputLimiterPitch = &_controlEnergyDistribution.getOutputLimiter(); BlockOutputLimiter *outputLimiterPitch = &_controlEnergyDistribution.getOutputLimiter();
if (mode == MTECS_MODE_TAKEOFF) { if (mode == MTECS_MODE_TAKEOFF) {
outputLimiterThrottle = &_BlockOutputLimiterTakeoffThrottle; outputLimiterThrottle = &_BlockOutputLimiterTakeoffThrottle;
outputLimiterPitch = &_BlockOutputLimiterTakeoffPitch; outputLimiterPitch = &_BlockOutputLimiterTakeoffPitch;
} else if (mode == MTECS_MODE_LAND) { } else if (mode == MTECS_MODE_LAND) {
// only limit pitch but do not limit throttle // only limit pitch but do not limit throttle
outputLimiterPitch = &_BlockOutputLimiterLandPitch; outputLimiterPitch = &_BlockOutputLimiterLandPitch;
} else if (mode == MTECS_MODE_LAND_THROTTLELIM) { } else if (mode == MTECS_MODE_LAND_THROTTLELIM) {
outputLimiterThrottle = &_BlockOutputLimiterLandThrottle; outputLimiterThrottle = &_BlockOutputLimiterLandThrottle;
outputLimiterPitch = &_BlockOutputLimiterLandPitch; outputLimiterPitch = &_BlockOutputLimiterLandPitch;
} else if (mode == MTECS_MODE_UNDERSPEED) { } else if (mode == MTECS_MODE_UNDERSPEED) {
outputLimiterThrottle = &_BlockOutputLimiterUnderspeedThrottle; outputLimiterThrottle = &_BlockOutputLimiterUnderspeedThrottle;
outputLimiterPitch = &_BlockOutputLimiterUnderspeedPitch; outputLimiterPitch = &_BlockOutputLimiterUnderspeedPitch;
@@ -293,11 +304,13 @@ void mTecs::updateTimeMeasurement()
{ {
if (!_dtCalculated) { if (!_dtCalculated) {
float deltaTSeconds = 0.0f; float deltaTSeconds = 0.0f;
if (!_firstIterationAfterReset) { if (!_firstIterationAfterReset) {
hrt_abstime timestampNow = hrt_absolute_time(); hrt_abstime timestampNow = hrt_absolute_time();
deltaTSeconds = (float)(timestampNow - timestampLastIteration) * 1e-6f; deltaTSeconds = (float)(timestampNow - timestampLastIteration) * 1e-6f;
timestampLastIteration = timestampNow; timestampLastIteration = timestampNow;
} }
setDt(deltaTSeconds); setDt(deltaTSeconds);
_dtCalculated = true; _dtCalculated = true;
@@ -312,7 +325,8 @@ void mTecs::debug_print(const char *fmt, va_list args)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
void mTecs::debug(const char *fmt, ...) { void mTecs::debug(const char *fmt, ...)
{
if (!_debug) { if (!_debug) {
return; return;
@@ -71,18 +71,22 @@ public:
* otherwise unchanged * otherwise unchanged
* @return: true if the limit is applied, false otherwise * @return: true if the limit is applied, false otherwise
*/ */
bool limit(float& value, float& difference) { bool limit(float &value, float &difference)
{
float minimum = getIsAngularLimit() ? getMin() * M_DEG_TO_RAD_F : getMin(); float minimum = getIsAngularLimit() ? getMin() * M_DEG_TO_RAD_F : getMin();
float maximum = getIsAngularLimit() ? getMax() * M_DEG_TO_RAD_F : getMax(); float maximum = getIsAngularLimit() ? getMax() * M_DEG_TO_RAD_F : getMax();
if (value < minimum) { if (value < minimum) {
difference = value - minimum; difference = value - minimum;
value = minimum; value = minimum;
return true; return true;
} else if (value > maximum) { } else if (value > maximum) {
difference = value - maximum; difference = value - maximum;
value = maximum; value = maximum;
return true; return true;
} }
return false; return false;
} }
//accessor: //accessor:
@@ -126,15 +130,18 @@ protected:
BlockOutputLimiter _outputLimiter; BlockOutputLimiter _outputLimiter;
float calcUnlimitedOutput(float inputValue, float inputError) {return getOffset() + getKFF() * inputValue + getKP() * inputError + getKI() * getIntegral().update(inputError);} float calcUnlimitedOutput(float inputValue, float inputError) {return getOffset() + getKFF() * inputValue + getKP() * inputError + getKI() * getIntegral().update(inputError);}
float calcLimitedOutput(float inputValue, float inputError, BlockOutputLimiter &outputLimiter) { float calcLimitedOutput(float inputValue, float inputError, BlockOutputLimiter &outputLimiter)
{
float difference = 0.0f; float difference = 0.0f;
float integralYPrevious = _integral.getY(); float integralYPrevious = _integral.getY();
float output = calcUnlimitedOutput(inputValue, inputError); float output = calcUnlimitedOutput(inputValue, inputError);
if(outputLimiter.limit(output, difference) &&
if (outputLimiter.limit(output, difference) &&
(((difference < 0) && (getKI() * getIntegral().getY() < 0)) || (((difference < 0) && (getKI() * getIntegral().getY() < 0)) ||
((difference > 0) && (getKI() * getIntegral().getY() > 0)))) { ((difference > 0) && (getKI() * getIntegral().getY() > 0)))) {
getIntegral().setY(integralYPrevious); getIntegral().setY(integralYPrevious);
} }
return output; return output;
} }
private: private:
@@ -154,7 +161,8 @@ public:
BlockFFPILimited(parent, name, isAngularLimit) BlockFFPILimited(parent, name, isAngularLimit)
{}; {};
virtual ~BlockFFPILimitedCustom() {}; virtual ~BlockFFPILimitedCustom() {};
float update(float inputValue, float inputError, BlockOutputLimiter *outputLimiter = NULL) { float update(float inputValue, float inputError, BlockOutputLimiter *outputLimiter = NULL)
{
return calcLimitedOutput(inputValue, inputError, outputLimiter == NULL ? _outputLimiter : *outputLimiter); return calcLimitedOutput(inputValue, inputError, outputLimiter == NULL ? _outputLimiter : *outputLimiter);
} }
}; };
@@ -170,7 +178,8 @@ public:
_outputLimiter(this, "", isAngularLimit) _outputLimiter(this, "", isAngularLimit)
{}; {};
virtual ~BlockPLimited() {}; virtual ~BlockPLimited() {};
float update(float input) { float update(float input)
{
float difference = 0.0f; float difference = 0.0f;
float output = getKP() * input; float output = getKP() * input;
getOutputLimiter().limit(output, difference); getOutputLimiter().limit(output, difference);
@@ -197,7 +206,8 @@ public:
_outputLimiter(this, "", isAngularLimit) _outputLimiter(this, "", isAngularLimit)
{}; {};
virtual ~BlockPDLimited() {}; virtual ~BlockPDLimited() {};
float update(float input) { float update(float input)
{
float difference = 0.0f; float difference = 0.0f;
float output = getKP() * input + (getDerivative().getDt() > 0.0f ? getKD() * getDerivative().update(input) : 0.0f); float output = getKP() * input + (getDerivative().getDt() > 0.0f ? getKD() * getDerivative().update(input) : 0.0f);
getOutputLimiter().limit(output, difference); getOutputLimiter().limit(output, difference);
+2
View File
@@ -82,6 +82,8 @@ class VtolType
public: public:
VtolType(VtolAttitudeControl *att_controller); VtolType(VtolAttitudeControl *att_controller);
VtolType(const VtolType &) = delete;
VtolType &operator=(const VtolType &) = delete;
virtual ~VtolType(); virtual ~VtolType();