$search
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. | |
bool | getDeviceIdentifierString (id_string type, char id[17]) |
Read one of the device identifier strings. | |
IMU () | |
Constructor. | |
void | initGyros (double *bias_x=0, double *bias_y=0, double *bias_z=0) |
Initial gyros. | |
void | initTime (double fix_off) |
Initialize timing variables. | |
void | openPort (const char *port_name) |
Open the port. | |
void | receiveAccelAngrate (uint64_t *time, double accel[3], double angrate[3]) |
Read a message of type "ACCEL_ANGRATE". | |
void | receiveAccelAngrateMag (uint64_t *time, double accel[3], double angrate[3], double mag[3]) |
Read a message of type "ACCEL_ANGRATE_MAG". | |
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". | |
void | receiveAccelAngrateOrientation (uint64_t *time, double accel[3], double angrate[3], double orientation[9]) |
Read a message of type "ACCEL_ANGRATE_ORIENTATION". | |
void | receiveDelvelDelang (uint64_t *time, double delvel[3], double delang[3]) |
Read a message of type "DELVEL_DELANG". | |
void | receiveEuler (uint64_t *time, double *roll, double *pitch, double *yaw) |
Read a message of type "EULER". | |
void | receiveRawAccelAngrate (uint64_t *time, double accel[3], double angrate[3]) |
Read a message of type "CMD_RAW". | |
bool | setContinuous (cmd command) |
Put the device in continuous mode. | |
void | setFixedOffset (double fix_off) |
Set the fixed time offset. | |
void | stopContinuous () |
Take the device out of continous mode. | |
~IMU () | |
Static Public Attributes | |
static const double | G = 9.80665 |
Gravity (m/sec^2). | |
Private Member Functions | |
uint64_t | extractTime (uint8_t *addr) |
Extract time from a pointer into an imu buffer. | |
uint64_t | filterTime (uint64_t imu_time, uint64_t sys_time) |
Run the filter on the imu time and system times. | |
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. | |
int | send (void *cmd, int cmd_len) |
Send a single packet frmo the IMU. | |
double | toDouble (uint64_t time) |
Convert the uint64_t time to a double for numerical computations. | |
uint64_t | toUint64_t (double time) |
Convert the double time back to a uint64_t. | |
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. | |
Private Attributes | |
bool | continuous |
Whether continuous mode is enabled. | |
unsigned int | counter |
A counter used by the filter. | |
double | d_offset |
uint32_t | diff_ticks |
The different in the number of ticks. | |
int | fd |
The file descriptor. | |
double | fixed_offset |
Variables used by the kalman computation. | |
bool | is_gx3 |
Is the IMU a GX3? | |
uint32_t | last_ticks |
The last number of ticks for computing wraparound. | |
double | offset |
uint32_t | offset_ticks |
The number of ticks the initial offset is off by. | |
double | P_time_est [2][2] |
The covariances on time offset and driftrate. | |
unsigned long long | start_time |
The time at which the imu was started. | |
double | sum_meas |
double | time_est [2] |
The estimate of time offset and driftrate. | |
uint32_t | wraps |
The number of times the imu has wrapped. | |
Static Private Attributes | |
static const double | KF_K_1 = 0.00995031 |
First KF term. | |
static const double | KF_K_2 = 0.0000497506 |
Second KF term. | |
static const unsigned int | KF_NUM_SUM = 100 |
Number of KF samples to sum over. | |
static const int | MAX_BYTES_SKIPPED = 1000 |
Maximum bytes allowed to be skipped when seeking a message. | |
static const int | TICKS_PER_SEC_GX2 = 19660800 |
IMU internal ticks/second. | |
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:
microstrain_3dmgx2_imu::IMU imu; imu.open_port("/dev/ttyUSB0"); imu.init_time(); imu.init_gyros(); imu.set_continuous(microstrain_3dmgx2_imu::IMU::CMD_ACCEL_ANGRATE_ORIENT); while (int i = 0 ; i < 100; i++) { double accel[3]; double angrate[3]; double orientation[9]; imu.receive_accel_angrate_orientation(&time, accel, angrate, orientation); } imu.close_port();
Definition at line 91 of file 3dmgx2.h.
Enumeration of possible IMU commands.
void microstrain_3dmgx2_imu::IMU::closePort | ( | ) |
uint64_t microstrain_3dmgx2_imu::IMU::extractTime | ( | uint8_t * | addr | ) | [private] |
uint64_t microstrain_3dmgx2_imu::IMU::filterTime | ( | uint64_t | imu_time, | |
uint64_t | sys_time | |||
) | [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 | ) |
int microstrain_3dmgx2_imu::IMU::receive | ( | uint8_t | command, | |
void * | rep, | |||
int | rep_len, | |||
int | timeout = 0 , |
|||
uint64_t * | sys_time = NULL | |||
) | [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] | |||
) |
int microstrain_3dmgx2_imu::IMU::send | ( | void * | cmd, | |
int | cmd_len | |||
) | [private] |
bool microstrain_3dmgx2_imu::IMU::setContinuous | ( | cmd | command | ) |
void microstrain_3dmgx2_imu::IMU::setFixedOffset | ( | double | fix_off | ) | [inline] |
void microstrain_3dmgx2_imu::IMU::stopContinuous | ( | ) |
double microstrain_3dmgx2_imu::IMU::toDouble | ( | uint64_t | time | ) | [private] |
uint64_t microstrain_3dmgx2_imu::IMU::toUint64_t | ( | double | time | ) | [private] |
int microstrain_3dmgx2_imu::IMU::transact | ( | void * | cmd, | |
int | cmd_len, | |||
void * | rep, | |||
int | rep_len, | |||
int | timeout = 0 | |||
) | [private] |
bool microstrain_3dmgx2_imu::IMU::continuous [private] |
unsigned int microstrain_3dmgx2_imu::IMU::counter [private] |
double microstrain_3dmgx2_imu::IMU::d_offset [private] |
uint32_t microstrain_3dmgx2_imu::IMU::diff_ticks [private] |
int microstrain_3dmgx2_imu::IMU::fd [private] |
double microstrain_3dmgx2_imu::IMU::fixed_offset [private] |
const double microstrain_3dmgx2_imu::IMU::G = 9.80665 [static] |
bool microstrain_3dmgx2_imu::IMU::is_gx3 [private] |
const double microstrain_3dmgx2_imu::IMU::KF_K_1 = 0.00995031 [static, private] |
const double microstrain_3dmgx2_imu::IMU::KF_K_2 = 0.0000497506 [static, private] |
const unsigned int microstrain_3dmgx2_imu::IMU::KF_NUM_SUM = 100 [static, private] |
uint32_t microstrain_3dmgx2_imu::IMU::last_ticks [private] |
const int microstrain_3dmgx2_imu::IMU::MAX_BYTES_SKIPPED = 1000 [static, private] |
double microstrain_3dmgx2_imu::IMU::offset [private] |
uint32_t microstrain_3dmgx2_imu::IMU::offset_ticks [private] |
double microstrain_3dmgx2_imu::IMU::P_time_est[2][2] [private] |
unsigned long long microstrain_3dmgx2_imu::IMU::start_time [private] |
double microstrain_3dmgx2_imu::IMU::sum_meas [private] |
const int microstrain_3dmgx2_imu::IMU::TICKS_PER_SEC_GX2 = 19660800 [static, private] |
const int microstrain_3dmgx2_imu::IMU::TICKS_PER_SEC_GX3 = 62500 [static, private] |
double microstrain_3dmgx2_imu::IMU::time_est[2] [private] |
uint32_t microstrain_3dmgx2_imu::IMU::wraps [private] |