mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-29 22:43:35 +08:00
mtecs: make sure dt is calculated before any control calculations
This commit is contained in:
@@ -60,6 +60,7 @@ mTecs::mTecs() :
|
|||||||
_pitchSp(0.0f),
|
_pitchSp(0.0f),
|
||||||
timestampLastIteration(hrt_absolute_time()),
|
timestampLastIteration(hrt_absolute_time()),
|
||||||
_firstIterationAfterReset(true),
|
_firstIterationAfterReset(true),
|
||||||
|
dtCalculated(false),
|
||||||
_counter(0)
|
_counter(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -71,6 +72,9 @@ mTecs::~mTecs()
|
|||||||
void mTecs::updateAltitudeSpeed(float flightPathAngle, float altitude, float altitudeSp, float airspeed, float airspeedSp)
|
void mTecs::updateAltitudeSpeed(float flightPathAngle, float altitude, float altitudeSp, float airspeed, float airspeedSp)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/* time measurement */
|
||||||
|
updateTimeMeasurement();
|
||||||
|
|
||||||
float flightPathAngleSp = _controlAltitude.update(altitudeSp - altitude);
|
float flightPathAngleSp = _controlAltitude.update(altitudeSp - altitude);
|
||||||
if (_counter % 10 == 0) {
|
if (_counter % 10 == 0) {
|
||||||
warnx("***");
|
warnx("***");
|
||||||
@@ -81,6 +85,9 @@ void mTecs::updateAltitudeSpeed(float flightPathAngle, float altitude, float alt
|
|||||||
|
|
||||||
void mTecs::updateFlightPathAngleSpeed(float flightPathAngle, float flightPathAngleSp, float airspeed, float airspeedSp) {
|
void mTecs::updateFlightPathAngleSpeed(float flightPathAngle, float flightPathAngleSp, float airspeed, float airspeedSp) {
|
||||||
|
|
||||||
|
/* time measurement */
|
||||||
|
updateTimeMeasurement();
|
||||||
|
|
||||||
float accelerationLongitudinalSp = _controlAirSpeed.update(airspeedSp - airspeed);
|
float accelerationLongitudinalSp = _controlAirSpeed.update(airspeedSp - airspeed);
|
||||||
if (_counter % 10 == 0) {
|
if (_counter % 10 == 0) {
|
||||||
warnx("updateFlightPathAngleSpeed airspeedSp %.4f, airspeed %.4f, accelerationLongitudinalSp%.4f", (double)airspeedSp, (double)airspeed, (double)accelerationLongitudinalSp);
|
warnx("updateFlightPathAngleSpeed airspeedSp %.4f, airspeed %.4f, accelerationLongitudinalSp%.4f", (double)airspeedSp, (double)airspeed, (double)accelerationLongitudinalSp);
|
||||||
@@ -91,13 +98,7 @@ void mTecs::updateFlightPathAngleSpeed(float flightPathAngle, float flightPathAn
|
|||||||
void mTecs::updateFlightPathAngleAcceleration(float flightPathAngle, float flightPathAngleSp, float airspeed, float accelerationLongitudinalSp)
|
void mTecs::updateFlightPathAngleAcceleration(float flightPathAngle, float flightPathAngleSp, float airspeed, float accelerationLongitudinalSp)
|
||||||
{
|
{
|
||||||
/* time measurement */
|
/* time measurement */
|
||||||
float deltaTSeconds = 0.0f;
|
updateTimeMeasurement();
|
||||||
if (!_firstIterationAfterReset) {
|
|
||||||
hrt_abstime timestampNow = hrt_absolute_time();
|
|
||||||
deltaTSeconds = (float)(timestampNow - timestampLastIteration) * 1e-6f;
|
|
||||||
timestampLastIteration = timestampNow;
|
|
||||||
}
|
|
||||||
setDt(deltaTSeconds);
|
|
||||||
|
|
||||||
/* update parameters first */
|
/* update parameters first */
|
||||||
updateParams();
|
updateParams();
|
||||||
@@ -147,6 +148,7 @@ void mTecs::updateFlightPathAngleAcceleration(float flightPathAngle, float fligh
|
|||||||
|
|
||||||
/* clean up */
|
/* clean up */
|
||||||
_firstIterationAfterReset = false;
|
_firstIterationAfterReset = false;
|
||||||
|
dtCalculated = false;
|
||||||
|
|
||||||
_counter++;
|
_counter++;
|
||||||
}
|
}
|
||||||
@@ -159,5 +161,20 @@ void mTecs::resetIntegrators()
|
|||||||
_firstIterationAfterReset = true;
|
_firstIterationAfterReset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace fwPosctrl */
|
} /* namespace fwPosctrl */
|
||||||
|
|
||||||
|
|||||||
@@ -104,9 +104,15 @@ protected:
|
|||||||
/* Time measurements */
|
/* Time measurements */
|
||||||
hrt_abstime timestampLastIteration; /**< Saves the result of hrt_absolute_time() of the last iteration */
|
hrt_abstime timestampLastIteration; /**< Saves the result of hrt_absolute_time() of the last iteration */
|
||||||
|
|
||||||
bool _firstIterationAfterReset; /**< True during the first iteration after a reset */
|
bool _firstIterationAfterReset; /**< True during the first iteration after a reset */
|
||||||
|
bool dtCalculated; /**< True if dt has been calculated in this iteration */
|
||||||
|
|
||||||
int _counter;
|
int _counter;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Measure and update the time step dt if this was not already done in the current iteration
|
||||||
|
*/
|
||||||
|
void updateTimeMeasurement();
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace fwPosctrl */
|
} /* namespace fwPosctrl */
|
||||||
|
|||||||
Reference in New Issue
Block a user