vmu931
Library for Variense VMU931 IMU
 All Data Structures Files Functions Variables Enumerations Enumerator Groups Pages
vmu931.h
Go to the documentation of this file.
1 /*
2  * vmu931 library header
3  *
4  * Copyright 2018 (C) Bartosz Meglicki <meglickib@gmail.com>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9  *
10  */
11 
25 #ifndef VMU931_H_
26 #define VMU931_H_
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <stdint.h>
33 
43 struct vmu;
44 
50 struct vmu_tx
51 {
52  uint32_t timestamp_ms;
53  float x;
54 };
55 
61 struct vmu_txyz
62 {
63  uint32_t timestamp_ms;
64  float x;
65  float y;
66  float z;
67 };
68 
74 struct vmu_twxyz
75 {
76  uint32_t timestamp_ms;
77  float w;
78  float x;
79  float y;
80  float z;
81 };
82 
83 /* TEXT RELATED */
84 
85 enum {VMU_MAX_STRING_SIZE=255};
86 
95 struct vmu_text
96 {
97  char text[VMU_MAX_STRING_SIZE];
98 };
99 
100 /* STATUS RELATED */
101 
106 enum vmu_sensors_enum {VMU_SENSORS_ACCEL=0x01, VMU_SENSORS_GYRO=0x02, VMU_SENSORS_MAG=0x04};
107 
112 enum vmu_resolution_enum {VMU_RESOLUTION_ACCEL_2G=0x01, VMU_RESOLUTION_ACCEL_4G=0x02,
113  VMU_RESOLUTION_ACCEL_8G=0x04, VMU_RESOLUTION_ACCEL_16G=0x08,
114  VMU_RESOLUTION_GYRO_250DPS=0x10, VMU_RESOLUTION_GYRO_500DPS=0x20,
115  VMU_RESOLUTION_GYRO_1000DPS=0x40, VMU_RESOLUTION_GYRO_2000DPS=0x80};
116 
121 enum vmu_stream_enum { VMU_STREAM_ACCEL=0x01, VMU_STREAM_GYRO = 0x02, VMU_STREAM_QUAT=0x04,
122  VMU_STREAM_MAG=0x08, VMU_STREAM_EULER=0x10, VMU_STREAM_HEAD=0x40 };
123 
131 {
132  uint8_t sensors;
133  uint8_t resolution;
134  uint8_t low_rate;
135  uint32_t stream;
136 };
137 
144 struct vmu_size
145 {
146  int accel;
147  int gyro;
148  int mag;
149  int euler;
150  int quat;
151  int head;
152  int text;
153  int status;
154 };
155 
164 struct vmu_data
165 {
166  struct vmu_txyz *accel;
167  struct vmu_txyz *gyro;
168  struct vmu_txyz *mag;
169  struct vmu_txyz *euler;
170  struct vmu_twxyz *quat;
171  struct vmu_tx *head;
172  struct vmu_text *text;
173  struct vmu_status *status;
174 
175  struct vmu_size size; //array sizes
176 };
177 
183  VMU_OK=0,
185  };
186 
189 
205 struct vmu *vmu_init(const char *tty);
206 
224 int vmu_close(struct vmu *v);
225 
227 
262 
264 int vmu_accel(struct vmu *v, struct vmu_txyz *data, int size);
266 int vmu_gyro(struct vmu *v, struct vmu_txyz *data, int size);
268 int vmu_mag(struct vmu *v, struct vmu_txyz *data, int size);
270 int vmu_euler(struct vmu *v, struct vmu_txyz *data, int size);
272 int vmu_quat(struct vmu *v, struct vmu_twxyz *data, int size);
274 int vmu_head(struct vmu *v, struct vmu_tx *data, int size);
276 
301 int vmu_read_all(struct vmu *v, struct vmu_data *data);
302 
323 int vmu_stream(struct vmu *v, uint32_t stream);
324 
355 int vmu_resolution(struct vmu *v, uint32_t resolution);
356 
357 //commands
358 
374 int vmu_selftest(struct vmu *v, struct vmu_text *data);
375 
398 int vmu_calibrate(struct vmu *v, struct vmu_text *data);
399 
413 int vmu_status(struct vmu *v, struct vmu_status *data);
414 
424 int vmu_fd(struct vmu *v);
425 
430 #ifdef __cplusplus
431 }
432 #endif
433 
434 #endif //VMU931_H_
float w
between -1.0f and 1.0f
Definition: vmu931.h:77
int vmu_euler(struct vmu *v, struct vmu_txyz *data, int size)
Read only euler data.
Definition: vmu931.c:270
float x
between -1.0f and 1.0f
Definition: vmu931.h:78
float z
Euler [-180.0f, 180.0f], Mag [-4800.0f, 4800.0f], Accel and Gyro as resolution.
Definition: vmu931.h:66
error occured with errno set
Definition: vmu931.h:182
int vmu_fd(struct vmu *v)
Get file descriptor used for serial communication with the device.
Definition: vmu931.c:910
float z
between -1.0f and 1.0f
Definition: vmu931.h:80
vmu_retval_enum
Constants returned by most of library functions.
Definition: vmu931.h:181
float y
between -1.0f and 1.0f
Definition: vmu931.h:79
vmu_sensors_enum
Constants used for determining enabled sensors.
Definition: vmu931.h:106
int vmu_selftest(struct vmu *v, struct vmu_text *data)
Command device to perform selftest.
Definition: vmu931.c:744
int vmu_status(struct vmu *v, struct vmu_status *data)
Retrieve device status.
Definition: vmu931.c:819
vmu_resolution_enum
Constants used for determining and setting sensor resolution.
Definition: vmu931.h:112
float y
Euler [-90.0f, 90.0f], Mag [-4800.0f, 4800.0f], Accel and Gyro as resolution.
Definition: vmu931.h:65
Data streamed for Accelerometers, Gyroscopes, Magnetometers and Euler angles.
Definition: vmu931.h:61
uint32_t timestamp_ms
Miliseconds elapsed since device was plugged in.
Definition: vmu931.h:52
int vmu_gyro(struct vmu *v, struct vmu_txyz *data, int size)
Read only gyroscope data data.
Definition: vmu931.c:236
Internal library data passed around by the user.
Definition: vmu931.c:64
uint32_t stream
bitwise AND with vmu_stream_enum, e.g. stream & VMU_STREAM_EULER
Definition: vmu931.h:135
Array sizes for vmu_data arrays.
Definition: vmu931.h:144
int vmu_quat(struct vmu *v, struct vmu_twxyz *data, int size)
Read only quaternion data.
Definition: vmu931.c:287
Device status - enabled sensors, resolution, rate and streamed data.
Definition: vmu931.h:130
vmu_stream_enum
Constants used for setting and determining streamed data.
Definition: vmu931.h:121
Data streamed for Heading.
Definition: vmu931.h:50
uint32_t timestamp_ms
Miliseconds elapsed since device was plugged in.
Definition: vmu931.h:63
int vmu_close(struct vmu *v)
free library resources
Definition: vmu931.c:195
int vmu_read_all(struct vmu *v, struct vmu_data *data)
Read multiple types of data simultanously.
Definition: vmu931.c:321
uint8_t resolution
bitwise AND with vmu_resolution_enum, e.g. resolution & VMU_RESOLUTION_ACCEL_8G
Definition: vmu931.h:133
float x
Euler [-180.0f, 180.0f], Mag [-4800.0f, 4800.0f], Accel and Gyro as resolution.
Definition: vmu931.h:64
int vmu_resolution(struct vmu *v, uint32_t resolution)
Set accelerometer and/or gyroscope resolutions.
Definition: vmu931.c:644
int vmu_mag(struct vmu *v, struct vmu_txyz *data, int size)
Read only magnetometer data.
Definition: vmu931.c:253
Textual data returned by device and library.
Definition: vmu931.h:95
int vmu_head(struct vmu *v, struct vmu_tx *data, int size)
Read only heading data.
Definition: vmu931.c:304
uint32_t timestamp_ms
miliseconds elapsed since device was plugged in
Definition: vmu931.h:76
Data streamed for Quaternions.
Definition: vmu931.h:74
succesfull execution and more data pending without blocking
Definition: vmu931.h:184
uint8_t sensors
bitwise AND with vmu_sensors_enum, e.g. sensors & VMU_SENSORS_ACCEL
Definition: vmu931.h:132
struct vmu * vmu_init(const char *tty)
initialize internal library data.
Definition: vmu931.c:138
int vmu_stream(struct vmu *v, uint32_t stream)
Make the device stream particular data types.
Definition: vmu931.c:592
char text[VMU_MAX_STRING_SIZE]
'\0' terminated character data
Definition: vmu931.h:97
int vmu_calibrate(struct vmu *v, struct vmu_text *data)
Command device to perform calibration.
Definition: vmu931.c:762
float x
Between 0.0f and 360.0f degrees.
Definition: vmu931.h:53
succesfull execution
Definition: vmu931.h:183
int vmu_accel(struct vmu *v, struct vmu_txyz *data, int size)
Read only accelerometer data.
Definition: vmu931.c:219
uint8_t low_rate
0 for 1000 Hz, 1 for 200 Hz
Definition: vmu931.h:134
Structure with multiple types of data returned from the device.
Definition: vmu931.h:164