SMACC2
Loading...
Searching...
No Matches
cb_absolute_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
15/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20
21#include <cl_nav2z/cl_nav2z.hpp>
23#include <cl_nav2z/common.hpp>
27
28namespace cl_nav2z
29{
30using namespace smacc2;
31
33CbAbsoluteRotate::CbAbsoluteRotate(float absoluteGoalAngleDegree)
34{
35 this->absoluteGoalAngleDegree = absoluteGoalAngleDegree;
36}
37
39{
40 listener = std::make_shared<tf2_ros::Buffer>(getNode()->get_clock());
41 double goal_angle = this->absoluteGoalAngleDegree;
42
43 RCLCPP_INFO_STREAM(getLogger(), "[CbAbsoluteRotate] Absolute yaw Angle:" << goal_angle);
44
45 CpPlannerSwitcher * plannerSwitcher = nullptr;
46 this->requiresComponent(plannerSwitcher, ComponentRequirement::SOFT);
47
48 if (plannerSwitcher == nullptr)
49 {
50 RCLCPP_WARN(
51 getLogger(), "[%s] no CpPlannerSwitcher; planners left as they are", getName().c_str());
52 }
54 {
55 plannerSwitcher->setPureSpinningPlanner();
56 }
57 else
58 {
59 plannerSwitcher->setDefaultPlanners();
60 }
61
62 cl_nav2z::CpPose * p = nullptr;
63 this->requiresComponent(p, ComponentRequirement::HARD);
64
65 auto referenceFrame = p->getReferenceFrame();
66 auto currentPoseMsg = p->toPoseMsg();
67
68 nav2_msgs::action::NavigateToPose::Goal goal;
69 goal.pose.header.frame_id = referenceFrame;
70
71 auto targetAngle = goal_angle * M_PI / 180.0;
72 goal.pose.pose.position = currentPoseMsg.position;
73 tf2::Quaternion q;
74 q.setRPY(0, 0, targetAngle);
75 goal.pose.pose.orientation = tf2::toMsg(q);
76
77 cl_nav2z::odom_tracker::CpOdomTracker * odomTracker_ = nullptr;
78 this->requiresComponent(odomTracker_, ComponentRequirement::SOFT);
79
80 if (odomTracker_ != nullptr)
81 {
82 auto pathname = this->getCurrentState()->getName() + " - " + getName();
83 odomTracker_->pushPath(pathname);
84 odomTracker_->setStartPoint(p->toPoseStampedMsg());
85 odomTracker_->setCurrentMotionGoal(goal.pose);
87 }
88
89 CpGoalCheckerSwitcher * goalCheckerSwitcher = nullptr;
90 this->requiresComponent(goalCheckerSwitcher, ComponentRequirement::HARD);
91
92 goalCheckerSwitcher->setGoalCheckerId("absolute_rotate_goal_checker");
93
94 RCLCPP_INFO_STREAM(
95 getLogger(),
96 "[" << getName() << "] current pose yaw: " << tf2::getYaw(currentPoseMsg.orientation));
97 RCLCPP_INFO_STREAM(
98 getLogger(),
99 "[" << getName() << "] goal pose yaw: " << tf2::getYaw(goal.pose.pose.orientation));
100 this->sendGoal(goal);
101}
102
103} // namespace cl_nav2z
std::optional< SpinningPlanner > spinningPlanner
std::shared_ptr< tf2_ros::Buffer > listener
void setGoalCheckerId(std::string goal_checker_id)
void setPureSpinningPlanner(bool commit=true)
void setDefaultPlanners(bool commit=true)
geometry_msgs::msg::Pose toPoseMsg()
Definition cp_pose.hpp:60
geometry_msgs::msg::PoseStamped toPoseStampedMsg()
Definition cp_pose.hpp:66
const std::string & getReferenceFrame() const
Definition cp_pose.hpp:85
void setCurrentMotionGoal(const geometry_msgs::msg::PoseStamped &pose)
void setWorkingMode(WorkingMode workingMode)
void setStartPoint(const geometry_msgs::msg::PoseStamped &pose)
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
virtual std::string getName()=0