SMACC2
Loading...
Searching...
No Matches
cb_sine_altitude_cruise.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
19#include <atomic>
20#include <chrono>
21#include <cmath>
22#include <smacc2/smacc.hpp>
23
24namespace cl_px4_mr
25{
26
27class CpTrajectorySetpoint;
28class CpVehicleLocalPosition;
29
30// Continuous behavior: cruise along a fixed heading while the altitude follows a
31// sine wave around the entry altitude. Never posts success - the state machine must
32// provide the exit event (timer orthogonal, mission event, keyboard). The commanded
33// ground track is UNBOUNDED along the heading; pair with an exit event by
34// construction and rely on the PX4 geofence as the independent backstop.
35// On exit, one final setpoint settles the vehicle at the entry altitude at the last
36// commanded ground position. Posts failure only if local position is invalid at entry.
38{
39public:
41 float groundSpeed = 2.0f, float amplitude = 1.5f, float wavelength = 20.0f,
42 float heading = std::numeric_limits<float>::quiet_NaN());
43
44 void onEntry() override;
45 void onExit() override;
46 void update() override;
47
48private:
52 float heading_;
53
54 float startX_ = 0.0f;
55 float startY_ = 0.0f;
56 float baseZ_ = 0.0f;
57 float arcLength_ = 0.0f;
58 float lastCmdX_ = 0.0f;
59 float lastCmdY_ = 0.0f;
60 std::atomic<bool> active_{false};
61 std::chrono::steady_clock::time_point lastUpdateTime_;
62};
63
64} // namespace cl_px4_mr
CbSineAltitudeCruise(float groundSpeed=2.0f, float amplitude=1.5f, float wavelength=20.0f, float heading=std::numeric_limits< float >::quiet_NaN())
std::chrono::steady_clock::time_point lastUpdateTime_