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
23
24namespace cl_nav2z
25{
26template <typename AsyncCB, typename Orthogonal>
27struct EvGoalWaypointReached : sc::event<EvGoalWaypointReached<AsyncCB, Orthogonal>>
28{
29};
30
32{
33public:
35 std::string goalWaypointName,
36 std::optional<NavigateNextWaypointOptions> options = std::nullopt);
37
39
40 template <typename TOrthogonal, typename TSourceObject>
42 {
44 CbNavigateNextWaypoint::onOrthogonalAllocation<TOrthogonal, TSourceObject>();
45
47 {
48 this->postEvent<EvGoalWaypointReached<TSourceObject, TOrthogonal>>();
49
50 // nav2zClient_->onSucceeded(&CbNavigateNextWaypointUntilReached::onWaypointReached, this);
51 };
52 }
53
54 void onEntry() override;
55
56 void onExit() override;
57
59 {
60 // if (!isOwnActionResponse(r))
61 // {
62 // RCLCPP_WARN(
63 // getLogger(), "[%s] Propagating success event skipped. Action response is not ours.",
64 // getName().c_str());
65 // return;
66 // }
67
68 navigationResult_ = r.code;
69
70 RCLCPP_INFO(
71 getLogger(), "[%s] Propagating success event from action server", getName().c_str());
72
74
75 auto current_waypoint_name = waypointsNavigator_->getCurrentWaypointName();
76
77 if (current_waypoint_name == this->goalWaypointName_)
78 {
79 RCLCPP_INFO(
80 getLogger(),
81 "[CbNavigateNextWaypointUntilReached] GoalReached current iteration waypoint i: %ld with "
82 "name '%s'",
83 waypointsNavigator_->getCurrentWaypointIndex(), current_waypoint_name->c_str());
84
86 }
87 else
88 {
89 RCLCPP_INFO(
90 getLogger(),
91 "[CbNavigateNextWaypointUntilReached] goal:'%s' current:'%s'. keep navigating.",
92 goalWaypointName_.c_str(), current_waypoint_name->c_str());
93 }
94
95 this->postSuccessEvent();
96 }
97
98private:
99 std::string goalWaypointName_;
100
101 std::function<void()> postEvGoalWaypointReached_;
102};
103} // namespace cl_nav2z
void onNavigationActionSuccess(const ClNav2Z::WrappedResult &r) override
std::optional< std::string > getCurrentWaypointName() const
virtual rclcpp::Logger getLogger() const
void requiresClient(SmaccClientType *&storage)
TComponent * getComponent()