mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-26 01:17:51 +08:00
FlightTaskAutoLine: move altitude above ground computaiton to method
This commit is contained in:
committed by
Lorenz Meier
parent
3ea0a53192
commit
c637ccb65f
@@ -55,21 +55,11 @@ bool FlightTaskAutoLine::update()
|
|||||||
// always reset constraints because they might change depending on the type
|
// always reset constraints because they might change depending on the type
|
||||||
_setDefaultConstraints();
|
_setDefaultConstraints();
|
||||||
|
|
||||||
|
_updateAltitudeAboveGround();
|
||||||
|
|
||||||
bool follow_line = _type == WaypointType::loiter || _type == WaypointType::position;
|
bool follow_line = _type == WaypointType::loiter || _type == WaypointType::position;
|
||||||
bool follow_line_prev = _type_previous == WaypointType::loiter || _type_previous == WaypointType::position;
|
bool follow_line_prev = _type_previous == WaypointType::loiter || _type_previous == WaypointType::position;
|
||||||
|
|
||||||
// Altitude above ground is by default just the negation of the current local position in D-direction.
|
|
||||||
_alt_above_ground = -_position(2);
|
|
||||||
|
|
||||||
if (PX4_ISFINITE(_dist_to_bottom)) {
|
|
||||||
// We have a valid distance to ground measurement
|
|
||||||
_alt_above_ground = _dist_to_bottom;
|
|
||||||
|
|
||||||
} else if (_sub_home_position->get().valid_alt) {
|
|
||||||
// if home position is set, then altitude above ground is relative to the home position
|
|
||||||
_alt_above_ground = -_position(2) + _sub_home_position->get().z;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1st time that vehicle starts to follow line. Reset all setpoints to current vehicle state.
|
// 1st time that vehicle starts to follow line. Reset all setpoints to current vehicle state.
|
||||||
if (follow_line && !follow_line_prev) {
|
if (follow_line && !follow_line_prev) {
|
||||||
_reset();
|
_reset();
|
||||||
@@ -521,6 +511,21 @@ float FlightTaskAutoLine::_getVelocityFromAngle(const float angle)
|
|||||||
return math::constrain(speed_close, min_cruise_speed, _mc_cruise_speed);
|
return math::constrain(speed_close, min_cruise_speed, _mc_cruise_speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FlightTaskAutoLine::_updateAltitudeAboveGround()
|
||||||
|
{
|
||||||
|
// Altitude above ground is by default just the negation of the current local position in D-direction.
|
||||||
|
_alt_above_ground = -_position(2);
|
||||||
|
|
||||||
|
if (PX4_ISFINITE(_dist_to_bottom)) {
|
||||||
|
// We have a valid distance to ground measurement
|
||||||
|
_alt_above_ground = _dist_to_bottom;
|
||||||
|
|
||||||
|
} else if (_sub_home_position->get().valid_alt) {
|
||||||
|
// if home position is set, then altitude above ground is relative to the home position
|
||||||
|
_alt_above_ground = -_position(2) + _sub_home_position->get().z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FlightTaskAutoLine::updateParams()
|
void FlightTaskAutoLine::updateParams()
|
||||||
{
|
{
|
||||||
FlightTaskAuto::updateParams();
|
FlightTaskAuto::updateParams();
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ protected:
|
|||||||
void _updateInternalWaypoints(); /* Depending on state of vehicle, the internal waypoints might differ from target (for instance if offtrack). */
|
void _updateInternalWaypoints(); /* Depending on state of vehicle, the internal waypoints might differ from target (for instance if offtrack). */
|
||||||
void _generateSetpoints(); /**< Generate velocity and position setpoint for following line. */
|
void _generateSetpoints(); /**< Generate velocity and position setpoint for following line. */
|
||||||
void _generateAltitudeSetpoints(); /**< Generate velocity and position setpoints for following line along z. */
|
void _generateAltitudeSetpoints(); /**< Generate velocity and position setpoints for following line along z. */
|
||||||
|
void _updateAltitudeAboveGround(); /**< Computes altitude above ground based on sensors available. */
|
||||||
void _generateXYsetpoints(); /**< Generate velocity and position setpoints for following line along xy. */
|
void _generateXYsetpoints(); /**< Generate velocity and position setpoints for following line along xy. */
|
||||||
void updateParams() override; /**< See ModuleParam class */
|
void updateParams() override; /**< See ModuleParam class */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user