Compare commits

...

2 Commits

Author SHA1 Message Date
Matthias Grob 43e6c411e3 FlightTaskAuto: remove WaypointType enum abstraction 2024-04-08 08:32:46 +02:00
Matthias Grob 32e66c0907 FlightTaskAuto: remove separate highEnoughForLandingGear function 2024-04-08 08:14:14 +02:00
2 changed files with 15 additions and 36 deletions
@@ -111,29 +111,29 @@ bool FlightTaskAuto::update()
// The only time a thrust set-point is sent out is during
// idle. Hence, reset thrust set-point to NAN in case the
// vehicle exits idle.
if (_type_previous == WaypointType::idle) {
if (_type_previous == position_setpoint_s::SETPOINT_TYPE_IDLE) {
_acceleration_setpoint.setNaN();
}
// during mission and reposition, raise the landing gears but only
// if altitude is high enough
if (_highEnoughForLandingGear()) {
if (_dist_to_ground > 2.f) {
_gear.landing_gear = landing_gear_s::GEAR_UP;
}
switch (_type) {
case WaypointType::idle:
case position_setpoint_s::SETPOINT_TYPE_IDLE:
// Send zero thrust setpoint
_position_setpoint.setNaN(); // Don't require any position/velocity setpoints
_velocity_setpoint.setNaN();
_acceleration_setpoint = Vector3f(0.f, 0.f, 100.f); // High downwards acceleration to make sure there's no thrust
break;
case WaypointType::land:
case position_setpoint_s::SETPOINT_TYPE_LAND:
_prepareLandSetpoints();
break;
case WaypointType::velocity:
case position_setpoint_s::SETPOINT_TYPE_VELOCITY:
// XY Velocity waypoint
// TODO : Rewiew that. What is the expected behavior?
_position_setpoint = Vector3f(NAN, NAN, _position(2));
@@ -141,14 +141,14 @@ bool FlightTaskAuto::update()
_velocity_setpoint(2) = NAN;
break;
case WaypointType::loiter:
case position_setpoint_s::SETPOINT_TYPE_LOITER:
if (_param_mpc_land_rc_help.get() && _sticks.checkAndUpdateStickInputs()) {
rcHelpModifyYaw(_yaw_setpoint);
}
// FALLTHROUGH
case WaypointType::takeoff:
case WaypointType::position:
case position_setpoint_s::SETPOINT_TYPE_TAKEOFF:
case position_setpoint_s::SETPOINT_TYPE_POSITION:
default:
// Simple waypoint navigation: go to xyz target, with standard limitations
_position_setpoint = _target;
@@ -243,7 +243,7 @@ void FlightTaskAuto::_prepareLandSetpoints()
vertical_speed = _param_mpc_land_crawl_speed.get();
}
if (_type_previous != WaypointType::land) {
if (_type_previous != position_setpoint_s::SETPOINT_TYPE_LAND) {
// initialize yaw and xy-position
_land_heading = _yaw_setpoint;
_stick_acceleration_xy.resetPosition(Vector2f(_target(0), _target(1)));
@@ -360,7 +360,7 @@ bool FlightTaskAuto::_evaluateTriplets()
if (!_sub_triplet_setpoint.get().current.valid || !PX4_ISFINITE(_sub_triplet_setpoint.get().current.alt)) {
// Best we can do is to just set all waypoints to current state
_prev_prev_wp = _triplet_prev_wp = _triplet_target = _triplet_next_wp = _position;
_type = WaypointType::loiter;
_type = position_setpoint_s::SETPOINT_TYPE_LOITER;
_yaw_setpoint = _yaw;
_yawspeed_setpoint = NAN;
_target_acceptance_radius = _sub_triplet_setpoint.get().current.acceptance_radius;
@@ -368,7 +368,7 @@ bool FlightTaskAuto::_evaluateTriplets()
return true;
}
_type = (WaypointType)_sub_triplet_setpoint.get().current.type;
_type = _sub_triplet_setpoint.get().current.type;
// Prioritize cruise speed from the triplet when it's valid and more recent than the previously commanded cruise speed
const float cruise_speed_from_triplet = _sub_triplet_setpoint.get().current.cruising_speed;
@@ -456,7 +456,7 @@ bool FlightTaskAuto::_evaluateTriplets()
_prev_was_valid = _sub_triplet_setpoint.get().previous.valid;
if (_type == WaypointType::loiter) {
if (_type == position_setpoint_s::SETPOINT_TYPE_LOITER) {
_triplet_next_wp = _triplet_target;
} else if (_isFinite(_sub_triplet_setpoint.get().next) && _sub_triplet_setpoint.get().next.valid) {
@@ -826,7 +826,7 @@ void FlightTaskAuto::_updateTrajConstraints()
// until the constraints don't do things like cause controller integrators to saturate. Once the controller
// doesn't use z speed constraints, this can go in _prepareTakeoffSetpoints(). Accel limit is to
// emulate the motor ramp (also done in the controller) so that the controller can actually track the setpoint.
if (_type == WaypointType::takeoff && _dist_to_ground < _param_mpc_land_alt1.get()) {
if (_type == position_setpoint_s::SETPOINT_TYPE_TAKEOFF && _dist_to_ground < _param_mpc_land_alt1.get()) {
z_vel_constraint = _param_mpc_tko_speed.get();
z_accel_constraint = math::min(z_accel_constraint, _param_mpc_tko_speed.get() / _param_mpc_tko_ramp_t.get());
@@ -850,12 +850,6 @@ void FlightTaskAuto::_updateTrajConstraints()
_constraints.speed_up = math::max(_constraints.speed_up, 1.2f * _param_mpc_z_v_auto_up.get());;
}
bool FlightTaskAuto::_highEnoughForLandingGear()
{
// return true if altitude is above two meters
return _dist_to_ground > 2.0f;
}
void FlightTaskAuto::updateParams()
{
FlightTask::updateParams();
@@ -60,20 +60,6 @@
#include <lib/avoidance/ObstacleAvoidance.hpp>
#endif
/**
* This enum has to agree with position_setpoint_s type definition
* The only reason for not using the struct position_setpoint is because
* of the size
*/
enum class WaypointType : int {
position = position_setpoint_s::SETPOINT_TYPE_POSITION,
velocity = position_setpoint_s::SETPOINT_TYPE_VELOCITY,
loiter = position_setpoint_s::SETPOINT_TYPE_LOITER,
takeoff = position_setpoint_s::SETPOINT_TYPE_TAKEOFF,
land = position_setpoint_s::SETPOINT_TYPE_LAND,
idle = position_setpoint_s::SETPOINT_TYPE_IDLE
};
enum class State {
offtrack, /**< Vehicle is more than cruise speed away from track */
target_behind, /**< Vehicle is in front of target. */
@@ -115,7 +101,6 @@ protected:
bool _checkTakeoff() override { return _want_takeoff; };
void _prepareLandSetpoints();
bool _highEnoughForLandingGear(); /**< Checks if gears can be lowered. */
void updateParams() override; /**< See ModuleParam class */
@@ -126,7 +111,8 @@ protected:
matrix::Vector3f _next_wp{}; /**< The next waypoint after target (local frame). If no next setpoint is available, next is set to target. */
bool _next_was_valid{false};
float _mc_cruise_speed{NAN}; /**< Requested cruise speed. If not valid, default cruise speed is used. */
WaypointType _type{WaypointType::idle}; /**< Type of current target triplet. */
uint8_t _type{position_setpoint_s::SETPOINT_TYPE_IDLE}; ///< Type of current target triplet
uint8_t _type_previous{position_setpoint_s::SETPOINT_TYPE_IDLE}; ///< Previous type of current target triplet
uORB::SubscriptionData<home_position_s> _sub_home_position{ORB_ID(home_position)};
uORB::SubscriptionData<vehicle_status_s> _sub_vehicle_status{ORB_ID(vehicle_status)};
@@ -147,7 +133,6 @@ protected:
StickYaw _stick_yaw{this};
matrix::Vector3f _land_position;
float _land_heading;
WaypointType _type_previous{WaypointType::idle}; /**< Previous type of current target triplet. */
bool _is_emergency_braking_active{false};
bool _want_takeoff{false};