PlatformControllerExecutor.cpp
Go to the documentation of this file.
2 
3 #include <filesystem>
4 
8 
11 #include <armarx/control/memory/config/util.h>
14 #include <armarx/navigation/platform_controller/aron/PlatformLocalTrajectoryControllerConfig.aron.generated.h>
19 
21 {
22 
24  ControllerComponentPlugin& controllerComponentPlugin,
25  const Properties& properties) :
26  controllerPlugin_(controllerComponentPlugin), properties_(properties)
27  {
29 
30  if (properties_.rtUnitDynamicallyLoadLibraries)
31  {
32  ARMARX_WARNING << "Dynamic loading of the controller library is deactivated (and this "
33  "is also desired). If loading the controllers is failing subsequently, "
34  "make sure that the RobotUnit's property `LoadLibraries` contains "
35  "`armarx_navigation:armarx_navigation_platform_controller`.";
36  }
37 
38  // make default configs available to the memory
39  ARMARX_INFO << "Loading default configs";
40  {
41  // const std::filesystem::path configBasePath =
42  // PackagePath("armarx_navigation", "controller_config").toSystemPath();
43 
45  // armarx::control::memory::config::parseAndStoreDefaultConfigs<
46  // armarx::navigation::common::ControllerType::PlatformTrajectory>(
47  // "" /*configBasePath*/, controllerComponentPlugin.configMemoryWriter());
48 
50  }
51 
52  // initialize controller
53  ARMARX_INFO << "Initializing local trajectory controller";
54  {
56  auto builder = controllerPlugin_.createControllerBuilder<
58 
60 
61  const armarx::PackagePath configPath = [&]() -> armarx::PackagePath
62  {
63  const armarx::PackagePath baseConfigPath(
64  "armarx_navigation", "controller_config/PlatformTrajectory/default.json");
65 
66  ARMARX_CHECK(std::filesystem::exists(baseConfigPath.toSystemPath()))
67  << baseConfigPath;
68 
69  const armarx::PackagePath robotSpecificConfigPath(
70  "armarx_navigation",
71  "controller_config/PlatformTrajectory/" + properties_.robotName +
72  "default.json");
73 
74  if (std::filesystem::exists(robotSpecificConfigPath.toSystemPath()))
75  {
76  return robotSpecificConfigPath;
77  }
78 
79  return baseConfigPath;
80  }();
81 
82  auto ctrlWrapper = builder.withNodeSet("PlatformPlanning")
83  .withConfig(configPath.toSystemPath())
84  .create();
85 
87  ARMARX_CHECK_NOT_NULL(ctrlWrapper);
88  localTrajCtrl_ = std::move(ctrlWrapper);
89  }
90 
92 
93  ARMARX_INFO << "Initializing global trajectory controller";
94  {
96  auto builder = controllerPlugin_.createControllerBuilder<
98 
100 
101  const armarx::PackagePath configPath("armarx_navigation",
102  "controller_config/GlobalTrajectory/default.json");
103 
104  auto ctrlWrapper = builder.withNodeSet("PlatformPlanning")
105  .withConfig(configPath.toSystemPath())
106  .create();
107 
108  ARMARX_TRACE;
109  ARMARX_CHECK_NOT_NULL(ctrlWrapper);
110  globalTrajCtrl_ = std::move(ctrlWrapper);
111  }
112 
114 
115  ARMARX_TRACE;
116  ARMARX_CHECK_NOT_NULL(localTrajCtrl_);
117  ARMARX_INFO << "PlatformControllerExecutor: init done.";
118  }
119 
121 
122  void
124  const bool activateController)
125  {
126  ARMARX_VERBOSE << "Received trajectory for execution with " << trajectory.points().size()
127  << " points";
128 
129  toAron(localTrajCtrl_->config.targets.trajectory, trajectory);
130 
131  // sends the updated config to the controller and stores it in the memory
132  localTrajCtrl_->updateConfig();
133 
134  if (activateController and not localTrajCtrl_->ctrl()->isControllerActive())
135  {
136  ARMARX_INFO << "Start local trajectory controller";
137 
138  localTrajCtrl_->activate();
139  }
140  }
141 
142  void
144  const bool activateController)
145  {
146  ARMARX_VERBOSE << "Received trajectory for execution with " << trajectory.points().size()
147  << " points";
148 
149  toAron(globalTrajCtrl_->config.targets.trajectory, trajectory);
150 
151  ARMARX_INFO << "Sending trajectory with "
152  << globalTrajCtrl_->config.targets.trajectory.points.size()
153  << " to controller.";
154 
155  // sends the updated config to the controller and stores it in the memory
156  globalTrajCtrl_->updateConfig();
157 
158  if (activateController and not globalTrajCtrl_->ctrl()->isControllerActive())
159  {
160  globalTrajCtrl_->activate();
161  }
162  }
163 
164  void
166  {
167  ARMARX_INFO << "Start";
168  switch (controllerType)
169  {
171  if (globalTrajCtrl_ and
172  not globalTrajCtrl_->ctrl()->isControllerActive())
173  {
174  globalTrajCtrl_->activate();
175  }
176  break;
178  if (localTrajCtrl_ and not localTrajCtrl_->ctrl()->isControllerActive())
179  {
180  localTrajCtrl_->activate();
181  }
182  break;
184  ARMARX_INFO << "No controller selected.";
185  break;
186  }
187  }
188 
189  void
191  {
192  switch (controllerType)
193  {
195  if (globalTrajCtrl_)
196  {
197  if (not globalTrajCtrl_->ctrl()->isControllerActive())
198  {
200  << "The global trajectory controller is not active but "
201  "should be. Activating now.";
202  globalTrajCtrl_->activate();
203  }
204  }
205  break;
207  if (localTrajCtrl_)
208  {
209  if (not globalTrajCtrl_->ctrl()->isControllerActive())
210  {
212  << "The local trajectory controller is not active but "
213  "should be. Activating now.";
214  localTrajCtrl_->activate();
215  }
216  }
217  break;
219  ARMARX_INFO << "No controller selected.";
220  break;
221  }
222  }
223 
224  void
226  {
227  lastActiveController_ = ControllerType::None;
228 
229  if (localTrajCtrl_->ctrl()->isControllerActive())
230  {
231  ARMARX_INFO << "Stopping local trajectory controller.";
232  localTrajCtrl_->deactivate();
233  lastActiveController_ = ControllerType::LocalTrajectory;
234  }
235 
236  if (globalTrajCtrl_->ctrl()->isControllerActive())
237  {
238  ARMARX_INFO << "Stopping global trajectory controller.";
239  globalTrajCtrl_->deactivate();
240  lastActiveController_ = ControllerType::GlobalTrajectory;
241  }
242 
243 
244  const auto platformUnitPrx =
245  controllerPlugin_.getRobotUnitPlugin().getRobotUnit()->getPlatformUnit();
246  if (platformUnitPrx)
247  {
248  ARMARX_INFO << "Stopping platform via PlatformUnit";
249  platformUnitPrx->stopPlatform();
250  }
251  }
252 } // namespace armarx::navigation::server
armarx::navigation::core::GlobalTrajectory
Definition: Trajectory.h:68
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::navigation::server::PlatformControllerExecutor::PlatformControllerExecutor
PlatformControllerExecutor(ControllerComponentPlugin &controllerComponentPlugin, const Properties &properties)
Definition: PlatformControllerExecutor.cpp:23
armarx::navigation::server::PlatformControllerExecutor::start
void start(ControllerType controllerType) override
Definition: PlatformControllerExecutor.cpp:165
armarx::navigation::server::PlatformControllerExecutor::ensureIsActive
void ensureIsActive(ControllerType controllerType) override
Definition: PlatformControllerExecutor.cpp:190
armarx::navigation::server::PlatformControllerExecutor::Properties::robotName
std::string robotName
Definition: PlatformControllerExecutor.h:33
armarx::navigation::server::PlatformControllerExecutor::stop
void stop() override
Definition: PlatformControllerExecutor.cpp:225
armarx::navigation::server::ExecutorInterface::ControllerType::GlobalTrajectory
@ GlobalTrajectory
armarx::core::time::Clock::WaitFor
static void WaitFor(const Duration &duration)
Wait for a certain duration on the virtual clock.
Definition: Clock.cpp:104
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
armarx::navigation::common::ControllerType::PlatformGlobalTrajectory
@ PlatformGlobalTrajectory
armarx::navigation::server::ExecutorInterface::ControllerType::LocalTrajectory
@ LocalTrajectory
armarx::navigation::server::PlatformControllerExecutor::execute
void execute(const core::LocalTrajectory &trajectory, bool activateController=false) override
Definition: PlatformControllerExecutor.cpp:123
armarx::navigation::common::ControllerType::PlatformLocalTrajectory
@ PlatformLocalTrajectory
armarx::navigation::core::LocalTrajectory::points
const std::vector< LocalTrajectoryPoint > & points() const
Definition: Trajectory.cpp:837
type.h
armarx::navigation::server::ExecutorInterface::ControllerType::None
@ None
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::navigation::server::PlatformControllerExecutor::~PlatformControllerExecutor
~PlatformControllerExecutor() override
armarx::navigation::server
This file is part of ArmarX.
Definition: EventPublishingInterface.h:10
armarx::navigation::server::PlatformControllerExecutor::Properties
Definition: PlatformControllerExecutor.h:31
armarx::control::client::ComponentPlugin
Definition: ComponentPlugin.h:69
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::core::time::Duration::Seconds
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
Definition: Duration.cpp:83
armarx::PackagePath::toSystemPath
static std::filesystem::path toSystemPath(const data::PackagePath &pp)
Definition: PackagePath.cpp:54
aron_conversions.h
armarx::control::client::ComponentPlugin::getRobotUnitPlugin
armarx::plugins::RobotUnitComponentPlugin & getRobotUnitPlugin()
Definition: ComponentPlugin.h:106
armarx::control::client::ComponentPlugin::createControllerBuilder
auto createControllerBuilder(Args... args)
Definition: ComponentPlugin.h:83
armarx::navigation::core::LocalTrajectory
Definition: Trajectory.h:167
PlatformControllerExecutor.h
controller_types.h
armarx::navigation::server::ExecutorInterface::ControllerType
ControllerType
Definition: ExecutorInterface.h:21
armarx::navigation::server::PlatformControllerExecutor::Properties::rtUnitDynamicallyLoadLibraries
bool rtUnitDynamicallyLoadLibraries
Definition: PlatformControllerExecutor.h:34
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
aron_conversions.h
json_conversions.h
aron_conversions.h
ComponentPlugin.h
Logging.h
armarx::toAron
void toAron(arondto::PackagePath &dto, const PackageFileLocation &bo)
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
ArmarXDataPath.h
armarx::PackagePath
Definition: PackagePath.h:55
controller_descriptions.h
armarx::navigation::core::GlobalTrajectory::points
const std::vector< GlobalTrajectoryPoint > & points() const
Definition: Trajectory.cpp:732
armarx::plugins::RobotUnitComponentPlugin::getRobotUnit
RobotUnitInterfacePrx getRobotUnit() const
Definition: RobotUnitComponentPlugin.cpp:112
PackagePath.h