-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOrientation.ino
More file actions
70 lines (53 loc) · 1.5 KB
/
Copy pathOrientation.ino
File metadata and controls
70 lines (53 loc) · 1.5 KB
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
// This file contains methods used to compute screen coordinates from sensor input.
#include <EEPROM.h>
#include "DCM.h"
#define EADR 0x00
#define eepr_magic 0xB00B
DCM dcm;
uint32_t noMotionCount;
// This is used to somewhat compensate for the IR sensor not pivoting exactly on it's axis.
// Normally, you hold the gun in your hand, so the IR sensor will be at about an arm's length
// from the pivot point.
float irHeadingRatio = 1.0f;
void loadScreenCalib()
{
uint32_t eepr_test;
EEPROM.get(EADR + 0, eepr_test);
if (eepr_test == eepr_magic)
{
EEPROM.get(EADR + 4, centerHeading);
EEPROM.get(EADR + 8, centerPitch);
EEPROM.get(EADR + 12, rangeHeading);
EEPROM.get(EADR + 16, rangePitch);
}
}
void saveScreenCalib()
{
EEPROM.put(EADR + 4, centerHeading);
EEPROM.put(EADR + 8, centerPitch);
EEPROM.put(EADR + 12, rangeHeading);
EEPROM.put(EADR + 16, rangePitch);
EEPROM.put(EADR + 0, eepr_magic);
}
bool initOrientation()
{
loadScreenCalib();
return true; //that's what I call a robust initializer
}
void updateOrientation()
{
dcm.update(gx, gy, gz, ax, ay, az, irHeading * irHeadingRatio, irPitch, irConfidence);
heading = dcm.yaw * irHeadingRatio;
pitch = dcm.pitch;
roll = dcm.roll;
if (!active && irConfidence > 0.75f) active = true;
else {
if (!dcm.motion) {
noMotionCount++;
if (noMotionCount >= 128) active = false;
}
else {
noMotionCount = 0;
}
}
}