ControllerHandler.h
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <memory>
5#include <string>
6
14
22#include <armarx/view_selection/gaze_targets/aron/GazeTarget.aron.generated.h>
24
26{
32
34 {
35 std::string robotName;
36 };
37
38 template <armarx::view_selection::common::ControllerType ControllerT>
40 {
41 public:
44
45 ControllerHandler(const InjectedServices& srv, const Params& params) :
46 srv(srv), params(params)
47 {
48 }
49
51 {
52 // ctrl.reset();
53 }
54
55 void
57 {
58 // Properties are loaded OK
59 ARMARX_INFO << "Activating controller";
60 ctrl->activate();
61 }
62
63 void
65 {
66 // initialize controller
67 ARMARX_INFO << "Initializing controller";
68 {
70 auto builder = srv.controlComponentPlugin->createControllerBuilder<ControllerT>();
71 builder.withNodeSet("Head");
72
73 const std::string controllerTypeID =
75
76 // Load the default or robot-specific config
77 {
78 // prefer robot-specific config if available
79 const armarx::PackagePath robotSpecificConfigPath(
80 "armarx_view_selection",
81 "controller_config/" + controllerTypeID + "/" + params.robotName + ".json");
82
83 if (std::filesystem::exists(robotSpecificConfigPath.toSystemPath()))
84 {
85 ARMARX_INFO << "Using robot specific config: " << robotSpecificConfigPath;
86 builder.withConfig(robotSpecificConfigPath.toSystemPath());
87 }
88 else // fallback: use default config
89 {
90 const armarx::PackagePath defaultConfigPath(
91 "armarx_view_selection",
92 "controller_config/" + controllerTypeID + "/default.json");
93
94 ARMARX_INFO << "Using default config: " << defaultConfigPath;
95
96 ARMARX_CHECK(std::filesystem::exists(defaultConfigPath.toSystemPath()))
97 << defaultConfigPath;
98
99 ARMARX_VERBOSE << "builder.withNodeSet().withConfig";
100 builder.withConfig(defaultConfigPath.toSystemPath());
101 }
102 }
103
104 ARMARX_VERBOSE << "builder.create()";
105 auto ctrlWrapper = builder.create();
107 ARMARX_CHECK_NOT_NULL(ctrlWrapper);
108
109 ARMARX_VERBOSE << "Successfully created controller";
110 ctrl = std::move(ctrlWrapper);
111 }
112
115 }
116
117 void
119 {
120 ARMARX_VERBOSE << "Sending new target to the controller " << gazeTarget;
121 armarx::view_selection::gaze_targets::arondto::GazeTarget dto;
122 toAron(dto, gazeTarget);
123
124 if (not ctrl->ctrl()->isControllerActive())
125 {
126 ARMARX_INFO << "Activating controller because it is not active yet.";
127 ctrl->ctrl()->activateController();
129 }
130
131 ctrl->config.target = dto;
132 ctrl->updateConfig();
133 }
134
135 protected:
136 private:
137 std::unique_ptr<armarx::control::client::ControllerWrapper<ControllerT>> ctrl;
138
139 const InjectedServices srv;
140
141 const Params params;
142 };
143} // namespace armarx::view_selection::gaze_scheduler
static void WaitFor(const Duration &duration)
Wait for a certain duration on the virtual clock.
Definition Clock.cpp:99
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition Duration.cpp:48
static std::filesystem::path toSystemPath(const data::PackagePath &pp)
void updateControllerTarget(const gaze_targets::GazeTarget &gazeTarget) override
ControllerHandler(const InjectedServices &srv, const Params &params)
Business Object (BO) class of GazeTarget.
Definition GazeTarget.h:23
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#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.
Definition Logging.h:181
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
void toAron(arondto::PackagePath &dto, const PackageFileLocation &bo)
std::experimental::observer_ptr< armarx::control::client::ComponentPlugin > controlComponentPlugin
#define ARMARX_TRACE
Definition trace.h:77