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