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();
197 stopRobotUnitStream();
203 stopRobotUnitStream();
208 const std::string& robotName,
209 const ::Ice::Current& )
212 ARMARX_DEBUG <<
"Getting robot pose of robot " << robotName <<
" at timestamp " << timestamp
217 const bool robotNameFound = simox::alg::contains_key(poseMap, robotName);
219 <<
"Robot with name " << robotName <<
" does not exist at or before timestamp "
220 << timestamp <<
".\n"
221 <<
"Available robots are: " << simox::alg::get_keys(poseMap);
223 return {
new Pose(poseMap[robotName].matrix())};
232 RobotStateMemory::startRobotUnitStream()
237 if (robotUnit.reader.task->isRunning() || robotUnit.writer.task->isRunning())
239 if (robotUnit.reader.task->isRunning() && robotUnit.writer.task->isRunning())
243 ARMARX_WARNING <<
"Found inconsistency in running tasks. Restarting all!";
244 stopRobotUnitStream();
247 std::stringstream ss;
248 ss <<
"Getting sensor values for:" << std::endl;
249 for (
const auto& [name, dataEntry] : robotUnit.reader.description.entries)
251 const std::string type =
253 ss <<
"\t" << name <<
" (type: '" << type <<
"')" << std::endl;
258 robotUnit.reader.task->start();
259 robotUnit.writer.task->start();
263 RobotStateMemory::stopRobotUnitStream()
266 robotUnit.dataBuffer->close();
267 robotUnit.reader.task->stop();
269 robotUnit.writer.task->stop();