SMACC2
Loading...
Searching...
No Matches
smacc2_client_library
cl_px4_mr
src
cl_px4_mr
components
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
15
#include <
cl_px4_mr/components/cp_offboard_keep_alive.hpp
>
16
#include <
cl_px4_mr/components/cp_trajectory_setpoint.hpp
>
17
18
namespace
cl_px4_mr
19
{
20
21
CpOffboardKeepAlive::CpOffboardKeepAlive
() {}
22
23
CpOffboardKeepAlive::~CpOffboardKeepAlive
() {}
24
25
void
CpOffboardKeepAlive::onInitialize
()
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
31
this->
requiresComponent
(
trajectorySetpoint_
);
32
33
RCLCPP_INFO(
getLogger
(),
"CpOffboardKeepAlive: initialized (disabled)"
);
34
}
35
36
void
CpOffboardKeepAlive::update
()
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
54
if
(
trajectorySetpoint_
)
55
{
56
trajectorySetpoint_
->
republishLast
();
57
}
58
}
59
60
void
CpOffboardKeepAlive::enable
()
61
{
62
enabled_
=
true
;
63
RCLCPP_INFO(
getLogger
(),
"CpOffboardKeepAlive: ENABLED"
);
64
}
65
66
void
CpOffboardKeepAlive::disable
()
67
{
68
enabled_
=
false
;
69
RCLCPP_INFO(
getLogger
(),
"CpOffboardKeepAlive: DISABLED"
);
70
}
71
72
bool
CpOffboardKeepAlive::isEnabled
()
const
{
return
enabled_
; }
73
74
}
// namespace cl_px4_mr
cl_px4_mr::CpOffboardKeepAlive::enabled_
bool enabled_
Definition
cp_offboard_keep_alive.hpp:42
cl_px4_mr::CpOffboardKeepAlive::~CpOffboardKeepAlive
virtual ~CpOffboardKeepAlive()
Definition
cp_offboard_keep_alive.cpp:23
cl_px4_mr::CpOffboardKeepAlive::publisher_
rclcpp::Publisher< px4_msgs::msg::OffboardControlMode >::SharedPtr publisher_
Definition
cp_offboard_keep_alive.hpp:40
cl_px4_mr::CpOffboardKeepAlive::trajectorySetpoint_
CpTrajectorySetpoint * trajectorySetpoint_
Definition
cp_offboard_keep_alive.hpp:41
cl_px4_mr::CpOffboardKeepAlive::onInitialize
void onInitialize() override
Definition
cp_offboard_keep_alive.cpp:25
cl_px4_mr::CpOffboardKeepAlive::update
void update() override
Definition
cp_offboard_keep_alive.cpp:36
cl_px4_mr::CpOffboardKeepAlive::enable
void enable()
Definition
cp_offboard_keep_alive.cpp:60
cl_px4_mr::CpOffboardKeepAlive::CpOffboardKeepAlive
CpOffboardKeepAlive()
Definition
cp_offboard_keep_alive.cpp:21
cl_px4_mr::CpOffboardKeepAlive::isEnabled
bool isEnabled() const
Definition
cp_offboard_keep_alive.cpp:72
cl_px4_mr::CpOffboardKeepAlive::disable
void disable()
Definition
cp_offboard_keep_alive.cpp:66
cl_px4_mr::CpTrajectorySetpoint::republishLast
void republishLast()
Definition
cp_trajectory_setpoint.cpp:85
smacc2::ISmaccComponent::getLogger
rclcpp::Logger getLogger() const
Definition
smacc_component.cpp:44
smacc2::ISmaccComponent::requiresComponent
void requiresComponent(TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
Definition
smacc_component_impl.hpp:44
smacc2::ISmaccComponent::getNode
rclcpp::Node::SharedPtr getNode()
Definition
smacc_component.cpp:42
cp_offboard_keep_alive.hpp
cp_trajectory_setpoint.hpp
cl_px4_mr
Definition
cl_px4_mr.hpp:28
Generated by
1.12.0