A class for interfacing to the microstrain 3dmgx2 and inertialink IMUs. More...
#include <3dmgx2.h>
Public Types | |
enum | cmd { CMD_RAW = 0xC1, CMD_ACCEL_ANGRATE = 0xC2, CMD_DELVEL_DELANG = 0xC3, CMD_CONTINUOUS = 0xC4, CMD_ORIENT = 0xC5, CMD_ATT_UPDATE = 0xC6, CMD_MAG_VEC = 0xC7, CMD_ACCEL_ANGRATE_ORIENT = 0xC8, CMD_WRITE_ACCEL_BIAS = 0xC9, CMD_WRITE_GYRO_BIAS = 0xCA, CMD_ACCEL_ANGRATE_MAG = 0xCB, CMD_ACCEL_ANGRATE_MAG_ORIENT = 0xCC, CMD_CAPTURE_GYRO_BIAS = 0xCD, CMD_EULER = 0xCE, CMD_EULER_ANGRATE = 0xCF, CMD_TEMPERATURES = 0xD1, CMD_GYROSTAB_ANGRATE_MAG = 0xD2, CMD_DELVEL_DELANG_MAG = 0xD3, CMD_DEV_ID_STR = 0xEA, CMD_STOP_CONTINUOUS = 0xFA } |
Enumeration of possible IMU commands. More... | |
enum | id_string { ID_MODEL_NUMBER = 0, ID_SERIAL_NUMBER = 1, ID_DEVICE_NAME = 2, ID_DEVICE_OPTIONS = 3 } |
Enumeration of possible identifier strings for the getDeviceIdentifierString command. More... | |
Public Member Functions | |
void | closePort () |
Close the port. More... | |
bool | getDeviceIdentifierString (id_string type, char id[17]) |
Read one of the device identifier strings. More... | |
IMU () | |
Constructor. More... | |
void | initGyros (double *bias_x=0, double *bias_y=0, double *bias_z=0) |
Initial gyros. More... | |
void | initTime (double fix_off) |
Initialize timing variables. More... | |
void | openPort (const char *port_name) |
Open the port. More... | |
void | receiveAccelAngrate (uint64_t *time, double accel[3], double angrate[3]) |
Read a message of type "ACCEL_ANGRATE". More... | |
void | receiveAccelAngrateMag (uint64_t *time, double accel[3], double angrate[3], double mag[3]) |
Read a message of type "ACCEL_ANGRATE_MAG". More... | |
void | receiveAccelAngrateMagOrientation (uint64_t *time, double accel[3], double angrate[3], double mag[3], double orientation[9]) |
Read a message of type "ACCEL_ANGRATE_MAG_ORIENT". More... | |
void | receiveAccelAngrateOrientation (uint64_t *time, double accel[3], double angrate[3], double orientation[9]) |
Read a message of type "ACCEL_ANGRATE_ORIENTATION". More... | |
void | receiveDelvelDelang (uint64_t *time, double delvel[3], double delang[3]) |
Read a message of type "DELVEL_DELANG". More... | |
void | receiveEuler (uint64_t *time, double *roll, double *pitch, double *yaw) |
Read a message of type "EULER". More... | |
void | receiveRawAccelAngrate (uint64_t *time, double accel[3], double angrate[3]) |
Read a message of type "CMD_RAW". More... | |
bool | setContinuous (cmd command) |
Put the device in continuous mode. More... | |
void | setFixedOffset (double fix_off) |
Set the fixed time offset. More... | |
void | stopContinuous () |
Take the device out of continous mode. More... | |
~IMU () | |
Static Public Attributes | |
static const double | G = 9.80665 |
Gravity (m/sec^2) More... | |
Private Member Functions | |
uint64_t | extractTime (uint8_t *addr) |
Extract time from a pointer into an imu buffer. More... | |
uint64_t | filterTime (uint64_t imu_time, uint64_t sys_time) |
Run the filter on the imu time and system times. More... | |
int | receive (uint8_t command, void *rep, int rep_len, int timeout=0, uint64_t *sys_time=NULL) |
Receive a particular message from the IMU. More... | |
int | send (void *cmd, int cmd_len) |
Send a single packet frmo the IMU. More... | |
double | toDouble (uint64_t time) |
Convert the uint64_t time to a double for numerical computations. More... | |
uint64_t | toUint64_t (double time) |
Convert the double time back to a uint64_t. More... | |
int | transact (void *cmd, int cmd_len, void *rep, int rep_len, int timeout=0) |
Send a command to the IMU and wait for a reply. More... | |
Private Attributes | |
bool | continuous |
Whether continuous mode is enabled. More... | |
unsigned int | counter |
A counter used by the filter. More... | |
double | d_offset |
uint32_t | diff_ticks |
The different in the number of ticks. More... | |
int | fd |
The file descriptor. More... | |
double | fixed_offset |
Variables used by the kalman computation. More... | |
bool | is_gx3 |
Is the IMU a GX3? More... | |
uint32_t | last_ticks |
The last number of ticks for computing wraparound. More... | |
double | offset |
uint32_t | offset_ticks |
The number of ticks the initial offset is off by. More... | |
double | P_time_est [2][2] |
The covariances on time offset and driftrate. More... | |
unsigned long long | start_time |
The time at which the imu was started. More... | |
double | sum_meas |
double | time_est [2] |
The estimate of time offset and driftrate. More... | |
uint32_t | wraps |
The number of times the imu has wrapped. More... | |
Static Private Attributes | |
static const double | KF_K_1 = 0.00995031 |
First KF term. More... | |
static const double | KF_K_2 = 0.0000497506 |
Second KF term. More... | |
static const unsigned int | KF_NUM_SUM = 100 |
Number of KF samples to sum over. More... | |
static const int | MAX_BYTES_SKIPPED = 1000 |
Maximum bytes allowed to be skipped when seeking a message. More... | |
static const int | TICKS_PER_SEC_GX2 = 19660800 |
IMU internal ticks/second. More... | |
static const int | TICKS_PER_SEC_GX3 = 62500 |
A class for interfacing to the microstrain 3dmgx2 and inertialink IMUs.
Note: This class is unreviewed and unsupported. It may change at any time without notice.
Many of the methods within this class may throw an microstrain_3dmgx2_imu::exception, timeout_exception, or corrupted_data_exception.
Before using the IMU, it must be opened via the open_port method. When finished using, it should be closed via the close_port method. Alternatively, close port will get called at destruction.
The library is primarily designed to be used in continuous mode, which is enabled with the set_continuous method, and then serviced with one of the receive methods.
Implementation of specific polled message transactions can be done with the transact method.
Because the timing related to the USB stack is fairly non-deterministic, but the IMU is internally known to be clocked to a 100hz clock, we have wrapped a Kalman filter around calls to get system time, and the internal imu time. This is only known to be reliable when operating in continuous mode, and if init_time is called shortly prior to beginning to get readings.
Example code:
Enumeration of possible IMU commands.
void microstrain_3dmgx2_imu::IMU::closePort | ( | ) |
|
private |
|
private |
bool microstrain_3dmgx2_imu::IMU::getDeviceIdentifierString | ( | id_string | type, |
char | id[17] | ||
) |
void microstrain_3dmgx2_imu::IMU::initGyros | ( | double * | bias_x = 0 , |
double * | bias_y = 0 , |
||
double * | bias_z = 0 |
||
) |
Initial gyros.
This call will prompt the IMU to run its gyro initialization routine.
NOTE: THE IMU MUST BE STATIONARY WHEN THIS ROUTINE IS CALLED
bias_x | Pointer to double where x bias will be placed. |
bias_y | Pointer to double where y bias will be placed. |
bias_z | Pointer to double where z bias will be placed. |
void microstrain_3dmgx2_imu::IMU::initTime | ( | double | fix_off | ) |
void microstrain_3dmgx2_imu::IMU::openPort | ( | const char * | port_name | ) |
|
private |
void microstrain_3dmgx2_imu::IMU::receiveAccelAngrate | ( | uint64_t * | time, |
double | accel[3], | ||
double | angrate[3] | ||
) |
void microstrain_3dmgx2_imu::IMU::receiveAccelAngrateMag | ( | uint64_t * | time, |
double | accel[3], | ||
double | angrate[3], | ||
double | mag[3] | ||
) |
Read a message of type "ACCEL_ANGRATE_MAG".
time | Pointer to uint64_t which will receive time |
accel | array of accelerations which will be filled |
angrate | array of angular rates which will be filled |
mag | array of magnetometer orientations which will be filled |
void microstrain_3dmgx2_imu::IMU::receiveAccelAngrateMagOrientation | ( | uint64_t * | time, |
double | accel[3], | ||
double | angrate[3], | ||
double | mag[3], | ||
double | orientation[9] | ||
) |
Read a message of type "ACCEL_ANGRATE_MAG_ORIENT".
time | Pointer to uint64_t which will receive time |
accel | array of accelerations which will be filled |
angrate | array of angular rates which will be filled |
mag | array of magnetometer orientations which will be filled |
orientation | orientation matrix which will be filled |
void microstrain_3dmgx2_imu::IMU::receiveAccelAngrateOrientation | ( | uint64_t * | time, |
double | accel[3], | ||
double | angrate[3], | ||
double | orientation[9] | ||
) |
Read a message of type "ACCEL_ANGRATE_ORIENTATION".
time | Pointer to uint64_t which will receive time |
accel | array of accelerations which will be filled |
angrate | array of angular rates which will be filled |
orientation | orientation matrix which will be filled |
void microstrain_3dmgx2_imu::IMU::receiveDelvelDelang | ( | uint64_t * | time, |
double | delvel[3], | ||
double | delang[3] | ||
) |
void microstrain_3dmgx2_imu::IMU::receiveEuler | ( | uint64_t * | time, |
double * | roll, | ||
double * | pitch, | ||
double * | yaw | ||
) |
void microstrain_3dmgx2_imu::IMU::receiveRawAccelAngrate | ( | uint64_t * | time, |
double | accel[3], | ||
double | angrate[3] | ||
) |
|
private |
bool microstrain_3dmgx2_imu::IMU::setContinuous | ( | cmd | command | ) |
|
inline |
void microstrain_3dmgx2_imu::IMU::stopContinuous | ( | ) |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
static |
|
private |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
private |
|
staticprivate |
|
private |
|
private |
|
private |
|
staticprivate |
|
staticprivate |
|
private |
|
private |