SMACC2
Loading...
Searching...
No Matches
cb_nitrosz_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_nitrosz
23{
25
27{
28 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] Creating sending goal callback signal.");
29
30 this->navigationCallback_ = std::make_shared<cl_nitrosz::ClNitrosZ::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 RCLCPP_DEBUG(
84 getLogger(), "[%s] Received result event from action server, result code", getName().c_str());
85
86 if (r.code == rclcpp_action::ResultCode::SUCCEEDED)
87 {
89 }
90 else
91 {
93 }
94}
95
97{
98 // if (!isOwnActionResponse(r))
99 // {
100 // RCLCPP_WARN(
101 // getLogger(), "[%s] Propagating success event skipped. Action response is not ours.",
102 // getName().c_str());
103 // return;
104 // }
105
106 navigationResult_ = r.code;
107
108 RCLCPP_INFO(getLogger(), "[%s] Propagating success event from action server", getName().c_str());
109 this->postSuccessEvent();
110}
111
113{
114 // if (!isOwnActionResponse(r))
115 // {
116 // RCLCPP_WARN(
117 // getLogger(), "[%s] Propagating success event skipped. Action response is not ours.",
118 // getName().c_str());
119 // return;
120 // }
121
122 navigationResult_ = r.code;
123 auto name = getName();
124 RCLCPP_INFO(getLogger(), "[%s] Propagating failure event from action server", name.c_str());
125 this->postFailureEvent();
126}
127} // namespace cl_nitrosz
std::shared_future< std::shared_ptr< rclcpp_action::ClientGoalHandle< nav2_msgs::action::NavigateToPose > > > goalHandleFuture_
virtual void onNavigationActionAbort(const ClNitrosZ::WrappedResult &)
bool isOwnActionResponse(const ClNitrosZ::WrappedResult &)
cl_nitrosz::ClNitrosZ::SmaccNavigateResultSignal::SharedPtr navigationCallback_
virtual void onNavigationResult(const ClNitrosZ::WrappedResult &)
virtual void onNavigationActionSuccess(const ClNitrosZ::WrappedResult &)
virtual rclcpp::Logger getLogger() const
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)
bool isShutdownRequested()
onEntry is executed in a new thread. However the current state cannot be left until the onEntry threa...
std::shared_future< typename GoalHandle::SharedPtr > sendGoal(Goal &goal, typename SmaccActionResultSignal::WeakPtr resultCallback=typename SmaccActionResultSignal::WeakPtr())
std::string demangleType(const std::type_info *tinfo)