NavigateTo.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 Markus Grotz ( Markus Grotz <markus dot grotz at kit dot edu> )
18 * @date 2022
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#include "NavigateTo.h"
24
25#include <Eigen/Geometry>
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 NavigateTo::SubClassRegistry NavigateTo::Registry(NavigateTo::GetName(),
52
53 void
55 {
56 // put your user code for the enter-point here
57 // execution time should be short (<100ms)
58 }
59
60 void
62 {
63 const auto v = in.getTargetPosition();
64
65
66 ARMARX_INFO << VAROUT(v);
67
68 core::Pose target = core::Pose::Identity();
69 target.linear() = Eigen::AngleAxisf(v->z, Eigen::Vector3f::UnitZ()).toRotationMatrix();
70 target.translation().head<2>() = Eigen::Vector2f(v->x, v->y);
71
72 ARMARX_INFO << "moving to target " << VAROUT(target.matrix());
73
74 // parameterize the navigation stack
76 cfg.general(core::GeneralConfig{}); //TODO: set velocity limits
78
79 // configure the `navigator` which provides a simplified and typed interface to the navigation server
80 client::IceNavigatorFactory iceNavigatorFactory(getNavigator());
81
82 armem::client::MemoryNameSystem mns(getMemoryNameSystem());
83
84 client::MemoryPolling memoryEventPolling(GetName(), mns);
85
86 // register our config
87 ARMARX_INFO << "Registering config";
88 client::NavigatorHandlePtr iceNavigator = iceNavigatorFactory.createConfig(cfg, GetName());
89
91 .navigator = iceNavigator.get(), .subscriber = &memoryEventPolling}};
92
93 // assemble the path, which might consist of waypoints and a goal (the goal is just the last `waypoint`)
94
95 // execute
96 ARMARX_INFO << "Sending navigation request";
97 navigator.moveTo(target, core::NavigationFrame::Absolute);
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.getTargetPosition()) << "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 NavigateTo::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} // namespace armarx::navigation::statecharts::navigation_group
#define VAROUT(x)
#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
NavigateTo(const XMLStateConstructorParams &stateData)
Definition NavigateTo.h:31
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
std::unique_ptr< core::NavigatorInterface > NavigatorHandlePtr
Eigen::Isometry3f Pose
Definition basic_types.h:31
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64