Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
sensor::imu::LaeImu Class Referenceabstract

#include <laeImu.h>

Inheritance diagram for sensor::imu::LaeImu:
sensor::imu::LaeImuCleanFlight

Public Member Functions

 LaeImu (std::string strIdent="Virtual IMU")
 Default constructor. More...
 
virtual ~LaeImu ()
 Destructor.
 
virtual int open (const std::string &strDevName, int nBaudRate)
 
virtual int close ()
 Close connection to motor controller. More...
 
virtual bool isOpen ()
 Check if IMU serial interface is open. More...
 
virtual void blacklist ()
 Black list IMU from robot sensors.
 
virtual void whitelist ()
 White list IMU sensor.
 
virtual bool isBlackListed ()
 Test if IMU is black listed. More...
 
virtual void clearSensedData ()
 Clear IMU sensed data.
 
virtual int numDoFs ()
 Get the total IMU degress of freedom. More...
 
virtual bool hasAccelerometer ()
 Test if IMU has an accelerometer. More...
 
virtual bool hasGyroscope ()
 Test if IMU has an gyroscope. More...
 
virtual bool hasMagnetometer ()
 Test if IMU has an magnetometer. More...
 
virtual int configure (const laelaps::LaeDesc &desc)
 Configure IMU from product description. More...
 
virtual int configure (const laelaps::LaeTunes &tunes)
 Configure IMU from tunable parameters. More...
 
virtual int reload (const laelaps::LaeTunes &tunes)
 Reload with new tuning parameters. More...
 
virtual int readIdentity (std::string &strIdent)=0
 Read sensor identity values. More...
 
virtual int readRawImu ()=0
 Read sensor raw IMU values. More...
 
virtual int convertRawToSI ()=0
 Convert last read IMU values to International System of Units. More...
 
virtual void compute ()
 Compute all IMU values form converted, raw values. More...
 
virtual void computeQuaternion ()
 Compute the quaternion from the IMU data.
 
virtual void computeDynamics ()
 Compute the velocity, position, and any other dynamics from the IMU data. More...
 
virtual void exec ()
 Exectute one step to read, convert, and compute IMU values.
 
std::string getIdentity ()
 Get IMU identity. More...
 
std::string getDevName ()
 Get IMU device name. More...
 
virtual void getRawInertiaData (int accel[], int gyro[])
 Get the last read raw inertia data. More...
 
virtual void getInertiaData (double accel[], double gyro[])
 Get the last read and converted inertia data. More...
 
virtual void getMagnetometerData (double mag[])
 Get the last read magnetometer values. More...
 
virtual void getAttitude (double rpy[])
 Get the last read IMU (vehicle) attitude. More...
 
virtual void getAttitude (double &roll, double &pitch, double &yaw)
 Get the last read IMU (vehicle) attitude. More...
 
virtual void getQuaternion (Quaternion &q)
 Get the last computed quaternion. More...
 
virtual void getImuData (double accel[], double gyro[], double mag[], double rpy[], Quaternion &q)
 Get the last sensed, converted, and computed IMU data. More...
 

Protected Member Functions

void lockIo ()
 Lock the shared I/O resource. More...
 
void unlockIo ()
 Unlock the shared I/O resource. More...
 
void lockOp ()
 Lock the extended operation. More...
 
void unlockOp ()
 Unlock the extended operation. More...
 

Protected Attributes

std::string m_strIdent
 IMU identity.
 
std::string m_strDevName
 serial device name
 
int m_nBaudRate
 device baudrate
 
int m_fd
 opened device file descriptor
 
bool m_bBlackListed
 IMU is [not] black listed.
 
int m_accelRaw [NumOfAxes]
 accelerometer raw values
 
int m_gyroRaw [NumOfAxes]
 gyroscope raw values
 
int m_magRaw [NumOfAxes]
 magnetometer raw values
 
int m_rpyRaw [NumOfAxes]
 roll,pitch,yaw raw values
 
double m_accel [NumOfAxes]
 accelerometer (m/s^2)
 
double m_gyro [NumOfAxes]
 gyrscope (radians/s)
 
double m_mag [NumOfAxes]
 magnetometer (tesla)
 
double m_rpy [NumOfAxes]
 roll,pitch,yaw (radians)
 
Quaternion m_quaternion
 imu orientation (and robot)
 
pthread_mutex_t m_mutexIo
 low-level I/O mutex
 
pthread_mutex_t m_mutexOp
 high-level operation mutex
 

Detailed Description

Inertia Measurement Unit virtual base class with serial interface.

