41 RCLCPP_ERROR(
getLogger(),
"CbWaitForHeadingStable: no CpVehicleLocalPosition");
48 "CbWaitForHeadingStable: waiting for the heading to hold within %.2f deg/s over %.0f s%s "
51 checkExpected ?
" and match the parked heading" :
"",
params_.
timeoutS);
54 using clock = std::chrono::steady_clock;
55 const auto start = clock::now();
56 std::deque<std::pair<double, float>> samples;
57 rclcpp::Rate rate(10.0);
58 double lastReport = -10.0;
62 const double t = std::chrono::duration<double>(clock::now() - start).count();
67 while (!samples.empty() && t - samples.front().first >
params_.
windowS)
73 !samples.empty() && samples.back().first - samples.front().first >= 0.9 *
params_.
windowS;
74 float drift = 0.0f, offset = 0.0f;
75 bool stable =
false, aligned =
true;
79 float lo = 0.0f, hi = 0.0f;
80 for (
const auto & s : samples)
82 const float d =
wrapPi(s.second - samples.front().second);
96 if (windowFull && stable && aligned)
100 "CbWaitForHeadingStable: heading %.1f deg stable (%.2f deg over %.0f s%s) - posting "
102 samples.back().second * 180.0 / M_PI, drift * 180.0 / M_PI,
params_.
windowS,
103 checkExpected ? (
", offset " + std::to_string(offset * 180.0 / M_PI) +
" deg").c_str()
110 if (t - lastReport >= 2.0)
116 getLogger(),
"CbWaitForHeadingStable: collecting (%zu samples, position valid=%d)",
123 "CbWaitForHeadingStable: heading %.1f deg NOT ready: drift %.2f deg/s%s - the EKF "
124 "yaw is not trustworthy for takeoff",
125 samples.back().second * 180.0 / M_PI, drift /
params_.
windowS * 180.0 / M_PI,
127 ? (
", offset from parked heading " + std::to_string(offset * 180.0 / M_PI) +
" deg")
138 "CbWaitForHeadingStable: timeout (%.0f s): heading %.1f deg, drift %.2f deg/s. "
139 "Refusing to arm; restart the estimator / SITL",
140 params_.
timeoutS, samples.empty() ? 0.0 : samples.back().second * 180.0 / M_PI,
147 RCLCPP_WARN(
getLogger(),
"CbWaitForHeadingStable: shutdown requested");