SMACC2
Loading...
Searching...
No Matches
cb_yaw_rotate.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
19namespace cl_px4_mr
20{
21
22CbYawRotate::CbYawRotate(float targetYawRad, bool relative)
23: targetYawRad_(targetYawRad), relative_(relative)
24{
25}
26
28{
31
32 float currentYaw = localPosition_->getHeading();
33
34 if (relative_)
35 {
36 absoluteTargetYaw_ = currentYaw + targetYawRad_;
37 }
38 else
39 {
41 }
42
43 // Normalize to [-PI, PI]
44 absoluteTargetYaw_ = std::atan2(std::sin(absoluteTargetYaw_), std::cos(absoluteTargetYaw_));
45
46 float curX = localPosition_->getX();
47 float curY = localPosition_->getY();
48 float curZ = localPosition_->getZ();
49
50 RCLCPP_INFO(
51 getLogger(), "CbYawRotate: rotating from %.2f to %.2f rad (relative=%d)", currentYaw,
53
55}
56
58
60{
61 float currentYaw = localPosition_->getHeading();
62
63 // Compute shortest angular distance
64 float diff = absoluteTargetYaw_ - currentYaw;
65 diff = std::atan2(std::sin(diff), std::cos(diff));
66
67 if (std::abs(diff) < 0.1f)
68 {
69 RCLCPP_INFO(
70 getLogger(), "CbYawRotate: target yaw reached (error=%.3f rad) - posting success",
71 std::abs(diff));
72 this->postSuccessEvent();
73 }
74}
75
76} // namespace cl_px4_mr
CbYawRotate(float targetYawRad, bool relative=false)
CpVehicleLocalPosition * localPosition_
void onEntry() override
CpTrajectorySetpoint * trajectorySetpoint_
void setPositionNED(float x, float y, float z, float yaw=std::numeric_limits< float >::quiet_NaN())
virtual rclcpp::Logger getLogger() const
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)