Definition at line 185 of file laeImu.h.

Constructor & Destructor Documentation

LaeImu::LaeImu ( std::string  strIdent = "Virtual IMU")

Default constructor.

Parameters
strIdentIMU identity string.

Definition at line 143 of file laeImu.cxx.

References clearSensedData(), m_bBlackListed, m_fd, m_mutexIo, and m_mutexOp.

143  : m_strIdent(strIdent)
144 {
145  m_fd = -1;
146  m_bBlackListed = false;
147 
148  clearSensedData();
149 
150  pthread_mutex_init(&m_mutexIo, NULL);
151  pthread_mutex_init(&m_mutexOp, NULL);
152 }
std::string m_strIdent
IMU identity.
Definition: laeImu.h:496
int m_fd
opened device file descriptor
Definition: laeImu.h:499
pthread_mutex_t m_mutexIo
low-level I/O mutex
Definition: laeImu.h:530
virtual void clearSensedData()
Clear IMU sensed data.
Definition: laeImu.cxx:252
pthread_mutex_t m_mutexOp
high-level operation mutex
Definition: laeImu.h:531
bool m_bBlackListed
IMU is [not] black listed.
Definition: laeImu.h:500

Member Function Documentation

int LaeImu::close ( )
virtual

Close connection to motor controller.

Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 201 of file laeImu.cxx.

References lockIo(), m_fd, m_nBaudRate, m_strDevName, and unlockIo().

Referenced by Laelaps.WatchDog.WatchDog::attach(), blacklist(), laelaps::LaeRobot::disconnect(), Laelaps.WatchDog.WatchDog::open(), and ~LaeImu().

202 {
203  lockIo();
204 
205  if( m_fd >= 0 )
206  {
207  SerDevClose(m_fd);
208  LOGDIAG2("Closed %s interface to IMU.", m_strDevName.c_str());
209  }
210 
211  m_strDevName.clear();
212  m_nBaudRate = 0;
213  m_fd = -1;
214 
215  unlockIo();
216 
217  return LAE_OK;
218 }
void lockIo()
Lock the shared I/O resource.
Definition: laeImu.h:541
void unlockIo()
Unlock the shared I/O resource.
Definition: laeImu.h:552
int m_fd
opened device file descriptor
Definition: laeImu.h:499
int m_nBaudRate
device baudrate
Definition: laeImu.h:498
std::string m_strDevName
serial device name
Definition: laeImu.h:497
void LaeImu::compute ( )
virtual

Compute all IMU values form converted, raw values.

Todo:

Definition at line 270 of file laeImu.cxx.

References computeDynamics(), and computeQuaternion().

Referenced by exec().

271 {
273  computeDynamics();
274 }
virtual void computeQuaternion()
Compute the quaternion from the IMU data.
Definition: laeImu.cxx:276
virtual void computeDynamics()
Compute the velocity, position, and any other dynamics from the IMU data.
Definition: laeImu.cxx:281
void LaeImu::computeDynamics ( )
virtual

Compute the velocity, position, and any other dynamics from the IMU data.

Todo:

Definition at line 281 of file laeImu.cxx.

Referenced by compute().

282 {
283 }
int LaeImu::configure ( const laelaps::LaeDesc desc)
virtual

Configure IMU from product description.

Call after connection is opened.

Parameters
descProduct description.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 237 of file laeImu.cxx.

Referenced by laelaps::LaeRobot::configForOperation().

238 {
239  return LAE_OK;
240 }
int LaeImu::configure ( const laelaps::LaeTunes tunes)
virtual

Configure IMU from tunable parameters.

Call after connection is opened.

Parameters
tunesLaelaps tuning parameters.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 242 of file laeImu.cxx.

243 {
244  return LAE_OK;
245 }
virtual int sensor::imu::LaeImu::convertRawToSI ( )
pure virtual

Convert last read IMU values to International System of Units.

Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Implemented in sensor::imu::LaeImuCleanFlight.

Referenced by exec().

void LaeImu::getAttitude ( double  rpy[])
virtual

Get the last read IMU (vehicle) attitude.

Note
N/A data are set to zero.
Parameters
[out]rpyVehicle roll, pitch, and yaw (radians). The array size must be ≥ NumOfAxes.

Definition at line 329 of file laeImu.cxx.

References m_rpy, and sensor::imu::NumOfAxes.

Referenced by getImuData().

