SMACC2
Loading...
Searching...
No Matches
cb_change_altitude.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
19
20namespace cl_px4_mr
21{
22
23CbChangeAltitude::CbChangeAltitude(float targetAltitude) : targetAltitude_(targetAltitude) {}
24
26{
30
33
34 float currentX = localPosition_->getX();
35 float currentY = localPosition_->getY();
36 float currentHeading = localPosition_->getHeading();
37 float targetZ = -targetAltitude_; // NED: up is negative Z
38
39 RCLCPP_INFO(
40 getLogger(), "CbChangeAltitude: changing altitude to %.2f m (NED z=%.2f)", targetAltitude_,
41 targetZ);
42
43 trajectorySetpoint_->setPositionNED(currentX, currentY, targetZ, currentHeading);
44 goalChecker_->setGoal(currentX, currentY, targetZ, 0.5f, 0.3f);
45}
46
48
50{
51 RCLCPP_INFO(getLogger(), "CbChangeAltitude: target altitude reached - posting success");
52 this->postSuccessEvent();
53}
54
55} // namespace cl_px4_mr
CpVehicleLocalPosition * localPosition_
CpTrajectorySetpoint * trajectorySetpoint_
CbChangeAltitude(float targetAltitude)
void setGoal(float x, float y, float z, float xy_tolerance=0.5f, float z_tolerance=0.3f)
smacc2::SmaccSignal< void()> onGoalReached_
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)
smacc2::SmaccSignalConnection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)