vmu931
Library for Variense VMU931 IMU
 All Data Structures Files Functions Variables Enumerations Enumerator Groups Pages
Public interface

Data Structures

struct  vmu_tx
 Data streamed for Heading. More...
 
struct  vmu_txyz
 Data streamed for Accelerometers, Gyroscopes, Magnetometers and Euler angles. More...
 
struct  vmu_twxyz
 Data streamed for Quaternions. More...
 
struct  vmu_text
 Textual data returned by device and library. More...
 
struct  vmu_status
 Device status - enabled sensors, resolution, rate and streamed data. More...
 
struct  vmu_size
 Array sizes for vmu_data arrays. More...
 
struct  vmu_data
 Structure with multiple types of data returned from the device. More...
 
struct  vmu
 Internal library data passed around by the user. More...
 

Enumerations

enum  { VMU_MAX_STRING_SIZE =255 }
 
enum  vmu_sensors_enum { VMU_SENSORS_ACCEL =0x01, VMU_SENSORS_GYRO =0x02, VMU_SENSORS_MAG =0x04 }
 Constants used for determining enabled sensors. More...
 
enum  vmu_resolution_enum {
  VMU_RESOLUTION_ACCEL_2G =0x01, VMU_RESOLUTION_ACCEL_4G =0x02, VMU_RESOLUTION_ACCEL_8G =0x04, VMU_RESOLUTION_ACCEL_16G =0x08,
  VMU_RESOLUTION_GYRO_250DPS =0x10, VMU_RESOLUTION_GYRO_500DPS =0x20, VMU_RESOLUTION_GYRO_1000DPS =0x40, VMU_RESOLUTION_GYRO_2000DPS =0x80
}
 Constants used for determining and setting sensor resolution. More...
 
enum  vmu_stream_enum {
  VMU_STREAM_ACCEL =0x01, VMU_STREAM_GYRO = 0x02, VMU_STREAM_QUAT =0x04, VMU_STREAM_MAG =0x08,
  VMU_STREAM_EULER =0x10, VMU_STREAM_HEAD =0x40
}
 Constants used for setting and determining streamed data. More...
 
enum  vmu_retval_enum { VMU_ERROR =-1, VMU_OK =0, VMU_DATA_PENDING =1 }
 Constants returned by most of library functions. More...
 

Functions

int vmu_read_all (struct vmu *v, struct vmu_data *data)
 Read multiple types of data simultanously. More...
 
int vmu_stream (struct vmu *v, uint32_t stream)
 Make the device stream particular data types. More...
 
int vmu_resolution (struct vmu *v, uint32_t resolution)
 Set accelerometer and/or gyroscope resolutions. More...
 
int vmu_selftest (struct vmu *v, struct vmu_text *data)
 Command device to perform selftest. More...
 
int vmu_calibrate (struct vmu *v, struct vmu_text *data)
 Command device to perform calibration. More...
 
int vmu_status (struct vmu *v, struct vmu_status *data)
 Retrieve device status. More...
 
int vmu_fd (struct vmu *v)
 Get file descriptor used for serial communication with the device. More...
 

Init and teardown

struct vmuvmu_init (const char *tty)
 initialize internal library data. More...
 
int vmu_close (struct vmu *v)
 free library resources More...
 

Convinient read

Simplified read functions for single type of data (e.g. only euler). If you need to read multiple types of data use vmu_read_all instead.

Functions will block waiting for data unless last call returned value > size. Timeout with return value VMU_ERROR and errno EAGAIN indicates device is not sending data type for some reason.

Other data types are discarded silently without parsing.

Perfomance hints:

  • use vmu_stream so that device streams only data you need
Parameters
vpointer to internal library data
datauser supplied array
sizeuser supplied array size
Returns
  • value > size indicates user array was filled and more data is pending (without blocking)
  • value <= size indicates number of data points returned in array (next call will block)
  • VMU_ERROR indicates error, query errno for the details
See Also
vmu_stream, vmu_read_all

Example:

int status, i;
struct vmu_txyz euler[10];
while( (status=vmu_euler(v, euler, 10)) != VMU_ERROR )
{
for(i=0; i<status && i<10; ++i)
printf("[%lu ms] x=%f y=%f z=%f\n", euler[i].timeout_ms, euler[i].x, euler[i].y, euler[i].z);
}
int vmu_accel (struct vmu *v, struct vmu_txyz *data, int size)
 Read only accelerometer data.
 
int vmu_gyro (struct vmu *v, struct vmu_txyz *data, int size)
 Read only gyroscope data data.
 
int vmu_mag (struct vmu *v, struct vmu_txyz *data, int size)
 Read only magnetometer data.
 
int vmu_euler (struct vmu *v, struct vmu_txyz *data, int size)
 Read only euler data.
 
int vmu_quat (struct vmu *v, struct vmu_twxyz *data, int size)
 Read only quaternion data.
 
int vmu_head (struct vmu *v, struct vmu_tx *data, int size)
 Read only heading data.
 

Detailed Description

Enumeration Type Documentation

Constants used for determining and setting sensor resolution.

See Also
vmu_status, vmu_resolution

Constants returned by most of library functions.

Enumerator
VMU_ERROR 

error occured with errno set

VMU_OK 

succesfull execution

VMU_DATA_PENDING 

succesfull execution and more data pending without blocking

Constants used for determining enabled sensors.

