SMACC2
Loading...
Searching...
No Matches
cb_navigate_next_waypoint_until_reached.hpp
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#pragma once
21
24
25namespace cl_nav2z
26{
27template <typename AsyncCB, typename Orthogonal>
28struct EvGoalWaypointReached : sc::event<EvGoalWaypointReached<AsyncCB, Orthogonal>>
29{
30};
31
33{
34public:
36 std::string goalWaypointName,
37 std::optional<NavigateNextWaypointOptions> options = std::nullopt);
38
40
41 template <typename TOrthogonal, typename TSourceObject>
49
50 void onEntry() override;
51
52 void onExit() override;
53
56 {
57 navigationResult_ = r.code;
58
59 RCLCPP_INFO(
60 getLogger(), "[%s] Propagating success event from action server", getName().c_str());
61
62 this->requiresComponent(waypointsNavigator_, ComponentRequirement::HARD);
63
64 auto current_waypoint_name = waypointsNavigator_->getCurrentWaypointName();
65
66 if (current_waypoint_name == this->goalWaypointName_)
67 {
68 RCLCPP_INFO(
69 getLogger(),
70 "[CbNavigateNextWaypointUntilReached] GoalReached current iteration waypoint i: %ld with "
71 "name '%s'",
72 waypointsNavigator_->getCurrentWaypointIndex(), current_waypoint_name->c_str());
73
75 }
76 else
77 {
78 RCLCPP_INFO(
79 getLogger(),
80 "[CbNavigateNextWaypointUntilReached] goal:'%s' current:'%s'. keep navigating.",
81 goalWaypointName_.c_str(), current_waypoint_name->c_str());
82 }
83
84 this->postSuccessEvent();
85 }
86
87private:
88 std::string goalWaypointName_;
89
90 std::function<void()> postEvGoalWaypointReached_;
91};
92} // namespace cl_nav2z
void onNavigationActionSuccess(const components::CpNav2ActionInterface::WrappedResult &r) override
CbNavigateNextWaypointUntilReached(std::string goalWaypointName, std::optional< NavigateNextWaypointOptions > options=std::nullopt)
std::optional< std::string > getCurrentWaypointName() const
virtual rclcpp::Logger getLogger() const
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)