PX4 Firmware
PX4 Autopilot Software http://px4.io
state_machine_helper.cpp File Reference

State machine helper functions implementations. More...

#include <px4_platform_common/px4_config.h>
#include <uORB/topics/vehicle_command.h>
#include <uORB/topics/vehicle_command_ack.h>
#include <uORB/topics/vehicle_status.h>
#include <systemlib/mavlink_log.h>
#include <drivers/drv_hrt.h>
#include "Arming/PreFlightCheck/PreFlightCheck.hpp"
#include "state_machine_helper.h"
#include "commander_helper.h"
Include dependency graph for state_machine_helper.cpp:

Go to the source code of this file.

Functions

void set_link_loss_nav_state (vehicle_status_s *status, actuator_armed_s *armed, const vehicle_status_flags_s &status_flags, commander_state_s *internal_state, const link_loss_actions_t link_loss_act, uint8_t auto_recovery_nav_state)
 
void reset_link_loss_globals (actuator_armed_s *armed, const bool old_failsafe, const link_loss_actions_t link_loss_act)
 
void set_offboard_loss_nav_state (vehicle_status_s *status, actuator_armed_s *armed, const vehicle_status_flags_s &status_flags, const offboard_loss_actions_t offboard_loss_act)
 
void set_offboard_loss_rc_nav_state (vehicle_status_s *status, actuator_armed_s *armed, const vehicle_status_flags_s &status_flags, const offboard_loss_rc_actions_t offboard_loss_rc_act)
 
void reset_offboard_loss_globals (actuator_armed_s *armed, const bool old_failsafe, const offboard_loss_actions_t offboard_loss_act, const offboard_loss_rc_actions_t offboard_loss_rc_act)
 
transition_result_t arming_state_transition (vehicle_status_s *status, const safety_s &safety, const arming_state_t new_arming_state, actuator_armed_s *armed, const bool fRunPreArmChecks, orb_advert_t *mavlink_log_pub, vehicle_status_flags_s *status_flags, const uint8_t arm_requirements, const hrt_abstime &time_since_boot)
 
bool is_safe (const safety_s &safety, const actuator_armed_s &armed)
 
transition_result_t main_state_transition (const vehicle_status_s &status, const main_state_t new_main_state, const vehicle_status_flags_s &status_flags, commander_state_s *internal_state)
 
void enable_failsafe (vehicle_status_s *status, bool old_failsafe, orb_advert_t *mavlink_log_pub, const char *reason)
 Enable failsafe and report to user. More...
 
bool set_nav_state (vehicle_status_s *status, actuator_armed_s *armed, commander_state_s *internal_state, orb_advert_t *mavlink_log_pub, const link_loss_actions_t data_link_loss_act, const bool mission_finished, const bool stay_in_failsafe, const vehicle_status_flags_s &status_flags, bool landed, const link_loss_actions_t rc_loss_act, const offboard_loss_actions_t offb_loss_act, const offboard_loss_rc_actions_t offb_loss_rc_act, const position_nav_loss_actions_t posctl_nav_loss_act)
 Check failsafe and main status and set navigation status for navigator accordingly. More...
 
bool check_invalid_pos_nav_state (vehicle_status_s *status, bool old_failsafe, orb_advert_t *mavlink_log_pub, const vehicle_status_flags_s &status_flags, const bool use_rc, const bool using_global_pos)
 
void battery_failsafe (orb_advert_t *mavlink_log_pub, const vehicle_status_s &status, const vehicle_status_flags_s &status_flags, commander_state_s *internal_state, const uint8_t battery_warning, const low_battery_action_t low_battery_action)
 

Variables

static constexpr const char reason_no_rc [] = "no RC"
 
static constexpr const char reason_no_offboard [] = "no offboard"
 
static constexpr const char reason_no_rc_and_no_offboard [] = "no RC and no offboard"
 
static constexpr const char reason_no_local_position [] = "no local position"
 
static constexpr const char reason_no_global_position [] = "no global position"
 
static constexpr const char reason_no_datalink [] = "no datalink"
 
static constexpr const bool arming_transitions [vehicle_status_s::ARMING_STATE_MAX][vehicle_status_s::ARMING_STATE_MAX]
 
const char *const arming_state_names [vehicle_status_s::ARMING_STATE_MAX]
 
static hrt_abstime last_preflight_check = 0
 initialize so it gets checked immediately More...
 

Detailed Description

State machine helper functions implementations.

Author
Thomas Gubler thoma.nosp@m.s@px.nosp@m.4.io
Julian Oes julia.nosp@m.n@oe.nosp@m.s.ch
Sander Smeets sande.nosp@m.r@dr.nosp@m.onesl.nosp@m.ab.c.nosp@m.om

Definition in file state_machine_helper.cpp.

Function Documentation

◆ arming_state_transition()

transition_result_t arming_state_transition ( vehicle_status_s status,
const safety_s safety,
const arming_state_t  new_arming_state,
actuator_armed_s armed,
const bool  fRunPreArmChecks,
orb_advert_t mavlink_log_pub,
vehicle_status_flags_s status_flags,
const uint8_t  arm_requirements,
const hrt_abstime time_since_boot 
)

◆ battery_failsafe()

void battery_failsafe ( orb_advert_t mavlink_log_pub,
const vehicle_status_s status,
const vehicle_status_flags_s status_flags,
commander_state_s internal_state,
const uint8_t  battery_warning,
const low_battery_action_t  low_battery_action 
)

Definition at line 1014 of file state_machine_helper.cpp.

References vehicle_status_flags_s::condition_global_position_valid, vehicle_status_flags_s::condition_home_position_valid, hrt_absolute_time(), LAND, commander_state_s::main_state, mavlink_log_critical, mavlink_log_emergency, RETURN, RETURN_OR_LAND, commander_state_s::timestamp, and WARNING.

Referenced by Commander::battery_status_check().

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

◆ check_invalid_pos_nav_state()

bool check_invalid_pos_nav_state ( vehicle_status_s status,
bool  old_failsafe,
orb_advert_t mavlink_log_pub,
const vehicle_status_flags_s status_flags,
const bool  use_rc,
const bool  using_global_pos 
)

Definition at line 724 of file state_machine_helper.cpp.

References vehicle_status_flags_s::condition_global_position_valid, vehicle_status_flags_s::condition_local_altitude_valid, vehicle_status_flags_s::condition_local_position_valid, vehicle_status_flags_s::condition_local_velocity_valid, enable_failsafe(), vehicle_status_s::nav_state, reason_no_global_position, reason_no_local_position, and vehicle_status_s::vehicle_type.

Referenced by set_nav_state().

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

◆ enable_failsafe()

void enable_failsafe ( vehicle_status_s status,
bool  old_failsafe,
orb_advert_t mavlink_log_pub,
const char *  reason 
)

Enable failsafe and report to user.

Definition at line 391 of file state_machine_helper.cpp.

References vehicle_status_s::arming_state, vehicle_status_s::failsafe, and mavlink_log_critical.

Referenced by check_invalid_pos_nav_state(), and set_nav_state().

Here is the caller graph for this function:

◆ is_safe()

bool is_safe ( const safety_s safety,
const actuator_armed_s armed 
)

Definition at line 248 of file state_machine_helper.cpp.

References actuator_armed_s::armed, actuator_armed_s::lockdown, actuator_armed_s::manual_lockdown, safety_s::safety_off, and safety_s::safety_switch_available.

Referenced by commander_low_prio_loop(), and StateMachineHelperTest::isSafeTest().

Here is the caller graph for this function:

◆ main_state_transition()

◆ reset_link_loss_globals()

void reset_link_loss_globals ( actuator_armed_s armed,
const bool  old_failsafe,
const link_loss_actions_t  link_loss_act 
)

Definition at line 852 of file state_machine_helper.cpp.

References actuator_armed_s::force_failsafe, actuator_armed_s::lockdown, LOCKDOWN, and TERMINATE.

Referenced by set_nav_state().

Here is the caller graph for this function:

◆ reset_offboard_loss_globals()

void reset_offboard_loss_globals ( actuator_armed_s armed,
const bool  old_failsafe,
const offboard_loss_actions_t  offboard_loss_act,
const offboard_loss_rc_actions_t  offboard_loss_rc_act 
)

Definition at line 993 of file state_machine_helper.cpp.

References actuator_armed_s::force_failsafe, actuator_armed_s::lockdown, LOCKDOWN, and TERMINATE.

Referenced by set_nav_state().

Here is the caller graph for this function:

◆ set_link_loss_nav_state()

