SMACC2
Loading...
Searching...
No Matches
cb_nav2z_client_behavior_base.cpp
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 ******************************************************************************************************************/
22namespace cl_nav2z
23{
25
27{
28 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] Creating sending goal callback signal.");
29
30 this->navigationCallback_ = std::make_shared<cl_nav2z::ClNav2Z::SmaccNavigateResultSignal>();
31
34
35 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] Sending goal");
37 RCLCPP_INFO_STREAM(
38 getLogger(), "[" << getName() << "] Goal set, future valid: " << goalHandleFuture_.valid());
39
40 // this->goal_uuid_ = gh.get_goal_id () ;
41}
42
44
46{
47 auto name = getName();
49 {
50 RCLCPP_ERROR(
51 getLogger(), "[%s] Propagating action client signal skipped. the behavior is shutting down",
52 name.c_str());
53 return false;
54 }
55
56 if (!goalHandleFuture_.valid())
57 {
58 RCLCPP_ERROR(
59 this->getLogger(), "[%s]Propagating action client signal, our goal handle is not valid",
60 name.c_str());
61 return false;
62 }
63
64 auto goalHandle = goalHandleFuture_.get();
65 auto goal_uuid_ = goalHandle->get_goal_id();
66
67 if (r.goal_id != goal_uuid_)
68 {
69 RCLCPP_ERROR(
70 getLogger(),
71 "[%s] Received a failure event from an action server with a different goal_uuid: %s, "
72 "expected: %s",
73 smacc2::demangleType(typeid(*this)).c_str(), rclcpp_action::to_string(r.goal_id).c_str(),
74 rclcpp_action::to_string(goal_uuid_).c_str());
75 return false;
76 }
77
78 return true;
79}
80
82{
83 if (r.code == rclcpp_action::ResultCode::SUCCEEDED)
84 {
86 }
87 else
88 {
90 }
91}
92
94{
95 // if (!isOwnActionResponse(r))
96 // {
97 // RCLCPP_WARN(
98 // getLogger(), "[%s] Propagating success event skipped. Action response is not ours.",
99 // getName().c_str());
100 // return;
101 // }
102
103 navigationResult_ = r.code;
104
105 RCLCPP_INFO(getLogger(), "[%s] Propagating success event from action server", getName().c_str());
106 this->postSuccessEvent();
107}
108
110{
111 // if (!isOwnActionResponse(r))
112 // {
113 // RCLCPP_WARN(
114 // getLogger(), "[%s] Propagating success event skipped. Action response is not ours.",
115 // getName().c_str());
116 // return;
117 // }
118
119 navigationResult_ = r.code;
120 auto name = getName();
121 RCLCPP_INFO(getLogger(), "[%s] Propagating failure event from action server", name.c_str());
122 this->postFailureEvent();
123}
124} // namespace cl_nav2z
virtual void onNavigationResult(const ClNav2Z::WrappedResult &)
std::shared_future< std::shared_ptr< rclcpp_action::ClientGoalHandle< nav2_msgs::action::NavigateToPose > > > goalHandleFuture_
bool isOwnActionResponse(const ClNav2Z::WrappedResult &)
cl_nav2z::ClNav2Z::SmaccNavigateResultSignal::SharedPtr navigationCallback_
virtual void onNavigationActionSuccess(const ClNav2Z::WrappedResult &)
virtual void onNavigationActionAbort(const ClNav2Z::WrappedResult &)
virtual rclcpp::Logger getLogger() const
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)
std::shared_future< typename GoalHandle::SharedPtr > sendGoal(Goal &goal, typename SmaccActionResultSignal::WeakPtr resultCallback=typename SmaccActionResultSignal::WeakPtr())
std::string demangleType(const std::type_info *tinfo)