-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAcc.cpp
71 lines (59 loc) · 1.39 KB
/
Acc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "Acc.h"
using namespace myRIO;
extern NiFpga_Session myrio_session; // global variable defined in CAPI/MyRio.c
/**
* Constructs an Accelerometer.
* Set the scale to the default (1/256)
*/
Acc::Acc() :
scale(1.0/ACCSCALEWGHT_CST) {
}
/**
* Get the acceleration for an axis.
* @param type One of ACCXVAL, ACCYVAL or ACCZVAL
* @param v The return value, passed by reference
*/
void Acc::readAcc(int type, double &v) {
uint16_t temp;
status = NiFpga_ReadU16(myrio_session,
type,
&temp);
MyRio_ReturnIfNotSuccess(status,
"Could not read the accelerometer!");
// x is returned as an unsigned short, but is a signed short
v = ((int16_t)temp)*scale;
}
/**
* Read the accelerometer value on the x axis
* @param v The result is given by reference for speed
*/
void Acc::x(double &v) {
readAcc(ACCXVAL, v);
}
/**
* Read the accelerometer value on the y axis
* @param v The result is given by reference for speed
*/
void Acc::y(double &v) {
readAcc(ACCYVAL, v);
}
/**
* Read the accelerometer value on the z axis
* @param v The result is given by reference for speed
*/
void Acc::z(double &v) {
readAcc(ACCZVAL, v);
}
/**
* Read the accelerometer value on each axis
* @param vx Acceleration on x axis
* @param vy Acceleration on y axis
* @param vz Acceleration on z axis
*/
void Acc::all(double &vx, double &vy, double &vz) {
x(vx);
y(vy);
z(vz);
}
Acc::~Acc() {
}