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>
16 #include <px4_ros2/components/shared_subscription.hpp>
34 using CompletedCallback = std::function<void (
Result)>;
46 Settings & activate(
Activation activation_option)
48 activation = activation_option;
53 enum class DeactivateReason
59 ModeExecutorBase(
const Settings & settings, ModeBase & owned_mode);
60 ModeExecutorBase(
const ModeExecutorBase &) =
delete;
61 virtual ~ModeExecutorBase();
91 uint32_t command,
float param1 = NAN,
float param2 = NAN,
float param3 = NAN,
93 float param5 = NAN,
float param6 = NAN,
float param7 = NAN);
104 bool forced =
false);
106 void takeoff(
const CompletedCallback & on_completed,
float altitude = NAN,
float heading = NAN);
107 void land(
const CompletedCallback & on_completed);
108 void rtl(
const CompletedCallback & on_completed);
110 void arm(
const CompletedCallback & on_completed,
bool run_preflight_checks =
true);
111 void disarm(
const CompletedCallback & on_completed,
bool forced =
false);
112 void waitReadyToArm(
const CompletedCallback & on_completed);
113 void waitUntilDisarmed(
const CompletedCallback & on_completed);
115 bool isInCharge()
const {
return _is_in_charge;}
117 bool isArmed()
const {
return _is_armed;}
119 ModeBase & ownedMode() {
return _owned_mode;}
123 rclcpp::Node & node() {
return _node;}
125 ConfigOverrides & configOverrides() {
return _config_overrides;}
142 void setSkipMessageCompatibilityCheck() {_skip_message_compatibility_check =
true;}
143 void overrideRegistration(
const std::shared_ptr<Registration> & registration);
149 ScheduledMode(rclcpp::Node & node,
const std::string & topic_namespace_prefix);
151 bool active()
const {
return _mode_id != ModeBase::kModeIDInvalid;}
152 void activate(
ModeBase::ModeID mode_id,
const CompletedCallback & on_completed);
157 void reset() {_mode_id = ModeBase::kModeIDInvalid;}
160 CompletedCallback _on_completed_callback;
161 rclcpp::Subscription<px4_msgs::msg::ModeCompleted>::SharedPtr _mode_completed_sub;
164 class WaitForVehicleStatusCondition
167 using RunCheckCallback =
168 std::function<bool (
const px4_msgs::msg::VehicleStatus::UniquePtr & msg)>;
169 WaitForVehicleStatusCondition() =
default;
171 bool active()
const {
return _on_completed_callback !=
nullptr;}
172 void update(
const px4_msgs::msg::VehicleStatus::UniquePtr & msg);
175 const RunCheckCallback & run_check_callback,
176 const CompletedCallback & on_completed);
180 CompletedCallback _on_completed_callback;
181 RunCheckCallback _run_check_callback;
186 void callOnActivate();
187 void callOnDeactivate(DeactivateReason reason);
189 void vehicleStatusUpdated(
const px4_msgs::msg::VehicleStatus::UniquePtr & msg);
193 const ModeExecutorBase::CompletedCallback & on_completed,
bool forced =
false);
195 rclcpp::Node & _node;
196 const std::string _topic_namespace_prefix;
197 const Settings _settings;
198 bool _skip_message_compatibility_check{
false};
199 ModeBase & _owned_mode;
201 std::shared_ptr<Registration> _registration;
203 rclcpp::Publisher<px4_msgs::msg::VehicleCommand>::SharedPtr _vehicle_command_pub;
205 SharedSubscriptionCallbackInstance _vehicle_status_sub_cb;
207 ScheduledMode _current_scheduled_mode;
208 WaitForVehicleStatusCondition _current_wait_vehicle_status;
210 bool _is_in_charge{
false};
211 bool _is_armed{
false};
212 bool _was_never_activated{
true};
214 uint8_t _prev_failsafe_defer_state{px4_msgs::msg::VehicleStatus::FAILSAFE_DEFER_STATE_DISABLED};
216 ConfigOverrides _config_overrides;
uint8_t ModeID
Mode ID, corresponds to nav_state.
Definition: mode.hpp:73
Base class for a mode executor.
Definition: mode_executor.hpp:32
virtual 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)
virtual void onDeactivate(DeactivateReason reason)=0
bool deferFailsafesSync(bool enabled, int timeout_s=0)
void scheduleMode(ModeBase::ModeID mode_id, const CompletedCallback &on_completed, bool forced=false)
virtual void onFailsafeDeferred()
Definition: mode_executor.hpp:84
virtual void onActivate()=0
Result
Definition: mode.hpp:31
Definition: mode_executor.hpp:37
Activation
Definition: mode_executor.hpp:39
@ 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...