![]() |
Laelaps
2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
|
#include <laeImu.h>
Public Member Functions | |
LaeImuCleanFlight () | |
Default constructor. | |
virtual | ~LaeImuCleanFlight () |
Destructor. | |
virtual int | numDoFs () |
Get the total degress of freedom of the IMU sensor. More... | |
virtual bool | hasAccelerometer () |
Test if IMU has an accelerometer. More... | |
virtual bool | hasGyroscope () |
Test if IMU has an gyroscope. More... | |
virtual int | readIdentity (std::string &strIdent) |
Read sensor identity values. More... | |
virtual int | readRawImu () |
Read sensor and board raw IMU values. More... | |
virtual int | readRawInertia () |
Read sensors inertia data. More... | |
virtual int | readRawRollPitchYaw () |
Read board's calculated roll, pitch, and yaw raw values. More... | |
virtual int | convertRawToSI () |
Convert last read IMU values to International System of Units. More... | |
![]() | |
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 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 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... | |
Static Public Attributes | |
static const int | SerBaud9600 = 9600 |
9600 serial baudrate | |
static const int | SerBaud19200 = 19200 |
19200 serial baudrate | |
static const int | SerBaud38400 = 38400 |
38400 serial baudrate | |
static const int | SerBaud57600 = 38400 |
38400 serial baudrate | |
static const int | SerBaud115200 = 115200 |
115200 serial baudrate | |
static const int | SerBaudDft = SerBaud115200 |
default serial baudrate | |
static const uint_t | TCmdTimeout = 1000 |
command timeout (usec) | |
static const uint_t | TRspTimeout = 12000 |
response timeout (usec) | |
static const uint_t | TFlushDelay = 100 |
flush buffer delay (usec) | |
Protected Member Functions | |
int | mspReadIdent (msp::MspIdent &ident) |
Read CleanFlight board's identity values. More... | |
int | mspReadRawImu () |
Read raw IMU data. More... | |
int | mspReadAttitude () |
MSP command/response. More... | |
int | sendCmd (uint_t cmdId, byte_t cmdData[], size_t lenData) |
Send command to IMU. More... | |
int | receiveRsp (uint_t cmdId, byte_t rspData[], size_t lenData) |
void | resyncComm () |
Attempt to resynchronize the serial communication between the host and the IMU. | |
void | flush (uint_t t) |
Flush serial input and output FIFOs, discarding all data. More... | |
int | pack16 (int val, byte_t buf[]) |
Pack 16-bit signed value into buffer. More... | |
int | pack16 (uint_t val, byte_t buf[]) |
Pack 16-bit unsigned value into buffer. More... | |
int | unpack16 (byte_t buf[], int &val) |
Unpack 16-bit signed value from buffer. More... | |
int | unpack16 (byte_t buf[], uint_t &val) |
Unpack 16-bit unsigned value from buffer. More... | |
int | pack32 (int val, byte_t buf[]) |
Pack 32-bit signed value into buffer. More... | |
int | pack32 (uint_t val, byte_t buf[]) |
Pack 32-bit unsigned value into buffer. More... | |
int | unpack32 (byte_t buf[], int &val) |
Unpack 32-bit signed value from buffer. More... | |
int | unpack32 (byte_t buf[], uint_t &val) |
Unpack 32-bit unsigned value from buffer. More... | |
![]() | |
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... | |
Additional Inherited Members | |
![]() | |
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 | |
Inertia Measurement Unit class running the CleanFlight firmware.
|
virtual |
Convert last read IMU values to International System of Units.
Implements sensor::imu::LaeImu.
Definition at line 452 of file laeImu.cxx.
References laelaps::degToRad(), sensor::imu::LaeImu::m_accel, sensor::imu::LaeImu::m_accelRaw, sensor::imu::LaeImu::m_gyro, sensor::imu::LaeImu::m_gyroRaw, sensor::imu::LaeImu::m_rpy, sensor::imu::LaeImu::m_rpyRaw, sensor::imu::msp::MspAttitudeRawToDeg, sensor::imu::msp::MspGToMPerSec2, sensor::imu::msp::MspMpu6050RawToDegPerSec, sensor::imu::msp::MspMpu6050RawToG, sensor::imu::NumOfAxes, and sensor::imu::YAW.
|
protected |
Flush serial input and output FIFOs, discarding all data.
t | Delay time (usec) before flushing. Zero means no delay. |
Definition at line 718 of file laeImu.cxx.
References sensor::imu::LaeImu::m_fd.
Referenced by receiveRsp(), resyncComm(), and sendCmd().
|
inlinevirtual |
Test if IMU has an accelerometer.
Reimplemented from sensor::imu::LaeImu.
|
inlinevirtual |
|
protected |
MSP command/response.
Definition at line 549 of file laeImu.cxx.
References sensor::imu::LaeImu::isOpen(), sensor::imu::LaeImu::lockIo(), sensor::imu::LaeImu::m_rpyRaw, sensor::imu::msp::MspCmdIdAttitude, sensor::imu::NumOfAxes, receiveRsp(), sendCmd(), sensor::imu::LaeImu::unlockIo(), and unpack16().
Referenced by readRawImu(), and readRawRollPitchYaw().
|
protected |
Read CleanFlight board's identity values.
MSP command/response.
[out] | ident | Identity. |
Definition at line 474 of file laeImu.cxx.
References sensor::imu::LaeImu::isOpen(), sensor::imu::LaeImu::lockIo(), sensor::imu::msp::MspIdent::m_uCaps, sensor::imu::msp::MspIdent::m_uFwVersion, sensor::imu::msp::MspIdent::m_uMspVersion, sensor::imu::msp::MspIdent::m_uMultiType, sensor::imu::msp::MspCmdIdIdent, receiveRsp(), sendCmd(), sensor::imu::LaeImu::unlockIo(), and unpack32().
Referenced by readIdentity(), and resyncComm().
|
protected |
Read raw IMU data.
Read data are updated to local class object member data.
MSP command/response.
Definition at line 507 of file laeImu.cxx.
References sensor::imu::LaeImu::isOpen(), sensor::imu::LaeImu::lockIo(), sensor::imu::LaeImu::m_accelRaw, sensor::imu::LaeImu::m_gyroRaw, sensor::imu::LaeImu::m_magRaw, sensor::imu::msp::MspCmdIdRawImu, sensor::imu::NumOfAxes, receiveRsp(), sendCmd(), sensor::imu::LaeImu::unlockIo(), and unpack16().
Referenced by readRawImu(), and readRawInertia().
|
inlinevirtual |
Get the total degress of freedom of the IMU sensor.
Reimplemented from sensor::imu::LaeImu.
|
inlineprotected |
Pack 16-bit signed value into buffer.
Order is little-endian (LSB first).
[in] | val | Value to pack. |
[out] | buf | Destination buffer. |
Definition at line 859 of file laeImu.h.
|
protected |
Pack 16-bit unsigned value into buffer.
Order is little-endian (LSB first).
[in] | val | Value to pack. |
[out] | buf | Destination buffer. |
Definition at line 729 of file laeImu.cxx.
|
inlineprotected |
Pack 32-bit signed value into buffer.
Order is little-endian (LSB first).
[in] | val | Value to pack. |
[out] | buf | Destination buffer. |
Definition at line 910 of file laeImu.h.
|
protected |
Pack 32-bit unsigned value into buffer.
Order is little-endian (LSB first).
[in] | val | Value to pack. |
[out] | buf | Destination buffer. |
Definition at line 750 of file laeImu.cxx.
|
virtual |
Read sensor identity values.
[out] | strIdent | Hardware specific, formated identity string. |
Implements sensor::imu::LaeImu.
Definition at line 376 of file laeImu.cxx.
References sensor::imu::LaeImu::isBlackListed(), sensor::imu::LaeImu::m_strIdent, sensor::imu::msp::MspIdent::m_uFwVersion, and mspReadIdent().
Referenced by laelaps::LaeRobot::connSensors().
|
virtual |
Read sensor and board raw IMU values.
The CleanFlight Naze32 with MPU-6050 sensor has:
Implements sensor::imu::LaeImu.
Definition at line 401 of file laeImu.cxx.
References sensor::imu::LaeImu::isBlackListed(), mspReadAttitude(), and mspReadRawImu().
|
virtual |
Read sensors inertia data.
Definition at line 418 of file laeImu.cxx.
References sensor::imu::LaeImu::isBlackListed(), and mspReadRawImu().
|
virtual |
Read board's calculated roll, pitch, and yaw raw values.
Definition at line 435 of file laeImu.cxx.
References sensor::imu::LaeImu::isBlackListed(), and mspReadAttitude().
|
protected |
cmdId | Response's associated MSP command id. | |
[out] | rspData | Optional response data. |
lenData | Length of response data. Zero if no data. |
Definition at line 623 of file laeImu.cxx.
References flush(), sensor::imu::LaeImu::m_fd, sensor::imu::msp::MspFieldPosCmdId, sensor::imu::msp::MspFieldPosDataStart, sensor::imu::msp::MspFieldPosSize, sensor::imu::msp::MspRspMaxLen, sensor::imu::msp::MspRspMinLen, resyncComm(), TFlushDelay, and TRspTimeout.
Referenced by mspReadAttitude(), mspReadIdent(), mspReadRawImu(), and Laelaps.Imu.Imu::unpackS32().
|
protected |
Send command to IMU.
cmdId | MSP command id. | |
[in] | cmdData | Optional command data. |
lenData | Length of command data. Zero if no data. |
Definition at line 584 of file laeImu.cxx.
References flush(), sensor::imu::LaeImu::m_fd, sensor::imu::msp::MspCmdMaxLen, sensor::imu::msp::MspCmdPreamble, TCmdTimeout, and TFlushDelay.
Referenced by mspReadAttitude(), mspReadIdent(), mspReadRawImu(), and Laelaps.Imu.Imu::unpackS32().
|
protected |
Unpack 16-bit signed value from buffer.
Buffer is little-endian (LSB first).
[in] | buf | Source buffer. |
[out] | val | Unpacked value. |
Definition at line 742 of file laeImu.cxx.
Referenced by mspReadAttitude(), and mspReadRawImu().
|
protected |
Unpack 16-bit unsigned value from buffer.
Buffer is little-endian (LSB first).
[in] | buf | Source buffer. |
[out] | val | Unpacked value. |
Definition at line 736 of file laeImu.cxx.
|
protected |
Unpack 32-bit signed value from buffer.
Buffer is little-endian (LSB first).
[in] | buf | Source buffer. |
[out] | val | Unpacked value. |
Definition at line 768 of file laeImu.cxx.
Referenced by mspReadIdent().
|
protected |
Unpack 32-bit unsigned value from buffer.
Buffer is little-endian (LSB first).
[in] | buf | Source buffer. |
[out] | val | Unpacked value. |
Definition at line 759 of file laeImu.cxx.