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 const 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 // The waypoint this entry navigated to: the navigator has already moved its index to the next one.
63 const auto & current_waypoint_name = sentWaypointName_;
64 const char * current = current_waypoint_name ? current_waypoint_name->c_str() : "(none)";
65
66 if (current_waypoint_name && *current_waypoint_name == this->goalWaypointName_)
67 {
68 RCLCPP_INFO(
69 getLogger(), "[CbNavigateNextWaypointUntilReached] GoalReached, waypoint with name '%s'",
70 current);
71
73 }
74 else
75 {
76 RCLCPP_INFO(
77 getLogger(),
78 "[CbNavigateNextWaypointUntilReached] goal:'%s' current:'%s'. keep navigating.",
79 goalWaypointName_.c_str(), current);
80 }
81
82 this->postSuccessEvent();
83 }
84
85private:
86 std::string goalWaypointName_;
87
88 // set in onEntry, before the goal is sent
89 std::optional<std::string> sentWaypointName_;
90
91 std::function<void()> postEvGoalWaypointReached_;
92};
93} // namespace cl_nav2z
void onNavigationActionSuccess(const components::CpNav2ActionInterface::WrappedResult &r) override
CbNavigateNextWaypointUntilReached(std::string goalWaypointName, const std::optional< NavigateNextWaypointOptions > &options=std::nullopt)
virtual rclcpp::Logger getLogger() const