330 {
331  for(int i = 0; i < NumOfAxes; ++i)
332  {
333  rpy[i] = m_rpy[i];
334  }
335 }
double m_rpy[NumOfAxes]
roll,pitch,yaw (radians)
Definition: laeImu.h:516
const int NumOfAxes
maximum number of axes per sensor component.
Definition: laeImu.h:98
void LaeImu::getAttitude ( double &  roll,
double &  pitch,
double &  yaw 
)
virtual

Get the last read IMU (vehicle) attitude.

Note
N/A data are set to zero.
Parameters
[out]rollVehicle roll (radians).
[out]pitchVehicle pitch (radians).
[out]yawVehicle yaw (radians).

Definition at line 337 of file laeImu.cxx.

References m_rpy, sensor::imu::PITCH, sensor::imu::ROLL, and sensor::imu::YAW.

338 {
339  roll = m_rpy[ROLL];
340  pitch = m_rpy[PITCH];
341  yaw = m_rpy[YAW];
342 }
double m_rpy[NumOfAxes]
roll,pitch,yaw (radians)
Definition: laeImu.h:516
yaw index
Definition: laeImu.h:107
roll index
Definition: laeImu.h:105
pitch index
Definition: laeImu.h:106
std::string sensor::imu::LaeImu::getDevName ( )
inline

Get IMU device name.

Returns
String.

Definition at line 396 of file laeImu.h.

397  {
398  return m_strDevName;
399  }
std::string m_strDevName
serial device name
Definition: laeImu.h:497
std::string sensor::imu::LaeImu::getIdentity ( )
inline

Get IMU identity.

Returns
String.

Definition at line 387 of file laeImu.h.

388  {
389  return m_strIdent;
390  }
std::string m_strIdent
IMU identity.
Definition: laeImu.h:496
void LaeImu::getImuData ( double  accel[],
double  gyro[],
double  mag[],
double  rpy[],
Quaternion q 
)
virtual

Get the last sensed, converted, and computed IMU data.

Note
N/A data are set to zero.
Parameters
[out]accelAccelerometer data (m/s^2). The array size must be ≥ NumOfAxes.
[out]gyroGyroscope data (radians/s). The array size must be ≥ NumOfAxes.
[out]magMagnetometer data (tesla). The array size must be ≥ NumOfAxes.
[out]rpyVehicle roll, pitch, and yaw (radians). The array size must be ≥ NumOfAxes.
[out]qVehicle quaternion.

Definition at line 349 of file laeImu.cxx.

References getAttitude(), getInertiaData(), getMagnetometerData(), getQuaternion(), lockOp(), and unlockOp().

Referenced by laelaps::LaeRobot::getImu().

351 {
352  lockOp();
353 
354  getInertiaData(accel, gyro);
355  getMagnetometerData(mag);
356  getAttitude(rpy);
357  getQuaternion(q);
358 
359  unlockOp();
360 }
void unlockOp()
Unlock the extended operation.
Definition: laeImu.h:576
virtual void getQuaternion(Quaternion &q)
Get the last computed quaternion.
Definition: laeImu.cxx:344
virtual void getMagnetometerData(double mag[])
Get the last read magnetometer values.
Definition: laeImu.cxx:321
void lockOp()
Lock the extended operation.
Definition: laeImu.h:565
virtual void getAttitude(double rpy[])
Get the last read IMU (vehicle) attitude.
Definition: laeImu.cxx:329
virtual void getInertiaData(double accel[], double gyro[])
Get the last read and converted inertia data.
Definition: laeImu.cxx:312
void LaeImu::getInertiaData ( double  accel[],
double  gyro[] 
)
virtual

Get the last read and converted inertia data.

Note
N/A data are set to zero.
Parameters
[out]accelAccelerometer data (m/s^2). The array size must be ≥ NumOfAxes.
[out]gyroGyroscope data (radians/s). The array size must be ≥ NumOfAxes.

Definition at line 312 of file laeImu.cxx.

References m_accel, m_gyro, and sensor::imu::NumOfAxes.

Referenced by getImuData().

313 {
314  for(int i = 0; i < NumOfAxes; ++i)
315  {
316  accel[i] = m_accel[i];
317  gyro[i] = m_gyro[i];
318  }
319 }
double m_accel[NumOfAxes]
accelerometer (m/s^2)
Definition: laeImu.h:513
const int NumOfAxes
maximum number of axes per sensor component.
Definition: laeImu.h:98
double m_gyro[NumOfAxes]
gyrscope (radians/s)
Definition: laeImu.h:514
void LaeImu::getMagnetometerData ( double  mag[])
virtual

Get the last read magnetometer values.

