25 #include <SimoxUtility/algorithm/contains.h>
26 #include <SimoxUtility/algorithm/get_map_keys_values.h>
27 #include <SimoxUtility/algorithm/string.h>
34 #include <RobotAPI/interface/core/PoseBase.h>
44 descriptionSegment(iceAdapter()),
45 proprioceptionSegment(iceAdapter()),
46 exteroceptionSegment(iceAdapter()),
47 localizationSegment(iceAdapter()),
48 commonVisu(descriptionSegment, proprioceptionSegment, localizationSegment)
55 robotUnit.plugin->setRobotUnitAsOptionalDependency(
true);
56 robotUnit.dataBuffer = std::make_unique<RobotUnit::Queue>();
67 const std::string robotUnitPrefix = RobotUnit::sensorValuePrefix;
70 defs->optional(robotUnit.waitForRobotUnit,
72 "Add the robot unit as dependency to the component. This memory requires a "
73 "running RobotUnit, therefore we should add it as explicit dependency.");
75 defs->optional(robotUnit.reader.properties.sensorPrefix,
76 robotUnitPrefix +
"SensorValuePrefix",
77 "Prefix of all sensor values.");
78 defs->optional(robotUnit.pollFrequency,
79 robotUnitPrefix +
"UpdateFrequency",
80 "The frequency to store values in Hz. All other values get discarded. "
81 "Minimum is 1, max is " +
84 .setMax(RobotUnit::ROBOT_UNIT_MAXIMUM_FREQUENCY);
87 const std::string prefix =
"mem.";
103 return "RobotStateMemory";
109 descriptionSegment.
init();
110 proprioceptionSegment.
init();
111 exteroceptionSegment.
init();
112 localizationSegment.
init();
115 robotUnit.pollFrequency =
116 std::clamp(robotUnit.pollFrequency, 0.F, RobotUnit::ROBOT_UNIT_MAXIMUM_FREQUENCY);
118 std::vector<std::string> includePaths;
122 for (
const std::string& projectName : packages)
124 if (projectName.empty())
130 const std::string pathsString =
project.getIncludePaths();
131 std::vector<std::string> projectIncludePaths =
simox::alg::split(pathsString,
";,");
133 includePaths.end(), projectIncludePaths.begin(), projectIncludePaths.end());
136 if (robotUnit.waitForRobotUnit)
138 usingProxy(robotUnit.plugin->getRobotUnitName());
146 ARMARX_CHECK(not robotUnit.reader.task or not robotUnit.reader.task->isRunning());
147 ARMARX_CHECK(not robotUnit.writer.task or not robotUnit.writer.task->isRunning());
148 robotUnit.dataBuffer = std::make_unique<RobotUnit::Queue>();
157 if (robotUnit.plugin->hasRobotUnitName())
159 robotUnit.plugin->waitUntilRobotUnitIsRunning();
162 robotUnit.reader.setTag(
getName());
163 robotUnit.writer.setTag(
getName());
165 descriptionSegment.
onConnect(robotUnitPrx);
166 proprioceptionSegment.
onConnect(robotUnitPrx);
168 robotUnit.reader.connect(
172 robotUnit.writer.connect(*debugObserver);
173 robotUnit.writer.properties.robotUnitProviderID =
177 [
this]() { robotUnit.reader.run(robotUnit.pollFrequency, *robotUnit.dataBuffer); },
178 "Robot Unit Reader");
182 robotUnit.writer.run(robotUnit.pollFrequency,
183 *robotUnit.dataBuffer,
185 localizationSegment);
187 "Robot State Writer");
189 startRobotUnitStream();
196 stopRobotUnitStream();
202 stopRobotUnitStream();
207 const std::string& robotName,
208 const ::Ice::Current& )
216 const bool robotNameFound = simox::alg::contains_key(poseMap, robotName);
218 <<
"Robot with name " << robotName <<
" does not exist at or before timestamp "
220 <<
"Available robots are: " << simox::alg::get_keys(poseMap);
222 return {
new Pose(poseMap[robotName].matrix())};
231 RobotStateMemory::startRobotUnitStream()
236 if (robotUnit.reader.task->isRunning() || robotUnit.writer.task->isRunning())
238 if (robotUnit.reader.task->isRunning() && robotUnit.writer.task->isRunning())
242 ARMARX_WARNING <<
"Found inconsistency in running tasks. Restarting all!";
243 stopRobotUnitStream();
246 std::stringstream ss;
247 ss <<
"Getting sensor values for:" << std::endl;
248 for (
const auto& [name, dataEntry] : robotUnit.reader.description.entries)
250 const std::string type =
252 ss <<
"\t" << name <<
" (type: '" << type <<
"')" << std::endl;
257 robotUnit.reader.task->start();
258 robotUnit.writer.task->start();
262 RobotStateMemory::stopRobotUnitStream()
265 robotUnit.dataBuffer->close();
266 robotUnit.reader.task->stop();
268 robotUnit.writer.task->stop();