SMACC2
Loading...
Searching...
No Matches
cb_wait_for_heading_stable.hpp
Go to the documentation of this file.
1// Copyright 2026 RobosoftAI 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#pragma once
16
18#include <rclcpp/rclcpp.hpp>
19#include <smacc2/smacc.hpp>
20
21#include <cmath>
22#include <limits>
23
24namespace cl_px4_mr
25{
26
27// Preflight gate on the EKF heading. A vehicle sitting still on the ground must
28// report a constant heading; if the estimate is drifting, the yaw gyro bias
29// has not converged (or the magnetometer has been rejected) and a takeoff in
30// that state is unstable: with a large heading error the position loop pushes
31// the wrong way and the vehicle flips over (sm_cl_px4_mr_test_5 run 19: 186
32// degrees of drift in 30 s, crash 4 s after liftoff).
33//
34// Success when the heading moved less than maxDriftRadS * windowS over the
35// last windowS seconds (and, if expectedHeadingRad is finite, is also within
36// headingTolRad of it). Failure on timeout, with the drift rate in the log.
38{
39 double maxDriftRadS = 0.0087; // 0.5 deg/s
40 double windowS = 5.0;
41 double timeoutS = 60.0;
42 // known heading of the parked vehicle (NED, rad); NaN = do not check
43 float expectedHeadingRad = std::numeric_limits<float>::quiet_NaN();
44 float headingTolRad = 0.26f; // 15 deg
45};
46
48{
49public:
50 explicit CbWaitForHeadingStable(HeadingStableParams params = {});
51
52 void onEntry() override;
53 void onExit() override {}
54
55private:
57};
58
59} // namespace cl_px4_mr
CbWaitForHeadingStable(HeadingStableParams params={})