PX4 Firmware
PX4 Autopilot Software http://px4.io
FlightTask Class Referenceabstract

#include <FlightTask.hpp>

Inheritance diagram for FlightTask:
Collaboration diagram for FlightTask:

Public Member Functions

 FlightTask ()
 
virtual ~FlightTask ()=default
 
virtual bool activate (vehicle_local_position_setpoint_s last_setpoint)
 Call once on the event where you switch to the task. More...
 
virtual void reActivate ()
 Call this to reset an active Flight Task. More...
 
virtual bool applyCommandParameters (const vehicle_command_s &command)
 To be called to adopt parameters from an arrived vehicle command. More...
 
virtual bool updateInitialize ()
 Call before activate() or update() to initialize time and input data. More...
 
virtual bool update ()=0
 To be called regularly in the control loop cycle to execute the task. More...
 
virtual bool updateFinalize ()
 Call after update() to constrain the generated setpoints in order to comply with the constraints of the current mode. More...
 
const vehicle_local_position_setpoint_s getPositionSetpoint ()
 Get the output data. More...
 
const vehicle_constraints_sgetConstraints ()
 Get vehicle constraints. More...
 
const landing_gear_sgetGear ()
 Get landing gear position. More...
 
const vehicle_trajectory_waypoint_sgetAvoidanceWaypoint ()
 Get avoidance desired waypoint. More...
 
void handleParameterUpdate ()
 Call this whenever a parameter update notification is received (parameter_update uORB message) More...
 
virtual void setYawHandler (WeatherVane *ext_yaw_handler)
 Sets an external yaw handler which can be used by any flight task to implement a different yaw control strategy. More...
 
void updateVelocityControllerIO (const matrix::Vector3f &vel_sp, const matrix::Vector3f &thrust_sp)
 

Static Public Attributes

static const vehicle_local_position_setpoint_s empty_setpoint = {0, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, {NAN, NAN, NAN}, {NAN, NAN, NAN}, {NAN, NAN, NAN}, {}}
 Empty setpoint. More...
 
static const vehicle_constraints_s empty_constraints = {0, NAN, NAN, NAN, NAN, NAN, NAN, NAN, false, {}}
 Empty constraints. More...
 
static const landing_gear_s empty_landing_gear_default_keep = {0, landing_gear_s::GEAR_KEEP, {}}
 default landing gear state More...
 

Protected Member Functions

void _resetSetpoints ()
 Reset all setpoints to NAN. More...
 
void _evaluateVehicleLocalPosition ()
 Check and update local position. More...
 
virtual void _setDefaultConstraints ()
 Set constraints to default values. More...
 
virtual bool _checkTakeoff ()
 Determine when to trigger a takeoff (ignored in flight) More...
 
void _initEkfResetCounters ()
 Monitor the EKF reset counters and call the appropriate handling functions in case of a reset event. More...
 
void _checkEkfResetCounters ()
 
virtual void _ekfResetHandlerPositionXY ()
 
virtual void _ekfResetHandlerVelocityXY ()
 
virtual void _ekfResetHandlerPositionZ ()
 
virtual void _ekfResetHandlerVelocityZ ()
 
virtual void _ekfResetHandlerHeading (float delta_psi)
 

Protected Attributes

uORB::SubscriptionData< vehicle_local_position_s_sub_vehicle_local_position {ORB_ID(vehicle_local_position)}
 
uORB::SubscriptionData< vehicle_attitude_s_sub_attitude {ORB_ID(vehicle_attitude)}
 
float _time = 0
 passed time in seconds since the task was activated More...
 
float _deltatime = 0
 passed time in seconds since the task was last updated More...
 
hrt_abstime _time_stamp_activate = 0
 time stamp when task was activated More...
 
hrt_abstime _time_stamp_current = 0
 time stamp at the beginning of the current task update More...
 
hrt_abstime _time_stamp_last = 0
 time stamp when task was last updated More...
 
matrix::Vector3f _position
 current vehicle position More...
 
matrix::Vector3f _velocity
 current vehicle velocity More...
 
