5 #include <SimoxUtility/algorithm/string/string_tools.h>
6 #include <VirtualRobot/XML/RobotIO.h>
22 #include <RobotAPI/libraries/armem_robot_state/aron/Proprioception.aron.generated.h>
23 #include <RobotAPI/libraries/armem_robot_state/aron/Robot.aron.generated.h>
24 #include <RobotAPI/libraries/armem_robot_state/aron/RobotDescription.aron.generated.h>
35 Base(memoryToIceAdapter,
37 arondto::RobotDescription::ToAronType())
46 robotUnit = robotUnitPrx;
49 updateRobotDescription();
53 Segment::commitRobotDescription(
62 arondto::RobotDescription::ToAronType());
70 arondto::RobotDescription dto;
71 toAron(dto, robotDescription);
72 update.instancesData = {dto.toAron()};
92 tryGet(
const std::function<std::string()>& func)
98 catch (
const std::exception& ex)
105 Segment::updateRobotDescription()
108 KinematicUnitInterfacePrx kinematicUnit = robotUnit->getKinematicUnit();
111 const std::string robotName = kinematicUnit->getRobotName();
112 const std::string robotFilename = kinematicUnit->getRobotFilename();
114 const std::vector<std::string> packages =
117 const std::string
package = simox::alg::split(robotFilename, "/").front();
127 auto spp = pp.serialize();
131 const std::string fixedPath = spp.path.substr(spp.package.size() + 1, -1);
133 spp.path = fixedPath;
142 const auto fixPathDto = [](armarx::arondto::PackagePath& pp)
147 const std::string fixedPath = pp.path.substr(pp.package.size() + 1, -1);
153 ARMARX_INFO <<
"Robot description '" << robotPath <<
"'";
157 arondto::RobotInfo info;
159 for (
const auto& side :
162 const auto arm = robotNameHelper->getArm(side);
164 arondto::RobotInfoElement e;
165 e.end_effector =
tryGet([&]() {
return arm.getEndEffector(); });
166 e.force_torque_sensor =
tryGet([&]() {
return arm.getForceTorqueSensor(); });
167 e.force_torque_sensor_frame =
168 tryGet([&]() {
return arm.getForceTorqueSensorFrame(); });
170 e.full_hand_collision_model.package =
171 tryGet([&]() {
return arm.getHandModelPackage(); });
172 e.full_hand_collision_model.path =
173 tryGet([&]() {
return arm.getFullHandCollisionModel(); });
174 fixPathDto(e.full_hand_collision_model);
177 e.hand_controller_name =
tryGet([&]() {
return arm.getHandControllerName(); });
179 e.hand_model.package =
tryGet([&]() {
return arm.getHandModelPackage(); });
180 e.hand_model.path =
tryGet([&]() {
return arm.getHandModelPath(); });
181 fixPathDto(e.hand_model);
183 e.hand_root_node =
tryGet([&]() {
return arm.getHandRootNode(); });
184 e.kinematic_chain =
tryGet([&]() {
return arm.getKinematicChain(); });
186 e.palm_collision_model =
tryGet([&]() {
return arm.getPalmCollisionModel(); });
188 e.tcp =
tryGet([&]() {
return arm.getTCP(); });
189 e.torso_kinematic_chain =
190 tryGet([&]() {
return arm.getTorsoKinematicChain(); });
193 tryGet([&]() {
return arm.getHandUnitName(); });
196 info.parts.emplace(side +
"Arm", e);
200 arondto::RobotDescriptionVisualization visualization;
202 for (
const auto& side :
205 const auto arm = robotNameHelper->getArm(side);
207 armarx::armem::arondto::BodyPartDescription bpd;
208 bpd.root_node_name =
tryGet([&]() {
return arm.getHandRootNode(); });
209 bpd.xml.package =
tryGet([&]() {
return arm.getHandModelPackage(); });
210 bpd.xml.path =
tryGet([&]() {
return arm.getHandModelPath(); });
213 visualization.body_parts.emplace(side +
"Hand", bpd);
218 std::map<std::string, std::vector<armarx::armem::arondto::ManipulationCapability>>>
219 allManipulationCapabilities;
221 const auto robot = VirtualRobot::RobotIO::loadRobot(robotPath.toSystemPath());
224 for (
const auto& eef : robot->getEndEffectors())
226 const auto& capabilities = eef->getManipulationCapabilities();
227 if (capabilities.has_value())
229 std::vector<armarx::armem::arondto::ManipulationCapability>
230 manipulationCapabilities;
232 for (
const auto& vrCap : capabilities->capabilities)
234 arondto::ManipulationCapability dto;
236 dto.affordance = vrCap.affordance;
238 dto.shape = vrCap.shape;
239 dto.type = vrCap.type;
241 manipulationCapabilities.push_back(dto);
245 if (not allManipulationCapabilities)
247 allManipulationCapabilities.emplace();
250 allManipulationCapabilities->emplace(eef->getName(),
251 manipulationCapabilities);
256 const armem::robot_state::description::RobotDescription robotDescription{
257 .
name = kinematicUnit->getRobotName(),
258 .xml = {robotPath.serialize().package, robotPath.serialize().path},
259 .visualization = visualization,
261 .manipulationCapabilities = allManipulationCapabilities};
266 commitRobotDescription(robotDescription);
270 ARMARX_WARNING <<
"Robot unit '" << robotUnit->ice_getIdentity().name
271 <<
"' does not have a kinematic unit."
272 <<
"\n Cannot commit robot description.";
290 [
this, &robotDescriptions](
const wm::Entity& entity)
294 const auto description =
299 robotDescriptions.emplace(description->name, *description);
303 ARMARX_WARNING <<
"Could not convert entity instance to 'RobotDescription'";
308 <<
"Number of known robot descriptions: " << robotDescriptions.size();
309 return robotDescriptions;