SMACC2
Loading...
Searching...
No Matches
cp_offboard_keep_alive.cpp
Go to the documentation of this file.
1// Copyright 2025 Robosoft Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
17
18namespace cl_px4_mr
19{
20
22
24
26{
27 auto node = this->getNode();
28 publisher_ = node->create_publisher<px4_msgs::msg::OffboardControlMode>(
29 "/fmu/in/offboard_control_mode", rclcpp::QoS(1).best_effort());
30
32
33 RCLCPP_INFO(getLogger(), "CpOffboardKeepAlive: initialized (disabled)");
34}
35
37{
38 if (!enabled_) return;
39
40 auto node = this->getNode();
41
42 px4_msgs::msg::OffboardControlMode msg;
43 msg.timestamp = node->get_clock()->now().nanoseconds() / 1000;
44 msg.position = true;
45 msg.velocity = false;
46 msg.acceleration = false;
47 msg.attitude = false;
48 msg.body_rate = false;
49 msg.thrust_and_torque = false;
50 msg.direct_actuator = false;
51 publisher_->publish(msg);
52
53 // Republish the latest trajectory setpoint to keep PX4 happy
55 {
57 }
58}
59
61{
62 enabled_ = true;
63 RCLCPP_INFO(getLogger(), "CpOffboardKeepAlive: ENABLED");
64}
65
67{
68 enabled_ = false;
69 RCLCPP_INFO(getLogger(), "CpOffboardKeepAlive: DISABLED");
70}
71
73
74} // namespace cl_px4_mr
rclcpp::Publisher< px4_msgs::msg::OffboardControlMode >::SharedPtr publisher_
rclcpp::Logger getLogger() const
void requiresComponent(TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
rclcpp::Node::SharedPtr getNode()