float _yaw = 0.f
 current vehicle yaw heading More...
 
float _dist_to_bottom = 0.0f
 current height above ground level More...
 
matrix::Vector3f _position_setpoint
 Setpoints which the position controller has to execute. More...
 
matrix::Vector3f _velocity_setpoint
 
matrix::Vector3f _acceleration_setpoint
 
matrix::Vector3f _jerk_setpoint
 
matrix::Vector3f _thrust_setpoint
 
float _yaw_setpoint
 
float _yawspeed_setpoint
 
matrix::Vector3f _velocity_setpoint_feedback
 
matrix::Vector3f _thrust_setpoint_feedback
 
struct {
   uint8_t   xy = 0
 
   uint8_t   vxy = 0
 
   uint8_t   z = 0
 
   uint8_t   vz = 0
 
   uint8_t   quat = 0
 
_reset_counters
 
vehicle_constraints_s _constraints {}
 Vehicle constraints. More...
 
landing_gear_s _gear {}
 
vehicle_trajectory_waypoint_s _desired_waypoint {}
 Desired waypoints. More...
 

Static Protected Attributes

static constexpr uint64_t _timeout = 500000
 maximal time in us before a loop or data times out More...
 

Detailed Description

Definition at line 57 of file FlightTask.hpp.

Constructor & Destructor Documentation

◆ FlightTask()

FlightTask::FlightTask ( )
inline

Definition at line 60 of file FlightTask.hpp.

References _constraints, _resetSetpoints(), activate(), empty_constraints, reActivate(), and ~FlightTask().

Here is the call graph for this function:

◆ ~FlightTask()

virtual FlightTask::~FlightTask ( )
virtualdefault

Referenced by FlightTask(), and FlightTasks::switchTask().

Here is the caller graph for this function:

Member Function Documentation

◆ _checkEkfResetCounters()

void FlightTask::_checkEkfResetCounters ( )
protected

Definition at line 51 of file FlightTask.cpp.

References _ekfResetHandlerHeading(), _ekfResetHandlerPositionXY(), _ekfResetHandlerPositionZ(), _ekfResetHandlerVelocityXY(), _ekfResetHandlerVelocityZ(), _reset_counters, _sub_attitude, _sub_vehicle_local_position, vehicle_attitude_s::delta_q_reset, uORB::SubscriptionData< T >::get(), vehicle_attitude_s::quat_reset_counter, vehicle_local_position_s::vxy_reset_counter, vehicle_local_position_s::vz_reset_counter, vehicle_local_position_s::xy_reset_counter, and vehicle_local_position_s::z_reset_counter.

Referenced by updateInitialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkTakeoff()

bool FlightTask::_checkTakeoff ( )
protectedvirtual

Determine when to trigger a takeoff (ignored in flight)

Reimplemented in FlightTaskAutoLineSmoothVel, and FlightTaskManualAltitude.

Definition at line 174 of file FlightTask.cpp.

References _position, _position_setpoint, _sub_vehicle_local_position, _velocity_setpoint, uORB::SubscriptionData< T >::get(), and vehicle_local_position_s::hagl_min.

Referenced by FlightTaskAuto::updateFinalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _ekfResetHandlerHeading()

virtual void FlightTask::_ekfResetHandlerHeading ( float  delta_psi)
inlineprotectedvirtual

Reimplemented in FlightTaskAutoLineSmoothVel, and FlightTaskManualAltitude.

Definition at line 196 of file FlightTask.hpp.

Referenced by _checkEkfResetCounters().

Here is the caller graph for this function:

◆ _ekfResetHandlerPositionXY()

virtual void FlightTask::_ekfResetHandlerPositionXY ( )
inlineprotectedvirtual

Reimplemented in FlightTaskManualPositionSmoothVel, and FlightTaskAutoLineSmoothVel.

Definition at line 192 of file FlightTask.hpp.

Referenced by _checkEkfResetCounters().

Here is the caller graph for this function:

◆ _ekfResetHandlerPositionZ()

virtual void FlightTask::_ekfResetHandlerPositionZ ( )
inlineprotectedvirtual

Reimplemented in FlightTaskManualPositionSmoothVel, FlightTaskAutoLineSmoothVel, and FlightTaskManualAltitudeSmoothVel.

Definition at line 194 of file FlightTask.hpp.

Referenced by _checkEkfResetCounters().

Here is the caller graph for this function:

◆ _ekfResetHandlerVelocityXY()

virtual void FlightTask::_ekfResetHandlerVelocityXY ( )
inlineprotectedvirtual

Reimplemented in FlightTaskManualPositionSmoothVel, and FlightTaskAutoLineSmoothVel.

Definition at line 193 of file FlightTask.hpp.

Referenced by _checkEkfResetCounters().

Here is the caller graph for this function:

◆ _ekfResetHandlerVelocityZ()

virtual void FlightTask::_ekfResetHandlerVelocityZ ( )
inlineprotectedvirtual

Reimplemented in FlightTaskManualPositionSmoothVel, FlightTaskAutoLineSmoothVel, and FlightTaskManualAltitudeSmoothVel.

Definition at line 195 of file FlightTask.hpp.

Referenced by _checkEkfResetCounters().

Here is the caller graph for this function:

◆ _evaluateVehicleLocalPosition()

◆ _initEkfResetCounters()

void FlightTask::_initEkfResetCounters ( )
protected

Monitor the EKF reset counters and call the appropriate handling functions in case of a reset event.

Definition at line 42 of file FlightTask.cpp.

References _reset_counters, _sub_attitude, _sub_vehicle_local_position, uORB::SubscriptionData< T >::get(), vehicle_attitude_s::quat_reset_counter, vehicle_local_position_s::vxy_reset_counter, vehicle_local_position_s::vz_reset_counter, vehicle_local_position_s::xy_reset_counter, and vehicle_local_position_s::z_reset_counter.

Referenced by activate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _resetSetpoints()

void FlightTask::_resetSetpoints ( )
protected

Reset all setpoints to NAN.

Definition at line 104 of file FlightTask.cpp.

References _acceleration_setpoint, _jerk_setpoint, _position_setpoint, _thrust_setpoint, _velocity_setpoint, _yaw_setpoint, _yawspeed_setpoint, and matrix::Matrix< Type, M, N >::setAll().

Referenced by activate(), and FlightTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _setDefaultConstraints()

void FlightTask::_setDefaultConstraints ( )
protectedvirtual

Set constraints to default values.

Reimplemented in FlightTaskAuto.

Definition at line 163 of file FlightTask.cpp.

References _constraints, vehicle_constraints_s::max_distance_to_ground, vehicle_constraints_s::min_distance_to_ground, math::radians(), vehicle_constraints_s::speed_down, vehicle_constraints_s::speed_up, vehicle_constraints_s::speed_xy, vehicle_constraints_s::tilt, and vehicle_constraints_s::want_takeoff.

Referenced by FlightTaskAuto::_setDefaultConstraints(), and activate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ activate()

bool FlightTask::activate ( vehicle_local_position_setpoint_s  last_setpoint)
virtual

Call once on the event where you switch to the task.

Parameters
stateof the previous task
Returns
true on success, false on error

Reimplemented in FlightTaskAuto, FlightTaskManualPositionSmoothVel, FlightTaskOrbit, FlightTaskSport, FlightTaskAutoLineSmoothVel, FlightTaskManualPosition, FlightTaskManualAltitudeSmoothVel, FlightTaskOffboard, FlightTaskAutoMapper, FlightTaskAutoMapper2, FlightTaskFailsafe, FlightTaskManualAltitude, FlightTaskTransition, and FlightTaskDescend.

Definition at line 12 of file FlightTask.cpp.

References _gear, _initEkfResetCounters(), _resetSetpoints(), _setDefaultConstraints(), _time_stamp_activate, empty_landing_gear_default_keep, and hrt_absolute_time().

Referenced by FlightTaskDescend::activate(), FlightTaskFailsafe::activate(), FlightTaskTransition::activate(), FlightTaskManualAltitude::activate(), FlightTaskOffboard::activate(), FlightTaskAuto::activate(), FlightTask(), reActivate(), and FlightTasks::switchTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyCommandParameters()

virtual bool FlightTask::applyCommandParameters ( const vehicle_command_s command)
inlinevirtual

To be called to adopt parameters from an arrived vehicle command.

Parameters
commandreceived command message containing the parameters
Returns
true if accepted, false if declined

Reimplemented in FlightTaskOrbit, and FlightTaskManual.

Definition at line 86 of file FlightTask.hpp.

References update(), and updateInitialize().

Referenced by FlightTasks::_updateCommand(), and FlightTaskManual::applyCommandParameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAvoidanceWaypoint()

const vehicle_trajectory_waypoint_s& FlightTask::getAvoidanceWaypoint ( )
inline

Get avoidance desired waypoint.

Returns
desired waypoints

Definition at line 133 of file FlightTask.hpp.

References _desired_waypoint.

◆ getConstraints()

const vehicle_constraints_s& FlightTask::getConstraints ( )
inline

Get vehicle constraints.

The constraints can vary with task.

Returns
constraints

Definition at line 120 of file FlightTask.hpp.

References _constraints.

Referenced by FlightTasks::getConstraints().

Here is the caller graph for this function:

◆ getGear()

const landing_gear_s& FlightTask::getGear ( )
inline

Get landing gear position.

The constraints can vary with task.

Returns
landing gear

Definition at line 127 of file FlightTask.hpp.

References _gear.

Referenced by FlightTasks::getGear().

Here is the caller graph for this function:

◆ getPositionSetpoint()

const vehicle_local_position_setpoint_s FlightTask::getPositionSetpoint ( )

Get the output data.

Returns
task output setpoints that get executed by the positon controller

Definition at line 81 of file FlightTask.cpp.

References _acceleration_setpoint, _jerk_setpoint, _position_setpoint, _thrust_setpoint, _velocity_setpoint, _yaw_setpoint, _yawspeed_setpoint, vehicle_local_position_setpoint_s::acceleration, matrix::Matrix< Type, M, N >::copyTo(), hrt_absolute_time(), vehicle_local_position_setpoint_s::jerk, vehicle_local_position_setpoint_s::thrust, vehicle_local_position_setpoint_s::timestamp, vehicle_local_position_setpoint_s::vx, vehicle_local_position_setpoint_s::vy, vehicle_local_position_setpoint_s::vz, vehicle_local_position_setpoint_s::x, vehicle_local_position_setpoint_s::y, vehicle_local_position_setpoint_s::yaw, vehicle_local_position_setpoint_s::yawspeed, and vehicle_local_position_setpoint_s::z.

Referenced by FlightTasks::getPositionSetpoint(), reActivate(), and updateFinalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleParameterUpdate()

void FlightTask::handleParameterUpdate ( )
inline

Call this whenever a parameter update notification is received (parameter_update uORB message)

Definition at line 155 of file FlightTask.hpp.

Referenced by FlightTasks::handleParameterUpdate().

Here is the caller graph for this function:

◆ reActivate()

void FlightTask::reActivate ( )
virtual

Call this to reset an active Flight Task.

Reimplemented in FlightTaskManualPositionSmoothVel, FlightTaskAutoLineSmoothVel, and FlightTaskManualAltitudeSmoothVel.

Definition at line 22 of file FlightTask.cpp.

References activate(), and getPositionSetpoint().

Referenced by FlightTask(), and FlightTasks::reActivate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setYawHandler()

virtual void FlightTask::setYawHandler ( WeatherVane ext_yaw_handler)
inlinevirtual

Sets an external yaw handler which can be used by any flight task to implement a different yaw control strategy.

This method does nothing, each flighttask which wants to use the yaw handler needs to override this method.

Reimplemented in FlightTaskAuto, and FlightTaskManualPosition.

Definition at line 164 of file FlightTask.hpp.

◆ update()

virtual bool FlightTask::update ( )
pure virtual

To be called regularly in the control loop cycle to execute the task.

Returns
true on success, false on error

Implemented in FlightTaskOrbit, FlightTaskManualAltitude, FlightTaskTransition, FlightTaskAutoMapper, FlightTaskAutoMapper2, FlightTaskOffboard, FlightTaskAutoFollowMe, FlightTaskFailsafe, and FlightTaskDescend.

Referenced by applyCommandParameters(), and FlightTasks::update().

Here is the caller graph for this function:

◆ updateFinalize()

virtual bool FlightTask::updateFinalize ( )
inlinevirtual

Call after update() to constrain the generated setpoints in order to comply with the constraints of the current mode.

Returns
true on success, false on error

Reimplemented in FlightTaskAuto.

Definition at line 107 of file FlightTask.hpp.

References getPositionSetpoint().

Referenced by FlightTasks::update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateInitialize()

bool FlightTask::updateInitialize ( )
virtual

Call before activate() or update() to initialize time and input data.

Returns
true on success, false on error

Reimplemented in FlightTaskAuto, FlightTaskManual, FlightTaskManualPosition, FlightTaskOffboard, FlightTaskManualAltitude, and FlightTaskTransition.

Definition at line 27 of file FlightTask.cpp.

References _checkEkfResetCounters(), _deltatime, _evaluateVehicleLocalPosition(), _sub_attitude, _sub_vehicle_local_position, _time, _time_stamp_activate, _time_stamp_current, _time_stamp_last, _timeout, hrt_absolute_time(), math::min(), and uORB::SubscriptionData< T >::update().

Referenced by applyCommandParameters(), FlightTasks::switchTask(), FlightTasks::update(), FlightTaskTransition::updateInitialize(), FlightTaskOffboard::updateInitialize(), FlightTaskManual::updateInitialize(), and FlightTaskAuto::updateInitialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateVelocityControllerIO()

void FlightTask::updateVelocityControllerIO ( const matrix::Vector3f vel_sp,
const matrix::Vector3f thrust_sp 
)
inline

Definition at line 166 of file FlightTask.hpp.

References _thrust_setpoint_feedback, and _velocity_setpoint_feedback.

Member Data Documentation

◆ _acceleration_setpoint

matrix::Vector3f FlightTask::_acceleration_setpoint
protected

◆ _constraints

◆ _deltatime

◆ _desired_waypoint

vehicle_trajectory_waypoint_s FlightTask::_desired_waypoint {}
protected

Desired waypoints.

Goals set by the FCU to be sent to the obstacle avoidance system.

Definition at line 252 of file FlightTask.hpp.

Referenced by getAvoidanceWaypoint().

◆ _dist_to_bottom

float FlightTask::_dist_to_bottom = 0.0f
protected

current height above ground level

Definition at line 210 of file FlightTask.hpp.

Referenced by _evaluateVehicleLocalPosition().

◆ _gear

landing_gear_s FlightTask::_gear {}
protected

Definition at line 246 of file FlightTask.hpp.

Referenced by activate(), and getGear().

◆ _jerk_setpoint

matrix::Vector3f FlightTask::_jerk_setpoint
protected

Definition at line 223 of file FlightTask.hpp.

Referenced by _resetSetpoints(), and getPositionSetpoint().

◆ _position

◆ _position_setpoint

matrix::Vector3f FlightTask::_position_setpoint
protected

Setpoints which the position controller has to execute.

Setpoints that are set to NAN are not controlled. Not all setpoints can be set at the same time. If more than one type of setpoint is set, then order of control is a as follow: position, velocity, acceleration, thrust. The exception is _position_setpoint together with _velocity_setpoint, where the _velocity_setpoint is used as feedforward. _acceleration_setpoint and _jerk_setpoint are currently not supported.

Definition at line 220 of file FlightTask.hpp.

Referenced by _checkTakeoff(), _resetSetpoints(), FlightTaskManualPosition::_updateXYlock(), FlightTaskFailsafe::activate(), FlightTaskManualPosition::activate(), FlightTaskAuto::activate(), FlightTaskOrbit::applyCommandParameters(), FlightTaskOrbit::generate_circle_approach_setpoints(), FlightTaskOrbit::generate_circle_setpoints(), getPositionSetpoint(), FlightTaskOrbit::sendTelemetry(), FlightTaskFailsafe::update(), and FlightTaskTransition::update().

◆ _reset_counters

struct { ... } FlightTask::_reset_counters

◆ _sub_attitude

uORB::SubscriptionData<vehicle_attitude_s> FlightTask::_sub_attitude {ORB_ID(vehicle_attitude)}
protected

◆ _sub_vehicle_local_position

◆ _thrust_setpoint

◆ _thrust_setpoint_feedback

matrix::Vector3f FlightTask::_thrust_setpoint_feedback
protected

Definition at line 229 of file FlightTask.hpp.

Referenced by updateVelocityControllerIO().

◆ _time

float FlightTask::_time = 0
protected

passed time in seconds since the task was activated

Definition at line 200 of file FlightTask.hpp.

Referenced by updateInitialize().

◆ _time_stamp_activate

hrt_abstime FlightTask::_time_stamp_activate = 0
protected

time stamp when task was activated

Definition at line 202 of file FlightTask.hpp.

Referenced by activate(), and updateInitialize().

◆ _time_stamp_current

hrt_abstime FlightTask::_time_stamp_current = 0
protected

time stamp at the beginning of the current task update

Definition at line 203 of file FlightTask.hpp.

Referenced by _evaluateVehicleLocalPosition(), and updateInitialize().

◆ _time_stamp_last

hrt_abstime FlightTask::_time_stamp_last = 0
protected

time stamp when task was last updated

Definition at line 204 of file FlightTask.hpp.

Referenced by updateInitialize().

◆ _timeout

constexpr uint64_t FlightTask::_timeout = 500000
staticprotected

maximal time in us before a loop or data times out

Definition at line 199 of file FlightTask.hpp.

Referenced by _evaluateVehicleLocalPosition(), and updateInitialize().

◆ _velocity

◆ _velocity_setpoint

◆ _velocity_setpoint_feedback

matrix::Vector3f FlightTask::_velocity_setpoint_feedback
protected

Definition at line 228 of file FlightTask.hpp.

Referenced by updateVelocityControllerIO().

◆ _yaw

◆ _yaw_setpoint

◆ _yawspeed_setpoint

◆ empty_constraints

const vehicle_constraints_s FlightTask::empty_constraints = {0, NAN, NAN, NAN, NAN, NAN, NAN, NAN, false, {}}
static

Empty constraints.

All constraints are set to NAN.

Definition at line 145 of file FlightTask.hpp.

Referenced by FlightTask(), FlightTasks::getConstraints(), and MulticopterPositionControl::Run().

◆ empty_landing_gear_default_keep

const landing_gear_s FlightTask::empty_landing_gear_default_keep = {0, landing_gear_s::GEAR_KEEP, {}}
static

default landing gear state

Definition at line 150 of file FlightTask.hpp.

Referenced by activate(), and FlightTasks::getGear().

◆ empty_setpoint

const vehicle_local_position_setpoint_s FlightTask::empty_setpoint = {0, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, {NAN, NAN, NAN}, {NAN, NAN, NAN}, {NAN, NAN, NAN}, {}}
static

Empty setpoint.

All setpoints are set to NAN.

Definition at line 139 of file FlightTask.hpp.

Referenced by FlightTasks::getPositionSetpoint(), and MulticopterPositionControl::Run().

◆ quat

uint8_t FlightTask::quat = 0

Definition at line 237 of file FlightTask.hpp.

◆ vxy

uint8_t FlightTask::vxy = 0

Definition at line 234 of file FlightTask.hpp.

◆ vz

uint8_t FlightTask::vz = 0

Definition at line 236 of file FlightTask.hpp.

◆ xy

uint8_t FlightTask::xy = 0

Definition at line 233 of file FlightTask.hpp.

◆ z

uint8_t FlightTask::z = 0

Definition at line 235 of file FlightTask.hpp.


The documentation for this class was generated from the following files: