9 #include "overrides.hpp"
11 #include <rclcpp/rclcpp.hpp>
12 #include <px4_msgs/msg/vehicle_status.hpp>
13 #include <px4_msgs/msg/vehicle_command.hpp>
14 #include <px4_msgs/msg/vehicle_command_ack.hpp>
15 #include <px4_msgs/msg/mode_completed.hpp>
33 using CompletedCallback = std::function<void (
Result)>;
46 enum class DeactivateReason
53 rclcpp::Node & node,
const Settings & settings, ModeBase & owned_mode,
54 const std::string & topic_namespace_prefix =
"");
55 ModeExecutorBase(
const ModeExecutorBase &) =
delete;
56 virtual ~ModeExecutorBase() =
default;
85 uint32_t command,
float param1 = NAN,
float param2 = NAN,
float param3 = NAN,
87 float param5 = NAN,
float param6 = NAN,
float param7 = NAN);
96 void takeoff(
const CompletedCallback & on_completed,
float altitude = NAN,
float heading = NAN);
97 void land(
const CompletedCallback & on_completed);
98 void rtl(
const CompletedCallback & on_completed);
100 void arm(
const CompletedCallback & on_completed);
101 void waitReadyToArm(
const CompletedCallback & on_completed);
102 void waitUntilDisarmed(
const CompletedCallback & on_completed);
104 bool isInCharge()
const {
return _is_in_charge;}
106 bool isArmed()
const {
return _is_armed;}
108 ModeBase & ownedMode() {
return _owned_mode;}
112 rclcpp::Node & node() {
return _node;}
114 ConfigOverrides & configOverrides() {
return _config_overrides;}
134 ScheduledMode(rclcpp::Node & node,
const std::string & topic_namespace_prefix);
136 bool active()
const {
return _mode_id != ModeBase::kModeIDInvalid;}
137 void activate(
ModeBase::ModeID mode_id,
const CompletedCallback & on_completed);
142 void reset() {_mode_id = ModeBase::kModeIDInvalid;}
145 CompletedCallback _on_completed_callback;
146 rclcpp::Subscription<px4_msgs::msg::ModeCompleted>::SharedPtr _mode_completed_sub;
149 class WaitForVehicleStatusCondition
152 using RunCheckCallback =
153 std::function<bool (
const px4_msgs::msg::VehicleStatus::UniquePtr & msg)>;
154 WaitForVehicleStatusCondition() =
default;
156 bool active()
const {
return _on_completed_callback !=
nullptr;}
157 void update(
const px4_msgs::msg::VehicleStatus::UniquePtr & msg);
160 const RunCheckCallback & run_check_callback,
161 const CompletedCallback & on_completed);
165 CompletedCallback _on_completed_callback;
166 RunCheckCallback _run_check_callback;
171 void callOnActivate();
172 void callOnDeactivate(DeactivateReason reason);
174 void vehicleStatusUpdated(
const px4_msgs::msg::VehicleStatus::UniquePtr & msg);
178 const ModeExecutorBase::CompletedCallback & on_completed);
180 rclcpp::Node & _node;
181 const std::string _topic_namespace_prefix;
182 const Settings _settings;
183 ModeBase & _owned_mode;
185 std::shared_ptr<Registration> _registration;
187 rclcpp::Subscription<px4_msgs::msg::VehicleStatus>::SharedPtr _vehicle_status_sub;
188 rclcpp::Publisher<px4_msgs::msg::VehicleCommand>::SharedPtr _vehicle_command_pub;
189 rclcpp::Subscription<px4_msgs::msg::VehicleCommandAck>::SharedPtr _vehicle_command_ack_sub;
191 ScheduledMode _current_scheduled_mode;
192 WaitForVehicleStatusCondition _current_wait_vehicle_status;
194 bool _is_in_charge{
false};
195 bool _is_armed{
false};
196 bool _was_never_activated{
true};
198 uint8_t _prev_failsafe_defer_state{px4_msgs::msg::VehicleStatus::FAILSAFE_DEFER_STATE_DISABLED};
200 ConfigOverrides _config_overrides;
uint8_t ModeID
Mode ID, corresponds to nav_state.
Definition: mode.hpp:72
Base class for a mode executor.
Definition: mode_executor.hpp:31
virtual void onDeactivate(DeactivateReason reason)=0
bool deferFailsafesSync(bool enabled, int timeout_s=0)
Result sendCommandSync(uint32_t command, float param1=NAN, float param2=NAN, float param3=NAN, float param4=NAN, float param5=NAN, float param6=NAN, float param7=NAN)
void scheduleMode(ModeBase::ModeID mode_id, const CompletedCallback &on_completed)
virtual void onFailsafeDeferred()
Definition: mode_executor.hpp:79
virtual void onActivate()=0
Result
Definition: mode.hpp:30
Definition: mode_executor.hpp:36
Activation
Definition: mode_executor.hpp:38
@ ActivateAlways
Allow the executor to always be activated (so it can arm the vehicle)
@ ActivateOnlyWhenArmed
Only activate the executor when armed (and selected)
@ ActivateImmediately
Activate the mode and executor immediately after registration. Only use this for fully autonomous exe...