SMACC2
Loading...
Searching...
No Matches
cb_arm_px4.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
18
19#include <chrono>
20#include <thread>
21
22namespace cl_px4_mr
23{
24
26
28{
31
34
35 for (int attempt = 0; attempt < MAX_RETRIES; attempt++)
36 {
37 if (attempt < 2)
38 {
39 RCLCPP_INFO(
40 getLogger(), "CbArmPX4: sending arm command (attempt %d/%d)", attempt + 1, MAX_RETRIES);
42 }
43 else
44 {
45 RCLCPP_WARN(getLogger(), "CbArmPX4: force-arming (attempt %d/%d)", attempt + 1, MAX_RETRIES);
47 }
48
49 // Wait for armed confirmation or timeout
50 for (int i = 0; i < RETRY_INTERVAL_SEC * 10; i++)
51 {
52 if (armed_) break;
53 std::this_thread::sleep_for(std::chrono::milliseconds(100));
54 }
55
56 if (armed_)
57 {
58 RCLCPP_INFO(getLogger(), "CbArmPX4: vehicle ARMED - posting success");
59 this->postSuccessEvent();
60 return;
61 }
62
63 RCLCPP_WARN(
64 getLogger(), "CbArmPX4: attempt %d/%d timed out, retrying...", attempt + 1, MAX_RETRIES);
65 }
66
67 RCLCPP_ERROR(getLogger(), "CbArmPX4: all %d attempts failed - posting failure", MAX_RETRIES);
68 this->postFailureEvent();
69}
70
72
74
75} // namespace cl_px4_mr
std::atomic< bool > armed_
void onExit() override
CpVehicleStatus * vehicleStatus_
void onEntry() override
static constexpr int MAX_RETRIES
CpVehicleCommand * vehicleCommand_
static constexpr int RETRY_INTERVAL_SEC
smacc2::SmaccSignal< void()> onArmed_
virtual rclcpp::Logger getLogger() const
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
smacc2::SmaccSignalConnection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)