NavigateToLocation.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package navigation::NavigationGroup
17 * @author armar-user ( armar-user at kit dot edu )
18 * @date 2021
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#include "NavigateToLocation.h"
24
25#include <optional>
26
28
32
43
44//#include <ArmarXCore/core/time/TimeUtil.h>
45//#include <ArmarXCore/observers/variant/DatafieldRef.h>
46
48{
49 // DO NOT EDIT NEXT LINE
50 NavigateToLocation::SubClassRegistry
51 NavigateToLocation::Registry(NavigateToLocation::GetName(),
53
54 void
56 {
57 ARMARX_INFO << "onEnter ...";
58 // put your user code for the enter-point here
59 // execution time should be short (<100ms)
60 }
61
62 void
64 {
65 ARMARX_IMPORTANT << "Navigating to location " << QUOTED(in.getlocation());
66
67 // parameterize the navigation stack
69 cfg.general(core::GeneralConfig{}); //TODO: set velocity limits
71
72 // configure the `navigator` which provides a simplified and typed interface to the navigation server
73 client::IceNavigatorFactory iceNavigatorFactory(getNavigator());
74
75 armem::client::MemoryNameSystem mns(getMemoryNameSystem());
76
77 client::MemoryPolling memoryEventPolling(GetName(), mns);
78
79 // register our config
80 ARMARX_INFO << "Registering config";
81 client::NavigatorHandlePtr iceNavigator = iceNavigatorFactory.createConfig(cfg, GetName());
82
83 client::Navigator navigator{
84 client::Navigator::InjectedServices{.navigator = iceNavigator.get(),
85 .subscriber = &memoryEventPolling}};
86
87 ARMARX_CHECK_NOT_EMPTY(in.getlocation());
88
89 std::optional<std::string> locationProvider = std::nullopt;
90 if (not in.getlocationProvider().empty())
91 {
92 locationProvider = in.getlocationProvider();
93 }
94
95 // execute
96 ARMARX_INFO << "Sending navigation request";
97 navigator.moveToLocation(in.getlocation(), locationProvider);
98
99 // Wait until goal is reached
100 ARMARX_INFO << "Waiting until goal is reached.";
101 client::StopEvent se = navigator.waitForStop();
102 if (se)
103 {
104 ARMARX_INFO << "Goal " << QUOTED(in.getlocation()) << "reached.";
105 }
106 else
107 {
109 {
110 ARMARX_ERROR << "Safety stop was triggered!";
111 emitFailure();
112 }
113 else if (se.isUserAbortTriggeredEvent())
114 {
115 ARMARX_ERROR << "Aborted by user!";
116 emitFailure();
117 }
118 else if (se.isInternalErrorEvent())
119 {
120 ARMARX_ERROR << "Unknown internal error occured! "
122 emitFailure();
123 }
124 }
125
126 emitSuccess();
127 }
128
129 //void NavigateToLocation::onBreak()
130 //{
131 // // put your user code for the breaking point here
132 // // execution time should be short (<100ms)
133 //}
134
135 void
137 {
138 // put your user code for the exit point here
139 // execution time should be short (<100ms)
140 }
141
142 // DO NOT EDIT NEXT FUNCTION
148
149} // namespace armarx::navigation::statecharts::navigation_group
#define ARMARX_CHECK_NOT_EMPTY(c)
#define QUOTED(x)
The memory name system (MNS) client.
NavigatorHandlePtr createConfig(const client::NavigationStackConfig &config, const std::string &configId) override
Create a Config object.
NavigationStackConfig & globalPlanner(const global_planning::GlobalPlannerParams &params)
NavigationStackConfig & general(const core::GeneralConfig &cfg)
core::InternalErrorEvent & toInternalErrorEvent()
Definition Navigator.h:95
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
std::unique_ptr< core::NavigatorInterface > NavigatorHandlePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64