3 #include <SimoxUtility/math/regression/linear.hpp>
15 #include <RobotAPI/libraries/armem_robot_state/aron/Proprioception.aron.generated.h>
26 Base(memoryToIceAdapter,
28 arondto::Proprioception::ToAronType(),
40 defs->optional(properties.predictionTimeWindow,
41 "prediction.TimeWindow",
42 "Duration of time window into the past to use for predictions"
43 " when requested via the PredictingMemoryInterface (in seconds).");
57 this->robotUnit = robotUnitPrx;
59 std::string providerSegmentName =
"Robot";
61 KinematicUnitInterfacePrx kinematicUnit = robotUnit->getKinematicUnit();
64 providerSegmentName = kinematicUnit->getRobotName();
68 ARMARX_WARNING <<
"Robot unit '" << robotUnit->ice_getIdentity().name <<
"' does not have a kinematic unit."
69 <<
"\n Falling back to provider segment name '" << providerSegmentName <<
"'.";
80 return doLocked([
this, ×tamp, &debugObserver]()
126 data = snapshot->findInstanceData();
149 debugObserver->
setDebugObserverDatafield(dp +
"t 1.1.2 ReadSensorValues (ms)", tReadSensorValues.toMilliSecondsDouble());
158 return robotUnitProviderID;
165 std::vector<double>
values;
173 static_cast<double>(adn::Float::DynamicCastAndCheck(
value)->getValue()));
179 if (
adn::DictPtr jointsPosition = getDictElement(*joints,
"position"))
181 addData(jointsPosition);
183 if (
adn::DictPtr jointsVelocity = getDictElement(*joints,
"velocity"))
185 addData(jointsVelocity);
187 if (
adn::DictPtr jointsTorque = getDictElement(*joints,
"torque"))
189 addData(jointsTorque);
192 Eigen::VectorXd vec =
193 Eigen::Map<Eigen::VectorXd>(
values.data(),
static_cast<Eigen::Index
>(
values.size()));
199 arondto::Proprioception& dataTemplate)
201 Eigen::Index row = 0;
202 for (
auto& [joint,
value] : dataTemplate.joints.position)
204 value =
static_cast<float>(jointData(row++));
206 for (
auto& [joint,
value] : dataTemplate.joints.velocity)
208 value =
static_cast<float>(jointData(row++));
210 for (
auto& [joint,
value] : dataTemplate.joints.torque)
212 value =
static_cast<float>(jointData(row++));
226 " is not supported in Proprioception.";
243 timeOrigin - timeWindow,
252 Eigen::VectorXd prediction(latestJoints.size());
255 prediction = latestJoints;
259 using simox::math::LinearRegression;
260 const bool inputOffset =
false;
261 const LinearRegression model = LinearRegression<Eigen::Dynamic>::Fit(
264 prediction = model.predict((predictionTime - timeOrigin).toSecondsDouble());
267 arondto::Proprioception templateData =
268 arondto::Proprioception::FromAron(info.
latestValue);
290 auto checkJVM = [&sensorValues](
const std::string& name)
301 for (
const auto& [name,
value] :
values->getElements())
305 = adn::Float::DynamicCastAndCheck(
value)->getValue();
310 for (
const auto& [name,
value] :
values->getElements())
314 = adn::Float::DynamicCastAndCheck(
value)->getValue();
319 for (
const auto& [name,
value] :
values->getElements())
323 = adn::Float::DynamicCastAndCheck(
value)->getValue();
329 for (
const auto& [name,
value] : forceTorqueMap->getElements())
333 const Eigen::Vector3f torque
335 adn::NDArray::DynamicCastAndCheck(forceTorqueValues->getElement(
"torque")));
337 const Eigen::Vector3f force
339 adn::NDArray::DynamicCastAndCheck(forceTorqueValues->getElement(
"force")));