Note
N/A data are set to zero.
Parameters
[out]magMagnetometer data (tesla). The array size must be ≥ NumOfAxes.

Definition at line 321 of file laeImu.cxx.

References m_mag, and sensor::imu::NumOfAxes.

Referenced by getImuData().

322 {
323  for(int i = 0; i < NumOfAxes; ++i)
324  {
325  mag[i] = m_mag[i];
326  }
327 }
double m_mag[NumOfAxes]
magnetometer (tesla)
Definition: laeImu.h:515
const int NumOfAxes
maximum number of axes per sensor component.
Definition: laeImu.h:98
void LaeImu::getQuaternion ( Quaternion q)
virtual

Get the last computed quaternion.

Parameters
[out]qVehicle quaternion.

Definition at line 344 of file laeImu.cxx.

References m_quaternion.

Referenced by getImuData().

345 {
346  q = m_quaternion;
347 }
Quaternion m_quaternion
imu orientation (and robot)
Definition: laeImu.h:517
void LaeImu::getRawInertiaData ( int  accel[],
int  gyro[] 
)
virtual

Get the last read raw inertia data.

Note
N/A data are set to zero.
Parameters
[out]accelRaw accelerometer data. The array size must be ≥ NumOfAxes.
[out]gyroRaw gyroscope data. The array size must be ≥ NumOfAxes.

Definition at line 303 of file laeImu.cxx.

References m_accelRaw, m_gyroRaw, and sensor::imu::NumOfAxes.

304 {
305  for(int i = 0; i < NumOfAxes; ++i)
306  {
307  accel[i] = m_accelRaw[i];
308  gyro[i] = m_gyroRaw[i];
309  }
310 }
int m_gyroRaw[NumOfAxes]
gyroscope raw values
Definition: laeImu.h:506
int m_accelRaw[NumOfAxes]
accelerometer raw values
Definition: laeImu.h:505
const int NumOfAxes
maximum number of axes per sensor component.
Definition: laeImu.h:98
virtual bool sensor::imu::LaeImu::hasAccelerometer ( )
inlinevirtual

Test if IMU has an accelerometer.

Returns
Returns true or false.

Reimplemented in sensor::imu::LaeImuCleanFlight.

Definition at line 267 of file laeImu.h.

268  {
269  return false;
270  }
virtual bool sensor::imu::LaeImu::hasGyroscope ( )
inlinevirtual

Test if IMU has an gyroscope.

Returns
Returns true or false.

Reimplemented in sensor::imu::LaeImuCleanFlight.

Definition at line 277 of file laeImu.h.

278  {
279  return false;
280  }
virtual bool sensor::imu::LaeImu::hasMagnetometer ( )
inlinevirtual

Test if IMU has an magnetometer.

Returns
Returns true or false.

Definition at line 287 of file laeImu.h.

288  {
289  return false;
290  }
virtual bool sensor::imu::LaeImu::isBlackListed ( )
inlinevirtual

Test if IMU is black listed.

Returns
Returns true or false.

Definition at line 242 of file laeImu.h.

Referenced by exec(), sensor::imu::LaeImuCleanFlight::readIdentity(), sensor::imu::LaeImuCleanFlight::readRawImu(), sensor::imu::LaeImuCleanFlight::readRawInertia(), and sensor::imu::LaeImuCleanFlight::readRawRollPitchYaw().

243  {
244  return m_bBlackListed;
245  }
bool m_bBlackListed
IMU is [not] black listed.
Definition: laeImu.h:500
void sensor::imu::LaeImu::lockIo ( )
inlineprotected

Lock the shared I/O resource.

The lock()/unlock() primitives provide for safe multi-threading.

Context:
Any.

Definition at line 541 of file laeImu.h.

Referenced by close(), sensor::imu::LaeImuCleanFlight::mspReadAttitude(), sensor::imu::LaeImuCleanFlight::mspReadIdent(), sensor::imu::LaeImuCleanFlight::mspReadRawImu(), and open().

542  {
543  pthread_mutex_lock(&m_mutexIo);
544  }
pthread_mutex_t m_mutexIo
low-level I/O mutex
Definition: laeImu.h:530
void sensor::imu::LaeImu::lockOp ( )
inlineprotected

Lock the extended operation.

The lock()/unlock() primitives provide for safe multi-threading.

Context:
Any.

Definition at line 565 of file laeImu.h.

Referenced by exec(), and getImuData().

566  {
567  pthread_mutex_lock(&m_mutexOp);
568  }
pthread_mutex_t m_mutexOp
high-level operation mutex
Definition: laeImu.h:531
virtual int sensor::imu::LaeImu::numDoFs ( )
inlinevirtual

