mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 04:33:34 +08:00
FlightTask: Weather vane cleanup
Remove the entire external yaw handler, dynamic memory allocation, pointer passing logic. Directly instanciate the weather vane instance in the flight tasks that support it.
This commit is contained in:
@@ -35,5 +35,5 @@ px4_add_library(FlightTaskAuto
|
||||
FlightTaskAuto.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(FlightTaskAuto PUBLIC avoidance FlightTask FlightTaskUtility)
|
||||
target_link_libraries(FlightTaskAuto PUBLIC avoidance FlightTask FlightTaskUtility WeatherVane)
|
||||
target_include_directories(FlightTaskAuto PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
@@ -40,14 +40,6 @@
|
||||
|
||||
using namespace matrix;
|
||||
|
||||
FlightTaskAuto::FlightTaskAuto() :
|
||||
_obstacle_avoidance(this),
|
||||
_sticks(this),
|
||||
_stick_acceleration_xy(this)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool FlightTaskAuto::activate(const trajectory_setpoint_s &last_setpoint)
|
||||
{
|
||||
bool ret = FlightTask::activate(last_setpoint);
|
||||
@@ -257,9 +249,7 @@ void FlightTaskAuto::_prepareLandSetpoints()
|
||||
vertical_speed *= (1 + _sticks.getPositionExpo()(2));
|
||||
|
||||
// Only set a yawrate setpoint if weather vane is not active or the yaw stick is out of its dead-zone
|
||||
const bool weather_vane_active = (_ext_yaw_handler != nullptr) && _ext_yaw_handler->is_active();
|
||||
|
||||
if (!weather_vane_active || fabsf(_sticks.getPositionExpo()(3)) > FLT_EPSILON) {
|
||||
if (!_weathervane.isActive() || fabsf(_sticks.getPositionExpo()(3)) > FLT_EPSILON) {
|
||||
_stick_yaw.generateYawSetpoint(_yawspeed_setpoint, _land_heading,
|
||||
_sticks.getPositionExpo()(3) * math::radians(_param_mpc_man_y_max.get()), _yaw, _is_yaw_good_for_control, _deltatime);
|
||||
}
|
||||
@@ -455,11 +445,8 @@ bool FlightTaskAuto::_evaluateTriplets()
|
||||
_next_was_valid = _sub_triplet_setpoint.get().next.valid;
|
||||
}
|
||||
|
||||
if (_ext_yaw_handler != nullptr) {
|
||||
// activation/deactivation of weather vane is based on parameter WV_EN and setting of navigator (allow_weather_vane)
|
||||
(_param_wv_en.get() && !_sub_triplet_setpoint.get().current.disable_weather_vane) ? _ext_yaw_handler->activate() :
|
||||
_ext_yaw_handler->deactivate();
|
||||
}
|
||||
// activation/deactivation of weather vane is based on parameter WV_EN and setting of navigator (allow_weather_vane)
|
||||
_weathervane.setNavigatorForceDisabled(_sub_triplet_setpoint.get().current.disable_weather_vane);
|
||||
|
||||
// Calculate the current vehicle state and check if it has updated.
|
||||
State previous_state = _current_state;
|
||||
@@ -476,13 +463,15 @@ bool FlightTaskAuto::_evaluateTriplets()
|
||||
_triplet_next_wp,
|
||||
_sub_triplet_setpoint.get().next.yaw,
|
||||
_sub_triplet_setpoint.get().next.yawspeed_valid ? _sub_triplet_setpoint.get().next.yawspeed : (float)NAN,
|
||||
_ext_yaw_handler != nullptr && _ext_yaw_handler->is_active(), _sub_triplet_setpoint.get().current.type);
|
||||
_weathervane.isActive(), _sub_triplet_setpoint.get().current.type);
|
||||
_obstacle_avoidance.checkAvoidanceProgress(
|
||||
_position, _triplet_prev_wp, _target_acceptance_radius, Vector2f(_closest_pt));
|
||||
}
|
||||
|
||||
// set heading
|
||||
if (_ext_yaw_handler != nullptr && _ext_yaw_handler->is_active()) {
|
||||
_weathervane.update();
|
||||
|
||||
if (_weathervane.isActive()) {
|
||||
_yaw_setpoint = NAN;
|
||||
// use the yawrate setpoint from WV only if not moving lateral (velocity setpoint below half of _param_mpc_xy_cruise)
|
||||
// otherwise, keep heading constant (as output from WV is not according to wind in this case)
|
||||
@@ -492,7 +481,7 @@ bool FlightTaskAuto::_evaluateTriplets()
|
||||
_yawspeed_setpoint = 0.0f;
|
||||
|
||||
} else {
|
||||
_yawspeed_setpoint = _ext_yaw_handler->get_weathervane_yawrate();
|
||||
_yawspeed_setpoint = _weathervane.getWeathervaneYawrate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <uORB/topics/manual_control_setpoint.h>
|
||||
#include <uORB/topics/vehicle_status.h>
|
||||
#include <lib/geo/geo.h>
|
||||
#include <lib/weather_vane/WeatherVane.hpp>
|
||||
#include <lib/mathlib/math/filter/AlphaFilter.hpp>
|
||||
#include <lib/motion_planning/PositionSmoothing.hpp>
|
||||
#include "Sticks.hpp"
|
||||
@@ -84,18 +85,13 @@ enum class State {
|
||||
class FlightTaskAuto : public FlightTask
|
||||
{
|
||||
public:
|
||||
FlightTaskAuto();
|
||||
|
||||
FlightTaskAuto() = default;
|
||||
virtual ~FlightTaskAuto() = default;
|
||||
bool activate(const trajectory_setpoint_s &last_setpoint) override;
|
||||
void reActivate() override;
|
||||
bool updateInitialize() override;
|
||||
bool update() override;
|
||||
|
||||
/**
|
||||
* Sets an external yaw handler which can be used to implement a different yaw control strategy.
|
||||
*/
|
||||
void setYawHandler(WeatherVane *ext_yaw_handler) override {_ext_yaw_handler = ext_yaw_handler;}
|
||||
void overrideCruiseSpeed(const float cruise_speed_m_s) override;
|
||||
|
||||
protected:
|
||||
@@ -143,12 +139,12 @@ protected:
|
||||
AlphaFilter<float> _yawspeed_filter;
|
||||
bool _yaw_sp_aligned{false};
|
||||
|
||||
ObstacleAvoidance _obstacle_avoidance; /**< class adjusting setpoints according to external avoidance module's input */
|
||||
ObstacleAvoidance _obstacle_avoidance{this}; /**< class adjusting setpoints according to external avoidance module's input */
|
||||
|
||||
PositionSmoothing _position_smoothing;
|
||||
Vector3f _unsmoothed_velocity_setpoint;
|
||||
Sticks _sticks;
|
||||
StickAccelerationXY _stick_acceleration_xy;
|
||||
Sticks _sticks{this};
|
||||
StickAccelerationXY _stick_acceleration_xy{this};
|
||||
StickYaw _stick_yaw;
|
||||
matrix::Vector3f _land_position;
|
||||
float _land_heading;
|
||||
@@ -164,7 +160,6 @@ protected:
|
||||
(ParamInt<px4::params::COM_OBS_AVOID>) _param_com_obs_avoid, // obstacle avoidance active
|
||||
(ParamFloat<px4::params::MPC_YAWRAUTO_MAX>) _param_mpc_yawrauto_max,
|
||||
(ParamFloat<px4::params::MIS_YAW_ERR>) _param_mis_yaw_err, // yaw-error threshold
|
||||
(ParamBool<px4::params::WV_EN>) _param_wv_en, // enable/disable weather vane (VTOL)
|
||||
(ParamFloat<px4::params::MPC_ACC_HOR>) _param_mpc_acc_hor, // acceleration in flight
|
||||
(ParamFloat<px4::params::MPC_ACC_UP_MAX>) _param_mpc_acc_up_max,
|
||||
(ParamFloat<px4::params::MPC_ACC_DOWN_MAX>) _param_mpc_acc_down_max,
|
||||
@@ -208,8 +203,7 @@ private:
|
||||
float _reference_altitude{NAN}; /**< Altitude relative to ground. */
|
||||
hrt_abstime _time_stamp_reference{0}; /**< time stamp when last reference update occured. */
|
||||
|
||||
WeatherVane *_ext_yaw_handler{nullptr}; /**< external weathervane library, used to implement a yaw control law that turns the vehicle nose into the wind */
|
||||
|
||||
WeatherVane _weathervane{this}; /**< weathervane library, used to implement a yaw control law that turns the vehicle nose into the wind */
|
||||
|
||||
void _limitYawRate(); /**< Limits the rate of change of the yaw setpoint. */
|
||||
bool _evaluateTriplets(); /**< Checks and sets triplets. */
|
||||
|
||||
Reference in New Issue
Block a user