77 static constexpr ModeID kModeIDInvalid = 0xff;
79 static constexpr ModeID kModeIDPosctl = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_POSCTL;
80 static constexpr ModeID kModeIDTakeoff =
81 px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_TAKEOFF;
82 static constexpr ModeID kModeIDDescend = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_DESCEND;
83 static constexpr ModeID kModeIDLand = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_LAND;
84 static constexpr ModeID kModeIDRtl = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_RTL;
85 static constexpr ModeID kModeIDPrecisionLand =
86 px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_PRECLAND;
87 static constexpr ModeID kModeIDLoiter =
88 px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_LOITER;
92 Settings(std::string mode_name) :
name(std::move(mode_name)) {}
101 Settings& activateEvenWhileDisarmed(
bool activate)
106 Settings& replaceInternalMode(
ModeID mode)
111 Settings& preventArming(
bool prevent)
116 Settings& userSelectable(
bool selectable)
123 ModeBase(rclcpp::Node& node, Settings settings,
const std::string& topic_namespace_prefix =
"");
124 ModeBase(
const ModeBase&) =
delete;
162 virtual void updateSetpoint(
float dt_s) {}
175 bool isArmed()
const {
return _is_armed; }
177 bool isActive()
const {
return _is_active; }
179 ConfigOverrides& configOverrides() {
return _config_overrides; }
208 void setSkipMessageCompatibilityCheck() { _skip_message_compatibility_check =
true; }
209 void setSkipSetpointCheck() { _skip_setpoint_check =
true; }
210 void overrideRegistration(
const std::shared_ptr<Registration>& registration);
212 void disableWatchdogTimer() { _health_and_arming_checks.disableWatchdogTimer(); }
214 void setWatchdogTimeoutCallback(HealthAndArmingChecks::WatchdogTimeoutCallback callback)
219 bool defaultMessageCompatibilityCheck();
222 void addSetpointType(SetpointBase* setpoint)
override;
223 void setRequirement(
const RequirementFlags& requirement_flags)
override;
225 friend class ModeExecutorBase;
226 RegistrationSettings getRegistrationSettings()
const;
227 void onAboutToRegister();
230 void unsubscribeVehicleStatus();
231 void vehicleStatusUpdated(
const px4_msgs::msg::VehicleStatus::UniquePtr& msg,
232 bool do_not_activate =
false);
234 void callOnActivate();
235 void callOnDeactivate();
237 void updateSetpointUpdateTimer();
239 void checkSetpointCompatibilityAndRequirements();
240 void setSetpointUpdateRateFromSetpointTypes();
241 void activateSetpointType(
const std::shared_ptr<SetpointBase>& setpoint);
242 void deactivateAllSetpointTypes();
244 std::shared_ptr<Registration> _registration;
246 const Settings _settings;
247 bool _skip_message_compatibility_check{
false};
248 bool _skip_setpoint_check{
false};
250 HealthAndArmingChecks _health_and_arming_checks;
252 rclcpp::Publisher<px4_msgs::msg::ModeCompleted>::SharedPtr _mode_completed_pub;
253 rclcpp::Publisher<px4_msgs::msg::SetpointConfig>::SharedPtr _setpoint_config_pub;
254 SharedSubscriptionCallbackInstance _setpoint_config_reply_sub_cb;
256 SharedSubscriptionCallbackInstance _vehicle_status_sub_cb;
258 bool _is_active{
false};
259 bool _is_armed{
false};
260 bool _completed{
false};
262 float _setpoint_update_rate_hz{0.f};
263 rclcpp::TimerBase::SharedPtr _setpoint_update_timer;
264 rclcpp::Time _last_setpoint_update{};
266 ConfigOverrides _config_overrides;
267 uint8_t _prev_failsafe_defer_state{px4_msgs::msg::VehicleStatus::FAILSAFE_DEFER_STATE_DISABLED};
269 std::vector<std::shared_ptr<SetpointBase>> _setpoint_types;
270 std::vector<SetpointBase*>
272 std::shared_ptr<SetpointBase> _current_activating_setpoint;
Definition context.hpp:18