NavigateToWithObstacleAvoidance.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 * @author Fabian Reister ( fabian dot reister at kit dot edu )
17 * @date 2023
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
23
24#include <Eigen/Geometry>
25
28
32
44
45//#include <ArmarXCore/core/time/TimeUtil.h>
46//#include <ArmarXCore/observers/variant/DatafieldRef.h>
47
49{
50 // DO NOT EDIT NEXT LINE
51 NavigateToWithObstacleAvoidance::SubClassRegistry
52 NavigateToWithObstacleAvoidance::Registry(NavigateToWithObstacleAvoidance::GetName(),
54
55 void
57 {
58 // put your user code for the enter-point here
59 // execution time should be short (<100ms)
60 }
61
62 void
64 {
65 const auto v = in.getTargetPosition();
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 \n" << VAROUT(target.matrix());
73
74 core::GeneralConfig generalConfig{};
76
77 if (in.isMaxAngularVelocitySet())
78 {
79 generalConfig.maxVel.angular = in.getMaxAngularVelocity();
80 // TODO: what to do when not set
81 }
82
83 if (in.isMaxLinearVelocitySet())
84 {
85 generalConfig.maxVel.linear = in.getMaxLinearVelocity();
86 // TODO: what to do when not set
87 }
88
89 if (in.isRotateIntoMovementDirectionSet())
90 {
91 if (not in.getRotateIntoMovementDirection())
92 {
93 ARMARX_INFO << "Will not rotate into movement direction.";
94 globalPlannerParams.optimizerParams.iterations = 1;
95 globalPlannerParams.optimizerParams.movementDirWeightStart = 0.F;
96 globalPlannerParams.optimizerParams.movementDirWeightEnd = 0.F;
97 }
98 }
99 else
100 {
101 globalPlannerParams.optimizerParams.iterations = 1;
102 globalPlannerParams.optimizerParams.movementDirWeightStart = 0.F;
103 globalPlannerParams.optimizerParams.movementDirWeightEnd = 10.F;
104 }
105
106 if (in.isOrientationOptimizationSmoothnessWeightSet())
107 {
108 ARMARX_CHECK_GREATER_EQUAL(in.getOrientationOptimizationSmoothnessWeight(), 0);
109 globalPlannerParams.optimizerParams.smoothnessWeight =
110 in.getOrientationOptimizationSmoothnessWeight();
111 }
112
113 if (in.isPredefinedRotationDirectionSet())
114 {
116 ARMARX_INFO << "Using predefined rotation direction: "
117 << (in.getPredefinedRotationDirection() ? "Clockwise" : "CounterClockwise");
118 globalPlannerParams.optimizerParams.predefinedRotationDirection =
119 in.getPredefinedRotationDirection() ? RotationDirection::Clockwise
120 : RotationDirection::CounterClockwise;
121 }
122
123
124 // parameterize the navigation stack
126 cfg.general(generalConfig);
127 cfg.globalPlanner(globalPlannerParams);
128
129 if (in.getUseLocalPlanner())
130 {
132 }
133
134 // configure the `navigator` which provides a simplified and typed interface to the navigation server
135 client::IceNavigatorFactory iceNavigatorFactory(getNavigator());
136
137 armem::client::MemoryNameSystem mns(getMemoryNameSystem());
138
139 client::MemoryPolling memoryEventPolling(GetName(), mns);
140
141 // register our config
142 ARMARX_INFO << "Registering config";
143 client::NavigatorHandlePtr iceNavigator = iceNavigatorFactory.createConfig(cfg, GetName());
144
146 .navigator = iceNavigator.get(), .subscriber = &memoryEventPolling}};
147
148 // assemble the path, which might consist of waypoints and a goal (the goal is just the last `waypoint`)
149
150 // execute
151 ARMARX_INFO << "Sending navigation request";
152 navigator.moveTo(target, core::NavigationFrame::Absolute);
153
154 // Wait until goal is reached
155 ARMARX_INFO << "Waiting until goal is reached.";
156 client::StopEvent se = navigator.waitForStop();
157 if (se)
158 {
159 ARMARX_INFO << "Goal " << QUOTED(in.getTargetPosition()) << "reached.";
160 }
161 else
162 {
164 {
165 ARMARX_ERROR << "Safety stop was triggered!";
166 emitFailure();
167 }
168 else if (se.isUserAbortTriggeredEvent())
169 {
170 ARMARX_ERROR << "Aborted by user!";
171 emitFailure();
172 }
173 else if (se.isInternalErrorEvent())
174 {
175 ARMARX_ERROR << "Unknown internal error occured! "
177 emitFailure();
178 }
179 }
180
181 emitSuccess();
182 }
183
184 //void NavigateToWithObstacleAvoidance::onBreak()
185 //{
186 // // put your user code for the breaking point here
187 // // execution time should be short (<100ms)
188 //}
189
190 void
192 {
193 // put your user code for the exit point here
194 // execution time should be short (<100ms)
195 }
196
197 // DO NOT EDIT NEXT FUNCTION
203} // 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 & localPlanner(const local_planning::LocalPlannerParams &params)
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_CHECK_GREATER_EQUAL(lhs, rhs)
This macro evaluates whether lhs is greater or equal (>=) rhs and if it turns out to be false it will...
#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
optimization::OrientationOptimizerParams optimizerParams
Definition SPFA.h:54