See Also
vmu_status

Constants used for setting and determining streamed data.

See Also
vmu_stream, vmu_status

Function Documentation

int vmu_calibrate ( struct vmu v,
struct vmu_text data 
)

Command device to perform calibration.

Blocks for around 4 seconds while device performs calibration. All textual data output by the device is concatenated in data argument. All non-textual data is discarded during the process. The device needs to remain still on a flat surface with its Z-axis pointing upward during the process. You don't have to repeat this procedure every time you power on the sensor.

Note - there is undocummented (VMU User Guide 1.3) magnetometer calibration procedure. Magnetometer calibration is essential to reduce drift on Z (heading) axis. While powering up the sensor move it around in multiple orientations. Do it until the Euler angles indicates 0 degrees while the sensor has its Y axis pointing North. As of firmware 1.01 this has to be repeated every time you power on the sensor.

Parameters
vpointer to internal library data
dataargument filled with textual data
Returns
  • VMU_OK if calibration succeded, query data for the details
  • VMU_ERROR on IO error, calibration failure or timeout, query data and errno for the details
int vmu_close ( struct vmu v)

free library resources

Frees memory and restores terminal settings.

May be safely called with NULL argument.

Parameters
vpointer to internal library data
Returns
  • VMU_OK on success
  • VMU_ERROR on error, query errno for the details

Example:

int vmu_fd ( struct vmu v)

Get file descriptor used for serial communication with the device.

Library user should not directly read or write from or to descriptor. This function is intended to be used in synchronous I/O multiplexing (select, poll).

Parameters
vpointer to internal library data
Returns
file descriptor
struct vmu* vmu_init ( const char *  tty)

initialize internal library data.

Parameters
ttydevice like "/dev/ttyACM0"
Returns
  • pointer to internal library data
  • NULL on error with errno set
See Also
vmu_close

Example:

struct vmu *v=vmu_init("/dev/ttyACM0");
int vmu_read_all ( struct vmu v,
struct vmu_data data 
)

Read multiple types of data simultanously.

Use this function if you need to read multiple types of data (e.g. euler and magnetometer).

If you care only about single data type use one of convinience functions instead.

Function will block waiting for data unless last call returned VMU_DATA_PENDING. Timeout with return value VMU_ERROR and errno EAGAIN indicates device is not sending data types for some reason.

Data types with 0 size in data parameter are discarded silently without parsing.

Perfomance hints:

  • use vmu_stream so that device streams only data you need
Parameters
vpointer to internal library data
datauser supplied arrays with sizes
Returns
  • VMU_OK indicates user arrays in data parameter were filled
  • VMU_DATA_PENDING indicates at least one array in data parameter was filled completely and more data is pending (without blocking)
  • VMU_ERROR indicates error, query errno for the details
See Also
vmu_stream, vmu_accel, vmu_gyro, vmu_mag, vmu_euler, vmu_quat, vmu_head
int vmu_resolution ( struct vmu v,
uint32_t  resolution 
)

Set accelerometer and/or gyroscope resolutions.

Blocks until resolution is set, error or timeout occurs.

Streaming Heading, Euler or Quaternion data forces:

  • 2000 dps for gyroscope
  • 2g for accelerometer

It setting resolution only for accelerometer or gyroscope the second remains unchanged.

errno values:

  • EINVAL if resolution argument is not sane
  • ENOTSUP if requested incompatible resolution while streaming Heading, Euler or Quaternion data
  • EAGAIN if timeout occured during communication with the device
  • other IO specific errno values are possible
Parameters
vpointer to internal library data
resolutionlogical combination of vmu_resolution_enum values
Returns
  • VMU_OK if setting resolution succeded
  • VMU_ERROR on IO error or invalid resolution argument, query errno for the details
See Also
vmu_resolution_enum

Example:

vmu_resolution(v, VMU_RESOLUTION_ACCEL_16G | VMU_RESOLUTION_GYRO_1000DPS);
int vmu_selftest ( struct vmu v,
struct vmu_text data 
)

Command device to perform selftest.

Blocks for around 2 seconds while device performs selftest. All textual data output by the device is concatenated in data argument. All non-textual data is discarded during the process.

The device needs to remain still on a flat surface with its Z-axis pointing upward during the process.

Parameters
vpointer to internal library data
dataargument filled with textual data
Returns
  • VMU_OK if selftest succeded, query data for the details
  • VMU_ERROR on IO error, selftest failure or timeout, query data and errno for the details
int vmu_status ( struct vmu v,
struct vmu_status data 
)

Retrieve device status.

Blocks until device returns status, error or timeout occurs.

Non status data types are discarded while waiting for device status.

Parameters
vpointer to internal library data
dataargument filled with status data
Returns
  • VMU_OK on success
  • VMU_ERROR on failure, query errno for the details
int vmu_stream ( struct vmu v,
uint32_t  stream 
)

Make the device stream particular data types.

Function blocks until one of:

  • new streaming parameters are set
  • error occurs (including timeout with errno EAGAIN)
Parameters
vpointer to internal library data
streamlogical sum of values from vmu_stream_enum
Returns
  • VMU_OK indicates device will stream requested data types
  • VMU_ERROR indicates error, query errno for the details
See Also
vmu_stream_enum

Example:

vmu_stream(v, VMU_STREAM_EULER | VMU_STREAM_MAG);