void set_link_loss_nav_state ( vehicle_status_s status,
actuator_armed_s armed,
const vehicle_status_flags_s status_flags,
commander_state_s internal_state,
const link_loss_actions_t  link_loss_act,
uint8_t  auto_recovery_nav_state 
)

Definition at line 784 of file state_machine_helper.cpp.

References AUTO_LAND, AUTO_LOITER, AUTO_RECOVER, AUTO_RTL, vehicle_status_flags_s::condition_global_position_valid, vehicle_status_flags_s::condition_home_position_valid, vehicle_status_flags_s::condition_local_altitude_valid, vehicle_status_flags_s::condition_local_position_valid, DISABLED, actuator_armed_s::force_failsafe, actuator_armed_s::lockdown, LOCKDOWN, main_state_transition(), vehicle_status_s::nav_state, TERMINATE, and vehicle_status_s::vehicle_type.

Referenced by set_nav_state().

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

◆ set_nav_state()

bool set_nav_state ( vehicle_status_s status,
actuator_armed_s armed,
commander_state_s internal_state,
orb_advert_t mavlink_log_pub,
const link_loss_actions_t  data_link_loss_act,
const bool  mission_finished,
const bool  stay_in_failsafe,
const vehicle_status_flags_s status_flags,
bool  landed,
const link_loss_actions_t  rc_loss_act,
const offboard_loss_actions_t  offb_loss_act,
const offboard_loss_rc_actions_t  offb_loss_rc_act,
const position_nav_loss_actions_t  posctl_nav_loss_act 
)

◆ set_offboard_loss_nav_state()

void set_offboard_loss_nav_state ( vehicle_status_s status,
actuator_armed_s armed,
const vehicle_status_flags_s status_flags,
const offboard_loss_actions_t  offboard_loss_act 
)

◆ set_offboard_loss_rc_nav_state()

void set_offboard_loss_rc_nav_state ( vehicle_status_s status,
actuator_armed_s armed,
const vehicle_status_flags_s status_flags,
const offboard_loss_rc_actions_t  offboard_loss_rc_act 
)

Variable Documentation

◆ arming_state_names

const char* const arming_state_names[vehicle_status_s::ARMING_STATE_MAX]
Initial value:
= {
"INIT",
"STANDBY",
"ARMED",
"STANDBY_ERROR",
"SHUTDOWN",
"IN_AIR_RESTORE",
}

Definition at line 77 of file state_machine_helper.cpp.

Referenced by arming_state_transition(), and print_status().

◆ arming_transitions

constexpr const bool arming_transitions[vehicle_status_s::ARMING_STATE_MAX][vehicle_status_s::ARMING_STATE_MAX]
static
Initial value:
= {
{ true, true, false, true, false, false },
{ true, true, true, false, false, false },
{ false, true, true, false, false, true },
{ true, true, true, true, false, false },
{ true, true, false, true, true, true },
{ false, false, false, false, false, false },
}

Definition at line 66 of file state_machine_helper.cpp.

Referenced by arming_state_transition().

◆ last_preflight_check

hrt_abstime last_preflight_check = 0
static

initialize so it gets checked immediately

Definition at line 86 of file state_machine_helper.cpp.

Referenced by arming_state_transition().

◆ reason_no_datalink

constexpr const char reason_no_datalink[] = "no datalink"
static

Definition at line 58 of file state_machine_helper.cpp.

Referenced by set_nav_state().

◆ reason_no_global_position

constexpr const char reason_no_global_position[] = "no global position"
static

Definition at line 57 of file state_machine_helper.cpp.

Referenced by check_invalid_pos_nav_state().

◆ reason_no_local_position

constexpr const char reason_no_local_position[] = "no local position"
static

Definition at line 56 of file state_machine_helper.cpp.

Referenced by check_invalid_pos_nav_state().

◆ reason_no_offboard

constexpr const char reason_no_offboard[] = "no offboard"
static

Definition at line 54 of file state_machine_helper.cpp.

Referenced by set_nav_state().

◆ reason_no_rc

constexpr const char reason_no_rc[] = "no RC"
static

Definition at line 53 of file state_machine_helper.cpp.

Referenced by set_nav_state().

◆ reason_no_rc_and_no_offboard

constexpr const char reason_no_rc_and_no_offboard[] = "no RC and no offboard"
static

Definition at line 55 of file state_machine_helper.cpp.

Referenced by set_nav_state().