32#include <RobotAPI/libraries/armem_robot_state/aron/Proprioception.aron.generated.h>
33#include <RobotAPI/libraries/armem_robot_state/aron/Transform.aron.generated.h>
48 std::vector<armem::MemoryID>
61 RobotStatePredictionClient::_queryEntityIDs(
const std::string& coreSegmentName)
84 std::vector<armem::PredictionRequest>
86 const std::vector<armem::MemoryID>& entityIDs,
88 const std::string& engineID)
90 std::vector<armem::PredictionRequest> requests;
91 requests.reserve(entityIDs.size());
102 std::vector<PredictionResult>
105 const std::string& engineID)
107 const std::vector<PredictionRequest> requests =
112 std::vector<PredictionResult>
115 const std::vector<PredictionResult> results =
remote.reader.predict(requests);
120 std::optional<Eigen::Affine3f>
122 const std::vector<armem::PredictionResult>& localizationPredictionResults,
123 const std::vector<armem::MemoryID>& localizationEntityIDs,
126 ARMARX_CHECK_EQUAL(localizationPredictionResults.size(), localizationEntityIDs.size());
127 std::stringstream errorMessages;
131 std::optional<armem::wm::CoreSegment> coreSegment;
133 loc::TransformQuery
query;
136 query.header.agent =
"";
137 query.header.timestamp = predictedTime;
139 for (
size_t i = 0; i < localizationPredictionResults.size(); ++i)
146 if (
query.header.agent.empty())
148 const arondto::Transform tf = arondto::Transform::FromAron(result.
prediction);
149 query.header.agent = tf.header.agent;
157 update.entityID = entityID;
158 update.referencedTime = predictedTime;
160 coreSegment->update(update);
165 errorMessages <<
"Prediction of '" << entityID <<
"'"
170 std::optional<Eigen::Affine3f> result;
171 if (coreSegment.has_value())
173 loc::TransformResult tf =
174 loc::TransformHelper::lookupTransform(coreSegment.value(),
query);
178 result = tf.transform.transform;
182 errorMessages <<
"\nFailed to lookup transform: " << tf.errorMessage <<
"\n";
186 if (not errorMessages.str().empty())
194 std::optional<std::map<std::string, float>>
196 const std::vector<PredictionResult>& proprioceptionPredictionResults,
197 const std::string& robotName)
199 auto it = std::find_if(proprioceptionPredictionResults.begin(),
200 proprioceptionPredictionResults.end(),
202 { return result.snapshotID.entityName == robotName; });
203 if (it != proprioceptionPredictionResults.end())
206 auto prop = armem::arondto::Proprioception::FromAron(result.
prediction);
207 return prop.joints.position;
215 std::optional<Eigen::Affine3f>
218 const std::string& engineID)
220 const std::vector<PredictionResult> results =
predict(entityIDs, predictedTime, engineID);
221 std::optional<Eigen::Affine3f> pose =
lookupGlobalPose(results, entityIDs, predictedTime);
225 std::optional<std::map<std::string, float>>
228 const std::string& robotName,
229 const std::string& engineID)
231 const std::vector<PredictionResult> results =
predict(entityIDs, predictedTime, engineID);
237 const std::vector<armem::MemoryID>& propEntityIDs,
239 const std::string& robotName,
240 const std::string& engineID)
245 const std::vector<armem::MemoryID> entityIDs =
248 if (entityIDs.empty())
253 auto _results =
predict(entityIDs, predictedTime,
"Linear");
256 std::vector<armem::PredictionResult> locResults, propResults;
MemoryID getCoreSegmentID() const
MemoryID withTimestamp(Time time) const
QueryResult query(const QueryInput &input) const
Perform a query on the WM.
CoreSegmentSelector & coreSegments()
Start specifying core segments.
ProviderSegmentSelector & providerSegments()
Start specifying provider segments.
SnapshotSelector & snapshots()
Start specifying entity snapshots.
EntitySelector & entities()
Start specifying entities.
std::optional< Eigen::Affine3f > predictGlobalPose(const std::vector< armem::MemoryID > &entityIDs, armem::Time predictedTime, const std::string &engineID="Linear")
std::optional< std::map< std::string, float > > predictJointPositions(const std::vector< armem::MemoryID > &entityIDs, armem::Time predictedTime, const std::string &robotName, const std::string &engineID="Linear")
std::vector< armem::PredictionResult > predict(const std::vector< armem::MemoryID > &entityIDs, armem::Time predictedTime, const std::string &engineID="Linear")
std::optional< std::map< std::string, float > > lookupJointPositions(const std::vector< armem::PredictionResult > &proprioceptionPredictionResults, const std::string &robotName)
std::vector< armem::PredictionRequest > makePredictionRequests(const std::vector< armem::MemoryID > &entityIDs, armem::Time predictedTime, const std::string &engineID="Linear")
std::vector< armem::MemoryID > queryProprioceptionEntityIDs()
std::optional< Eigen::Affine3f > lookupGlobalPose(const std::vector< armem::PredictionResult > &localizationPredictionResults, const std::vector< armem::MemoryID > &localizationEntityIDs, armem::Time predictedTime)
std::vector< armem::MemoryID > queryLocalizationEntityIDs()
WholeBodyPrediction predictWholeBody(const std::vector< armem::MemoryID > &localizationEntityIDs, const std::vector< armem::MemoryID > &proprioceptionEntityIDs, armem::Time predictedTime, const std::string &robotName, const std::string &engineID="Linear")
RobotStatePredictionClient()
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_VERBOSE
The logging level for verbose information.
std::string const GlobalFrame
Variable of the global coordinate system.
query::Builder QueryBuilder
const std::string localizationCoreSegment
const std::string robotRootNodeName
const std::string proprioceptionCoreSegment
std::vector< MemoryID > getEntityIDs(const ContainerT &container)
armarx::core::time::DateTime Time
std::vector< Args... > concatenate(const std::vector< Args... > &lhs, const std::vector< Args... > &rhs)
std::vector< Args... > slice(const std::vector< Args... > &vector, size_t start=0, std::optional< size_t > end=std::nullopt)
An update of an entity for a specific point in time.
armem::MemoryID snapshotID
PredictionSettings predictionSettings
aron::data::DictPtr prediction
std::string predictionEngineID
wm::Memory memory
The slice of the memory that matched the query.
armem::client::Reader reader
std::optional< Eigen::Affine3f > globalPose
std::optional< std::map< std::string, float > > jointPositions