mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-24 15:20:34 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 43e6c411e3 | |||
| 32e66c0907 |
@@ -111,29 +111,29 @@ bool FlightTaskAuto::update()
|
|||||||
// The only time a thrust set-point is sent out is during
|
// The only time a thrust set-point is sent out is during
|
||||||
// idle. Hence, reset thrust set-point to NAN in case the
|
// idle. Hence, reset thrust set-point to NAN in case the
|
||||||
// vehicle exits idle.
|
// vehicle exits idle.
|
||||||
if (_type_previous == WaypointType::idle) {
|
if (_type_previous == position_setpoint_s::SETPOINT_TYPE_IDLE) {
|
||||||
_acceleration_setpoint.setNaN();
|
_acceleration_setpoint.setNaN();
|
||||||
}
|
}
|
||||||
|
|
||||||
// during mission and reposition, raise the landing gears but only
|
// during mission and reposition, raise the landing gears but only
|
||||||
// if altitude is high enough
|
// if altitude is high enough
|
||||||
if (_highEnoughForLandingGear()) {
|
if (_dist_to_ground > 2.f) {
|
||||||
_gear.landing_gear = landing_gear_s::GEAR_UP;
|
_gear.landing_gear = landing_gear_s::GEAR_UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case WaypointType::idle:
|
case position_setpoint_s::SETPOINT_TYPE_IDLE:
|
||||||
// Send zero thrust setpoint
|
// Send zero thrust setpoint
|
||||||
_position_setpoint.setNaN(); // Don't require any position/velocity setpoints
|
_position_setpoint.setNaN(); // Don't require any position/velocity setpoints
|
||||||
_velocity_setpoint.setNaN();
|
_velocity_setpoint.setNaN();
|
||||||
_acceleration_setpoint = Vector3f(0.f, 0.f, 100.f); // High downwards acceleration to make sure there's no thrust
|
_acceleration_setpoint = Vector3f(0.f, 0.f, 100.f); // High downwards acceleration to make sure there's no thrust
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WaypointType::land:
|
case position_setpoint_s::SETPOINT_TYPE_LAND:
|
||||||
_prepareLandSetpoints();
|
_prepareLandSetpoints();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WaypointType::velocity:
|
case position_setpoint_s::SETPOINT_TYPE_VELOCITY:
|
||||||
// XY Velocity waypoint
|
// XY Velocity waypoint
|
||||||
// TODO : Rewiew that. What is the expected behavior?
|
// TODO : Rewiew that. What is the expected behavior?
|
||||||
_position_setpoint = Vector3f(NAN, NAN, _position(2));
|
_position_setpoint = Vector3f(NAN, NAN, _position(2));
|
||||||
@@ -141,14 +141,14 @@ bool FlightTaskAuto::update()
|
|||||||
_velocity_setpoint(2) = NAN;
|
_velocity_setpoint(2) = NAN;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WaypointType::loiter:
|
case position_setpoint_s::SETPOINT_TYPE_LOITER:
|
||||||
if (_param_mpc_land_rc_help.get() && _sticks.checkAndUpdateStickInputs()) {
|
if (_param_mpc_land_rc_help.get() && _sticks.checkAndUpdateStickInputs()) {
|
||||||
rcHelpModifyYaw(_yaw_setpoint);
|
rcHelpModifyYaw(_yaw_setpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FALLTHROUGH
|
// FALLTHROUGH
|
||||||
case WaypointType::takeoff:
|
case position_setpoint_s::SETPOINT_TYPE_TAKEOFF:
|
||||||
case WaypointType::position:
|
case position_setpoint_s::SETPOINT_TYPE_POSITION:
|
||||||
default:
|
default:
|
||||||
// Simple waypoint navigation: go to xyz target, with standard limitations
|
// Simple waypoint navigation: go to xyz target, with standard limitations
|
||||||
_position_setpoint = _target;
|
_position_setpoint = _target;
|
||||||
@@ -243,7 +243,7 @@ void FlightTaskAuto::_prepareLandSetpoints()
|
|||||||
vertical_speed = _param_mpc_land_crawl_speed.get();
|
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
|
// initialize yaw and xy-position
|
||||||
_land_heading = _yaw_setpoint;
|
_land_heading = _yaw_setpoint;
|
||||||
_stick_acceleration_xy.resetPosition(Vector2f(_target(0), _target(1)));
|
_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)) {
|
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
|
// 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;
|
_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;
|
_yaw_setpoint = _yaw;
|
||||||
_yawspeed_setpoint = NAN;
|
_yawspeed_setpoint = NAN;
|
||||||
_target_acceptance_radius = _sub_triplet_setpoint.get().current.acceptance_radius;
|
_target_acceptance_radius = _sub_triplet_setpoint.get().current.acceptance_radius;
|
||||||
@@ -368,7 +368,7 @@ bool FlightTaskAuto::_evaluateTriplets()
|
|||||||
return true;
|
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
|
// 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;
|
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;
|
_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;
|
_triplet_next_wp = _triplet_target;
|
||||||
|
|
||||||
} else if (_isFinite(_sub_triplet_setpoint.get().next) && _sub_triplet_setpoint.get().next.valid) {
|
} 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
|
// 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
|
// 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.
|
// 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_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());
|
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());;
|
_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()
|
void FlightTaskAuto::updateParams()
|
||||||
{
|
{
|
||||||
FlightTask::updateParams();
|
FlightTask::updateParams();
|
||||||
|
|||||||
@@ -60,20 +60,6 @@
|
|||||||
#include <lib/avoidance/ObstacleAvoidance.hpp>
|
#include <lib/avoidance/ObstacleAvoidance.hpp>
|
||||||
#endif
|
#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 {
|
enum class State {
|
||||||
offtrack, /**< Vehicle is more than cruise speed away from track */
|
offtrack, /**< Vehicle is more than cruise speed away from track */
|
||||||
target_behind, /**< Vehicle is in front of target. */
|
target_behind, /**< Vehicle is in front of target. */
|
||||||
@@ -115,7 +101,6 @@ protected:
|
|||||||
bool _checkTakeoff() override { return _want_takeoff; };
|
bool _checkTakeoff() override { return _want_takeoff; };
|
||||||
|
|
||||||
void _prepareLandSetpoints();
|
void _prepareLandSetpoints();
|
||||||
bool _highEnoughForLandingGear(); /**< Checks if gears can be lowered. */
|
|
||||||
|
|
||||||
void updateParams() override; /**< See ModuleParam class */
|
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. */
|
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};
|
bool _next_was_valid{false};
|
||||||
float _mc_cruise_speed{NAN}; /**< Requested cruise speed. If not valid, default cruise speed is used. */
|
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<home_position_s> _sub_home_position{ORB_ID(home_position)};
|
||||||
uORB::SubscriptionData<vehicle_status_s> _sub_vehicle_status{ORB_ID(vehicle_status)};
|
uORB::SubscriptionData<vehicle_status_s> _sub_vehicle_status{ORB_ID(vehicle_status)};
|
||||||
@@ -147,7 +133,6 @@ protected:
|
|||||||
StickYaw _stick_yaw{this};
|
StickYaw _stick_yaw{this};
|
||||||
matrix::Vector3f _land_position;
|
matrix::Vector3f _land_position;
|
||||||
float _land_heading;
|
float _land_heading;
|
||||||
WaypointType _type_previous{WaypointType::idle}; /**< Previous type of current target triplet. */
|
|
||||||
bool _is_emergency_braking_active{false};
|
bool _is_emergency_braking_active{false};
|
||||||
bool _want_takeoff{false};
|
bool _want_takeoff{false};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user