Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Answering my own question,

You can have an instance of the IMU sensor by using the SensorManager class and read the IMU data by using the ImuSensor class as follow:

sensors::SensorManager *pMgr = sensors::SensorManager::Instance() ;
if(pMgr == nullptr)
{
   /*ERROR*/
}
else
{
    sensors::SensorPtr pSensor = pMgr->GetSensor("imu_sensor");
    if(pSensor == nullptr)
    {
       /*ERROR*/
    } 
    else
    {
       sensors::ImuSensorPtr pImuSensor = dynamic_pointer_cast<sensors::ImuSensor, sensors::Sensor>(pSensor);
       if(pImuSensor == nullptr)
       {
           /*ERROR*/
       }
       else
       {
            /*Do something ... for example to read the linear accel from the IMU:*/
            ignition::math::Vector3d linearAcceleration = m_pImuSensor->LinearAcceleration();
       }
    }
}