SMACC2
Loading...
Searching...
No Matches
angle_utils.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
17#include <cmath>
18
19namespace cl_px4_mr
20{
21
22// Wrap an angle to [-pi, pi]. PX4 heading and yaw setpoints are absolute wrapped
23// angles; any arithmetic on them (base heading + sine offset) must re-wrap before
24// being commanded or compared.
25inline float wrapPi(float angle)
26{
27 angle = std::fmod(angle + static_cast<float>(M_PI), 2.0f * static_cast<float>(M_PI));
28 if (angle < 0.0f)
29 {
30 angle += 2.0f * static_cast<float>(M_PI);
31 }
32 return angle - static_cast<float>(M_PI);
33}
34
35} // namespace cl_px4_mr
float wrapPi(float angle)