SMACC2
Loading...
Searching...
No Matches
cb_abort_navigation.cpp
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
21#include <cl_nav2z/cl_nav2z.hpp>
23#include <cl_nav2z/common.hpp>
27
28#include <chrono>
29#include <thread>
30
31#include <rclcpp/parameter_client.hpp>
32
33namespace cl_nav2z
34{
36
38{
39 // connected before the request, so the result of the cancelled goal cannot be missed
40 goalFinished_ = false;
44
46 {
47 RCLCPP_INFO(getLogger(), "[CbAbortNavigation] no navigation goal in flight");
48 this->postSuccessEvent();
49 return;
50 }
51
52 const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(5);
53 while (!goalFinished_)
54 {
55 // the state was left first: no event
56 if (this->isShutdownRequested()) return;
57 if (std::chrono::steady_clock::now() >= deadline)
58 {
59 RCLCPP_ERROR(getLogger(), "[CbAbortNavigation] no result for the cancelled goal after 5 s");
60 this->postFailureEvent();
61 return;
62 }
63 std::this_thread::sleep_for(std::chrono::milliseconds(10));
64 }
65
66 RCLCPP_INFO(getLogger(), "[CbAbortNavigation] the cancelled goal has finished");
67 this->postSuccessEvent();
68}
69
75
77
78} // namespace cl_nav2z
void onNavigationResult(const components::CpNav2ActionInterface::WrappedResult &result)
components::CpNav2ActionInterface * nav2ActionInterface_
smacc2::SmaccSignalConnection onNavigationSucceeded(void(T::*callback)(const WrappedResult &), T *object)
smacc2::SmaccSignalConnection onNavigationAborted(void(T::*callback)(const WrappedResult &), T *object)
smacc2::SmaccSignalConnection onNavigationCancelled(void(T::*callback)(const WrappedResult &), T *object)
virtual rclcpp::Logger getLogger() const
bool isShutdownRequested()
onEntry is executed in a new thread. However the current state cannot be left until the onEntry threa...