19#include <armarx/navigation/platform_controller/aron/PlatformLocalTrajectoryControllerConfig.aron.generated.h>
30 controllerPlugin_(controllerComponentPlugin),
31 properties_(properties),
32 emergencyStop_(emergencyStop)
36 if (properties_.rtUnitDynamicallyLoadLibraries)
39 <<
"Dynamic loading of the controller library is deactivated (and this "
40 "is also desired). If loading the controllers is failing subsequently, "
41 "make sure that the RobotUnit's property `LoadLibraries` contains "
42 "`armarx_navigation:armarx_navigation_platform_controller`.";
60 ARMARX_INFO <<
"Initializing local trajectory controller";
63 auto builder = controllerPlugin_.createControllerBuilder<
64 armarx::navigation::common::ControllerType::PlatformLocalTrajectory>();
68 const armarx::PackagePath configPath = [&]() -> armarx::PackagePath
70 const armarx::PackagePath baseConfigPath(
71 "armarx_navigation",
"controller_config/PlatformTrajectory/default.json");
73 ARMARX_CHECK(std::filesystem::exists(baseConfigPath.toSystemPath()))
76 const armarx::PackagePath robotSpecificConfigPath(
78 "controller_config/PlatformTrajectory/" + properties_.robotName +
81 if (std::filesystem::exists(robotSpecificConfigPath.toSystemPath()))
83 return robotSpecificConfigPath;
86 return baseConfigPath;
89 auto ctrlWrapper = builder.withNodeSet(
"PlatformPlanning")
90 .withConfig(configPath.toSystemPath())
95 localTrajCtrl_ = std::move(ctrlWrapper);
96 localTrajCtrlInitialConfig_ = localTrajCtrl_->config;
101 ARMARX_INFO <<
"Initializing global trajectory controller";
104 auto builder = controllerPlugin_.createControllerBuilder<
109 builder.withNodeSet(
"PlatformPlanning");
115 "controller_config/GlobalTrajectory/" + properties.robotName +
".json");
117 if (std::filesystem::exists(robotSpecificConfigPath.toSystemPath()))
119 ARMARX_INFO <<
"Using robot specific config: " << robotSpecificConfigPath;
120 builder.withConfig(robotSpecificConfigPath.toSystemPath());
125 "armarx_navigation",
"controller_config/GlobalTrajectory/default.json");
126 builder.withConfig(configPath.toSystemPath());
129 auto ctrlWrapper = builder.create();
133 globalTrajCtrl_ = std::move(ctrlWrapper);
134 globalTrajCtrlInitialConfig_ = globalTrajCtrl_->config;
144 PlatformControllerExecutor::~PlatformControllerExecutor() =
default;
148 const bool activateController)
156 localTrajCtrl_->updateConfig();
158 if (activateController and not localTrajCtrl_->ctrl()->isControllerActive())
160 ARMARX_INFO <<
"Start local trajectory controller";
162 localTrajCtrl_->activate();
168 const bool activateController)
176 << globalTrajCtrl_->config.targets.trajectory.points.size()
177 <<
" to controller.";
180 globalTrajCtrl_->updateConfig();
182 if (activateController and not globalTrajCtrl_->ctrl()->isControllerActive())
184 globalTrajCtrl_->activate();
192 switch (controllerType)
195 if (globalTrajCtrl_ and not globalTrajCtrl_->ctrl()->isControllerActive())
197 globalTrajCtrl_->activate();
201 if (localTrajCtrl_ and not localTrajCtrl_->ctrl()->isControllerActive())
203 localTrajCtrl_->activate();
218 if (emergencyStop_ !=
nullptr and emergencyStop_->isActive())
220 if (not emergencyStopWasActive_)
222 emergencyStopWasActive_ =
true;
223 emergencyStopReleased_ =
false;
232 ARMARX_IMPORTANT <<
"The emergency stop was engaged. Withdrawing the trajectory "
233 "controller request so it is not resurrected on release.";
234 withdrawControllerRequests();
238 <<
"The emergency stop is engaged. Not activating the trajectory "
243 if (emergencyStopWasActive_)
247 emergencyStopWasActive_ =
false;
248 emergencyStopReleased_ =
true;
253 switch (controllerType)
258 if (not globalTrajCtrl_->ctrl()->isControllerActive())
261 <<
"The global trajectory controller is not active but "
262 "should be. Activating now.";
263 globalTrajCtrl_->activate();
270 if (not localTrajCtrl_->ctrl()->isControllerActive())
273 <<
"The local trajectory controller is not active but "
274 "should be. Activating now.";
275 localTrajCtrl_->activate();
288 const bool released = emergencyStopReleased_;
289 emergencyStopReleased_ =
false;
295 PlatformControllerExecutor::withdrawControllerRequests()
300 if (localTrajCtrl_ and localTrajCtrl_->ctrl())
302 localTrajCtrl_->deactivate();
305 if (globalTrajCtrl_ and globalTrajCtrl_->ctrl())
307 globalTrajCtrl_->deactivate();
315 if (globalTrajCtrl_ ==
nullptr)
323 globalTrajCtrl_->config.diagnostics.dumpRequest += 1;
324 globalTrajCtrl_->updateConfig();
326 catch (
const std::exception& e)
329 ARMARX_WARNING <<
"Could not request the execution diagnostics dump: " << e.what();
337 ARMARX_INFO <<
"Stopping local trajectory controller (if available and active)";
338 if (localTrajCtrl_ && localTrajCtrl_->ctrl() &&
339 localTrajCtrl_->ctrl()->isControllerActive())
341 ARMARX_INFO <<
"Stopping local trajectory controller.";
342 localTrajCtrl_->deactivate();
347 ARMARX_INFO <<
"Local trajectory controller was not available or active.";
350 ARMARX_INFO <<
"Stopping global trajectory controller (if available and active)";
351 if (globalTrajCtrl_ && globalTrajCtrl_->ctrl() &&
352 globalTrajCtrl_->ctrl()->isControllerActive())
354 ARMARX_INFO <<
"Stopping global trajectory controller.";
355 globalTrajCtrl_->deactivate();
360 ARMARX_INFO <<
"Global trajectory controller was not available or active.";
364 auto robotUnit = controllerPlugin_.getRobotUnitPlugin().getRobotUnit();
367 const auto platformUnitPrx = robotUnit->getPlatformUnit();
370 ARMARX_INFO <<
"Stopping platform via PlatformUnit";
371 platformUnitPrx->stopPlatform();
375 ARMARX_WARNING <<
"PlatformUnit proxy not available, cannot stop platform";
380 ARMARX_INFO <<
"RobotUnit not available, cannot stop platform";
388 if (localTrajCtrl_->ctrl()->isControllerActive())
391 localTrajCtrl_->config.params.limits.linear =
392 std::min(limits.
linear, localTrajCtrlInitialConfig_.params.limits.linear);
393 localTrajCtrl_->config.params.limits.angular =
394 std::min(limits.
angular, localTrajCtrlInitialConfig_.params.limits.angular);
396 localTrajCtrl_->updateConfig();
399 if (globalTrajCtrl_->ctrl()->isControllerActive())
402 globalTrajCtrl_->config.params.limits.linear =
403 std::min(limits.
linear, globalTrajCtrlInitialConfig_.params.limits.linear);
404 globalTrajCtrl_->config.params.limits.angular =
405 std::min(limits.
angular, globalTrajCtrlInitialConfig_.params.limits.angular);
407 globalTrajCtrl_->updateConfig();
415 <<
"Scaling factor may not be negative, but is " << velocityFactor;
417 <<
"Scaling factor may not be > 1, but is " << velocityFactor;
419 if (localTrajCtrl_->ctrl()->isControllerActive())
421 localTrajCtrl_->config.params.velocityFactor = velocityFactor;
423 localTrajCtrl_->updateConfig();
426 if (globalTrajCtrl_->ctrl()->isControllerActive())
428 globalTrajCtrl_->config.params.velocityFactor = velocityFactor;
430 globalTrajCtrl_->updateConfig();
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
static void WaitFor(const Duration &duration)
Wait for a certain duration on the virtual clock.
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
The robot's software emergency stop, as far as navigation needs to know it.
#define ARMARX_CHECK_POSITIVE(number)
This macro evaluates whether number is positive (> 0) and if it turns out to be false it will throw a...
#define ARMARX_CHECK_LESS_EQUAL(lhs, rhs)
This macro evaluates whether lhs is less or equal (<=) rhs and if it turns out to be false it will th...
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
@ PlatformGlobalTrajectory
This file is part of ArmarX.
void toAron(arondto::PackagePath &dto, const PackageFileLocation &bo)