SMACC2
Loading...
Searching...
No Matches
cp_goal_checker.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
17
18namespace cl_px4_mr
19{
20
22
24
26{
28 RCLCPP_INFO(getLogger(), "CpGoalChecker: initialized");
29}
30
32{
33 if (!goalActive_ || !localPosition_ || !localPosition_->isValid()) return;
34
35 float dx = localPosition_->getX() - goalX_;
36 float dy = localPosition_->getY() - goalY_;
37 float dz = localPosition_->getZ() - goalZ_;
38 float xyDist = std::sqrt(dx * dx + dy * dy);
39 float zDist = std::abs(dz);
40
41 if (xyDist <= xyTolerance_ && zDist <= zTolerance_)
42 {
43 RCLCPP_INFO(
44 getLogger(), "CpGoalChecker: GOAL REACHED (xy_dist=%.2f z_dist=%.2f)", xyDist, zDist);
45 goalActive_ = false;
47 }
48}
49
50void CpGoalChecker::setGoal(float x, float y, float z, float xy_tolerance, float z_tolerance)
51{
52 goalX_ = x;
53 goalY_ = y;
54 goalZ_ = z;
55 xyTolerance_ = xy_tolerance;
56 zTolerance_ = z_tolerance;
57 goalActive_ = true;
58 RCLCPP_INFO(
59 getLogger(), "CpGoalChecker: goal set [%.2f, %.2f, %.2f] tol(xy=%.2f z=%.2f)", x, y, z,
60 xy_tolerance, z_tolerance);
61}
62
64
66
67} // namespace cl_px4_mr
CpVehicleLocalPosition * localPosition_
void setGoal(float x, float y, float z, float xy_tolerance=0.5f, float z_tolerance=0.3f)
smacc2::SmaccSignal< void()> onGoalReached_
rclcpp::Logger getLogger() const
void requiresComponent(TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)