Get the total IMU degress of freedom.

Returns
DoF

Reimplemented in sensor::imu::LaeImuCleanFlight.

Definition at line 257 of file laeImu.h.

258  {
259  return 0;
260  }
int LaeImu::open ( const std::string &  strDevName,
int  nBaudRate 
)
virtual

Open connection to IMU.

Parameters
strDevNameSerial device name.
nBaudRateSerial device baud rate.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 162 of file laeImu.cxx.

References clearSensedData(), laelaps::getRealDeviceName(), lockIo(), m_bBlackListed, m_fd, m_nBaudRate, m_strDevName, and unlockIo().

Referenced by laelaps::LaeRobot::connSensors().

163 {
164  string strDevNameReal;
165  int rc;
166 
167  lockIo();
168 
169  // Get the real device name, not any symbolic links.
170  strDevNameReal = getRealDeviceName(strDevName);
171 
172  m_fd = SerDevOpen(strDevNameReal.c_str(), nBaudRate, 8, 'N', 1, false, false);
173 
174  if( m_fd < 0 )
175  {
176  LOGERROR("Failed to open %s@%d.", strDevNameReal.c_str(), nBaudRate);
177  rc = -LAE_ECODE_NO_DEV;
178  }
179 
180  else
181  {
182  m_strDevName = strDevNameReal;
183  m_nBaudRate = nBaudRate;
184  m_bBlackListed = false;
185 
186  RtDb.m_enable.m_bImu = true;
187 
188  clearSensedData();
189 
190  LOGDIAG2("Opened interface to IMU on %s@%d.",
191  strDevNameReal.c_str(), nBaudRate);
192 
193  rc = LAE_OK;
194  }
195 
196  unlockIo();
197 
198  return rc;
199 }
void lockIo()
Lock the shared I/O resource.
Definition: laeImu.h:541
void unlockIo()
Unlock the shared I/O resource.
Definition: laeImu.h:552
int m_fd
opened device file descriptor
Definition: laeImu.h:499
virtual void clearSensedData()
Clear IMU sensed data.
Definition: laeImu.cxx:252
int m_nBaudRate
device baudrate
Definition: laeImu.h:498
bool m_bBlackListed
IMU is [not] black listed.
Definition: laeImu.h:500
std::string m_strDevName
serial device name
Definition: laeImu.h:497
std::string getRealDeviceName(const std::string &strDevName)
Get real device name.
virtual int sensor::imu::LaeImu::readIdentity ( std::string &  strIdent)
pure virtual

Read sensor identity values.

Parameters
[out]strIdentHardware specific, formated identity string.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Implemented in sensor::imu::LaeImuCleanFlight.

virtual int sensor::imu::LaeImu::readRawImu ( )
pure virtual

Read sensor raw IMU values.

Depending on the sensor and the board, raw values read:

  • accelerometer
  • gyroscope
  • magnetometer
  • GPS
  • barometer
  • temperature
  • accurate timing
  • attitude
  • quaternions
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Implemented in sensor::imu::LaeImuCleanFlight.

Referenced by exec().

int LaeImu::reload ( const laelaps::LaeTunes tunes)
virtual

Reload with new tuning parameters.

Parameters
tunesLaelaps tuning parameters.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 247 of file laeImu.cxx.

Referenced by laelaps::LaeThreadImu::reload().

248 {
249  return LAE_OK;
250 }
void sensor::imu::LaeImu::unlockIo ( )
inlineprotected

Unlock the shared I/O resource.

Context:
Any.

Definition at line 552 of file laeImu.h.

Referenced by close(), sensor::imu::LaeImuCleanFlight::mspReadAttitude(), sensor::imu::LaeImuCleanFlight::mspReadIdent(), sensor::imu::LaeImuCleanFlight::mspReadRawImu(), and open().

553  {
554  pthread_mutex_unlock(&m_mutexIo);
555  }
pthread_mutex_t m_mutexIo
low-level I/O mutex
Definition: laeImu.h:530
void sensor::imu::LaeImu::unlockOp ( )
inlineprotected

Unlock the extended operation.

Context:
Any.

Definition at line 576 of file laeImu.h.

Referenced by exec(), and getImuData().

577  {
578  pthread_mutex_unlock(&m_mutexOp);
579  }
pthread_mutex_t m_mutexOp
high-level operation mutex
Definition: laeImu.h:531

The documentation for this class was generated from the following files: