35 defineOptionalProperty<std::string>(
"nodeName",
"HeadIMU",
"");
36 defineOptionalProperty<std::string>(
"SimulatorName",
"Simulator",
"Name of the simulator component that should be used");
37 defineOptionalProperty<std::string>(
"RobotStateComponentName",
"RobotStateComponent",
"Name of the robot state component that should be used");
43 usingProxy(getProperty<std::string>(
"RobotStateComponentName").getValue());
45 nodeName = getProperty<std::string>(
"nodeName").getValue();
49 usingProxy(getProperty<std::string>(
"SimulatorName").getValue());
55 robotStateComponent = getProxy<RobotStateComponentInterfacePrx>(getProperty<std::string>(
"RobotStateComponentName").getValue());
57 simulator = getProxy<SimulatorInterfacePrx>(getProperty<std::string>(
"SimulatorName").getValue());
71 void IMUSimulation::frameAcquisitionTaskLoop()
75 auto robotLinearVelocityAsync = simulator->begin_getRobotLinearVelocity(robotStateComponent->getRobotName(), nodeName);
76 auto robotAngularVelocityAsync = simulator->begin_getRobotAngularVelocity(robotStateComponent->getRobotName(), nodeName);
78 SharedRobotNodeInterfacePrx robotNode = robotStateComponent->getSynchronizedRobot()->getRobotNode(nodeName);
79 FramedPoseBasePtr poseInRootFrame = robotNode->getGlobalPose();
82 Eigen::Vector3f currentPosition = Vector3Ptr::dynamicCast(poseInRootFrame->position)->
toEigen() / 1000.0;
84 float deltaTime = (now->timestamp - timestamp) * std::pow(10, -6);
86 Vector3BasePtr robotLinearVelocity = simulator->end_getRobotLinearVelocity(robotLinearVelocityAsync);
87 Vector3BasePtr robotAngularVelocity = simulator->end_getRobotAngularVelocity(robotAngularVelocityAsync);
91 Eigen::Vector3f currentLinearVelocity = orientation.toRotationMatrix().transpose() * Vector3Ptr::dynamicCast(robotLinearVelocity)->
toEigen() / 1000.0f;
92 Eigen::Vector3f angularVelocity = orientation.toRotationMatrix().transpose() * Vector3Ptr::dynamicCast(robotAngularVelocity)->
toEigen();
97 Eigen::Vector3f acceleration = (currentLinearVelocity - linearVelocity) / deltaTime;
101 data.acceleration.push_back(acceleration(0));
102 data.acceleration.push_back(acceleration(1));
103 data.acceleration.push_back(acceleration(2));
105 data.gyroscopeRotation.push_back(angularVelocity(0));
106 data.gyroscopeRotation.push_back(angularVelocity(1));
107 data.gyroscopeRotation.push_back(angularVelocity(2));
109 data.magneticRotation.push_back(0.0);
110 data.magneticRotation.push_back(0.0);
111 data.magneticRotation.push_back(0.0);
113 data.orientationQuaternion.push_back(currentOrientation.w());
114 data.orientationQuaternion.push_back(currentOrientation.x());
115 data.orientationQuaternion.push_back(currentOrientation.y());
116 data.orientationQuaternion.push_back(currentOrientation.z());
121 orientation = currentOrientation;
122 position = currentPosition;
123 timestamp = now->timestamp;
124 linearVelocity = currentLinearVelocity;
130 return "IMUSimulation";