SMACC2
Loading...
Searching...
No Matches
cb_navigate_next_waypoint_until_reached.hpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI 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 // if (!isOwnActionResponse(r))
58 // {
59 // RCLCPP_WARN(
60 // getLogger(), "[%s] Propagating success event skipped. Action response is not ours.",
61 // getName().c_str());
62 // return;
63 // }
64
65 navigationResult_ = r.code;
66
67 RCLCPP_INFO(
68 getLogger(), "[%s] Propagating success event from action server", getName().c_str());
69
70 this->requiresComponent(waypointsNavigator_, ComponentRequirement::HARD);
71
72 auto current_waypoint_name = waypointsNavigator_->getCurrentWaypointName();
73
74 if (current_waypoint_name == this->goalWaypointName_)
75 {
76 RCLCPP_INFO(
77 getLogger(),
78 "[CbNavigateNextWaypointUntilReached] GoalReached current iteration waypoint i: %ld with "
79 "name '%s'",
80 waypointsNavigator_->getCurrentWaypointIndex(), current_waypoint_name->c_str());
81
83 }
84 else
85 {
86 RCLCPP_INFO(
87 getLogger(),
88 "[CbNavigateNextWaypointUntilReached] goal:'%s' current:'%s'. keep navigating.",
89 goalWaypointName_.c_str(), current_waypoint_name->c_str());
90 }
91
92 this->postSuccessEvent();
93 }
94
95private:
96 std::string goalWaypointName_;
97
98 std::function<void()> postEvGoalWaypointReached_;
99};
100} // 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)