ArticulatedObjectReader.cpp
Go to the documentation of this file.
2 
3 #include <mutex>
4 #include <optional>
5 
6 #include <VirtualRobot/XML/BaseIO.h>
7 #include <VirtualRobot/XML/RobotIO.h>
8 
12 
15 #include <RobotAPI/libraries/ArmarXObjects/aron/ObjectPose.aron.generated.h>
21 #include <RobotAPI/libraries/armem_robot_state/aron/Robot.aron.generated.h>
24 
26 {
27 
29  ArticulatedObjectReader::getArticulatedObject(const std::string& typeName,
30  const armem::Time& timestamp,
31  const std::optional<std::string>& providerName,
32  const std::string& instanceName,
33  VirtualRobot::RobotIO::RobotDescription loadMode)
34  {
35  const auto descriptions = queryDescriptions(timestamp, providerName);
36 
37  ARMARX_INFO << "Found " << descriptions.size() << " articulated object descriptions";
38 
39  const auto it = std::find_if(
40  descriptions.begin(),
41  descriptions.end(),
43  { return desc.name == typeName; });
44 
45  if (it == descriptions.end())
46  {
47  ARMARX_WARNING << "Description for articulate object with type <" << typeName
48  << "> not (yet) available!";
49  return nullptr;
50  }
51 
52  ARMARX_DEBUG << "Description for articulate object with type <" << typeName
53  << "> available!";
54 
55  auto obj = VirtualRobot::RobotIO::loadRobot(it->xml.toSystemPath(), loadMode);
56 
57  if (not obj)
58  {
59  ARMARX_WARNING << "Failed to load description for articulated object <" << typeName
60  << ">!";
61  return nullptr;
62  }
63 
64  obj->setName(instanceName);
65  obj->setType(it->name);
66 
67  return obj;
68  }
69 
70  bool
72  VirtualRobot::Robot& object,
73  const armem::Time& timestamp,
74  const std::optional<std::string>& providerName)
75  {
76  const auto objectState =
77  queryState(object.getType() + "/" + object.getName(), timestamp, providerName);
78  if (not objectState)
79  {
80  ARMARX_VERBOSE << deactivateSpam(5) << "Querying object state failed for object `"
81  << object.getName() << "` " << "(type `" << object.getType() << "`)!";
82  return false;
83  }
84 
85  object.setJointValues(objectState->jointMap);
86  object.setGlobalPose(objectState->globalPose.matrix());
87 
88  return true;
89  }
90 
91 } // namespace armarx::armem::articulated_object
armarx::armem::articulated_object::Reader::queryState
std::optional< robot_state::RobotState > queryState(const std::string &instanceName, const armem::Time &timestamp, const std::optional< std::string > &providerName) const
Definition: Reader.cpp:255
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::armem::robot_state::description::RobotDescription
Definition: types.h:44
armarx::armem::articulated_object::Reader::queryDescriptions
std::vector< robot_state::description::RobotDescription > queryDescriptions(const armem::Time &timestamp, const std::optional< std::string > &providerName) const
Definition: Reader.cpp:164
ArticulatedObjectReader.h
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
armarx::armem::human::Robot
@ Robot
Definition: util.h:14
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
error.h
aron_conversions.h
ObjectPose.h
ObjectInfo.h
memory_definitions.h
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::articulated_object::ArticulatedObjectReader::synchronizeArticulatedObject
bool synchronizeArticulatedObject(VirtualRobot::Robot &object, const armem::Time &timestamp, const std::optional< std::string > &providerName)
Definition: ArticulatedObjectReader.cpp:71
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::armem::articulated_object
Definition: ArticulatedObjectReader.cpp:25
Time.h
Builder.h
Logging.h
robot_conversions.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
aron_conversions.h
ArmarXDataPath.h
armarx::armem::articulated_object::ArticulatedObjectReader::getArticulatedObject
VirtualRobot::RobotPtr getArticulatedObject(const std::string &typeName, const armem::Time &timestamp, const std::optional< std::string > &providerName, const std::string &instanceName="", VirtualRobot::RobotIO::RobotDescription loadMode=VirtualRobot::RobotIO::eStructure)
Definition: ArticulatedObjectReader.cpp:29
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
PackagePath.h