-
Notifications
You must be signed in to change notification settings - Fork 0
/
_gyro_8cpp_source.html
136 lines (134 loc) · 40.4 KB
/
_gyro_8cpp_source.html
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>myWRIO: C:/Users/jackb/OneDrive - etu.univ-lyon1.fr/TERi/Eclipse/workspace/APIForRIO/src/Gyro.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">myWRIO
</div>
<div id="projectbrief">C++ framework for NationalInstruments myRIO</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_gyro_8cpp_source.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="headertitle">
<div class="title">Gyro.cpp</div> </div>
</div><!--header-->
<div class="contents">
<a href="_gyro_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="preprocessor">#include "<a class="code" href="_gyro_8h.html">Gyro.h</a>"</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> </div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="keyword">using namespace </span><a class="code" href="namespacemy_r_i_o.html">myRIO</a>;</div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="keyword">using namespace </span>GyroRegisters;</div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> </div><div class="line"><a name="l00009"></a><span class="lineno"><a class="line" href="classmy_r_i_o_1_1_gyro.html#a8ff2fdb2417c677f4694fa23fc0ce6da"> 9</a></span> <a class="code" href="classmy_r_i_o_1_1_gyro.html#a8ff2fdb2417c677f4694fa23fc0ce6da">Gyro::Gyro</a>() : regs(new uint8_t[6]), gyroStatusVal(0), xOff(0), yOff(0), zOff(0), th(nullptr), run(new bool) {</div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span>  <a class="code" href="classmy_r_i_o_1_1_gyro.html#ad782b97fd2a5438f04eb098be47dc5d8">gyro</a> = <a class="code" href="classmy_r_i_o_1_1_i2_c.html#af38bb693bc9c445ca675faeb9bacd6ee">I2C::open</a>()-><a class="code" href="classmy_r_i_o_1_1_i2_c.html#a46c2a82b1a8146fc6b4a688a82a0970d">slave</a>(0b11010010);</div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> </div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span>  uint8_t ad = 0;</div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span>  <a class="code" href="classmy_r_i_o_1_1_gyro.html#ad782b97fd2a5438f04eb098be47dc5d8">gyro</a>-><a class="code" href="classmy_r_i_o_1_1_i2_c.html#a0885faa777f4c62e70979c84d5133090">read</a>(<a class="code" href="namespacemy_r_i_o_1_1_gyro_registers.html#a527b412376904baaea708aecf4a20924">L3G4200D_WHO_AM_I</a>, &ad);</div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span>  <span class="keywordflow">if</span>(ad!=0b11010011) {</div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span>  <a class="code" href="namespacemy_r_i_o.html#a4a95a51adb92d1bfede6144d499c1cff">status</a> = -1;</div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span>  <span class="keywordflow">return</span>;</div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span>  }</div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> </div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span>  <span class="keywordflow">if</span>(!<a class="code" href="classmy_r_i_o_1_1_gyro.html#ad782b97fd2a5438f04eb098be47dc5d8">gyro</a>-><a class="code" href="classmy_r_i_o_1_1_i2_c.html#a17cbf8d61e1ecaf6dc21a2aa0def1f27">write</a>(<a class="code" href="namespacemy_r_i_o_1_1_gyro_registers.html#ac31c5e5a0a125a8407e600f8f234f69b">L3G4200D_CTRL_REG1</a>,</div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span>  0b00<<6 | <span class="comment">// DR<1:0> : data rate</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span>  0b00<<4 | <span class="comment">// BW<1:0> : bandwidth</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span>  0b1111) <span class="comment">// power mode : normal, X/Y/Z enabled</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span>  ||!<a class="code" href="classmy_r_i_o_1_1_gyro.html#ad782b97fd2a5438f04eb098be47dc5d8">gyro</a>-><a class="code" href="classmy_r_i_o_1_1_i2_c.html#a17cbf8d61e1ecaf6dc21a2aa0def1f27">write</a>(<a class="code" href="namespacemy_r_i_o_1_1_gyro_registers.html#ab10f36b188796cfe13e850f1051ae89c">L3G4200D_CTRL_REG5</a>,0x80)) <span class="comment">// 250dps : 8.75mdps/LSB</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span>  <a class="code" href="namespacemy_r_i_o.html#a4a95a51adb92d1bfede6144d499c1cff">status</a> = -1;</div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> }</div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> </div><div class="line"><a name="l00032"></a><span class="lineno"><a class="line" href="classmy_r_i_o_1_1_gyro.html#ac7186293f827c8c5a91bec9048bf1b7f"> 32</a></span> <span class="keywordtype">void</span> <a class="code" href="classmy_r_i_o_1_1_gyro.html#ac7186293f827c8c5a91bec9048bf1b7f">Gyro::calibrate</a>(<span class="keywordtype">short</span> samples) {</div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span>  <span class="keywordtype">double</span> x[samples], y[samples], z[samples];</div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> </div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span>  <a class="code" href="classmy_r_i_o_1_1_time.html">Time</a> t = <a class="code" href="classmy_r_i_o_1_1_time.html#a92732a8e1b40acc9735440b3996cda51">Time::stopwatch</a>();</div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> </div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>  <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i<samples; i++) {</div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span>  <span class="keywordflow">while</span>(!<a class="code" href="classmy_r_i_o_1_1_gyro.html#ae5465f4d912d9e2d266be2658d1ade0f">gyroStatusVal</a>&(1<<3)) {</div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>  <span class="keywordflow">if</span>(!<a class="code" href="classmy_r_i_o_1_1_gyro.html#ad782b97fd2a5438f04eb098be47dc5d8">gyro</a>-><a class="code" href="classmy_r_i_o_1_1_i2_c.html#a0885faa777f4c62e70979c84d5133090">read</a>(<a class="code" href="namespacemy_r_i_o_1_1_gyro_registers.html#a7c670ca0062f1cc0c00fc8eb9ee7196c">L3G4200D_STATUS_REG</a>, &<a class="code" href="classmy_r_i_o_1_1_gyro.html#ae5465f4d912d9e2d266be2658d1ade0f">gyroStatusVal</a>) || <a class="code" href="namespacemy_r_i_o.html#a4a95a51adb92d1bfede6144d499c1cff">status</a>!=0) {</div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>  <a class="code" href="namespacemy_r_i_o.html#a4a95a51adb92d1bfede6144d499c1cff">status</a> = -1;</div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>  <span class="keywordflow">return</span>;</div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>  }</div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  }</div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>  <a class="code" href="classmy_r_i_o_1_1_gyro.html#abfb7a8963eea0c13dd7278f55e5ee884">readGyro</a>(x[i], y[i], z[i]);</div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span>  }</div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span> </div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> elapsed = t.<a class="code" href="classmy_r_i_o_1_1_time.html#a35a43f1d728b65aecc047c48691dc317">elapsed_ns</a>();</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span> </div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  std::cout << std::endl << <span class="stringliteral">"Elapsed : "</span> << elapsed << <span class="stringliteral">" us, which is "</span> << elapsed/samples << <span class="stringliteral">" us per sample, or"</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  <span class="stringliteral">" a fq of "</span> << 1.0e9/(1.*elapsed/samples) << <span class="stringliteral">" Hz"</span> << std::endl << std::endl;</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span> </div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span> </div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i<samples; i++) {</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>  <a class="code" href="classmy_r_i_o_1_1_gyro.html#a3daeedc2b8243087bf825c6fde5a138c">xOff</a>+=x[i];</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  <a class="code" href="classmy_r_i_o_1_1_gyro.html#ae673ba32f3762cd3429532c76f1de591">yOff</a>+=y[i];</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  <a class="code" href="classmy_r_i_o_1_1_gyro.html#aa9bf1d1c4459f25e973b58166876c431">zOff</a>+=z[i];</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  }</div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span> </div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  <a class="code" href="classmy_r_i_o_1_1_gyro.html#a3daeedc2b8243087bf825c6fde5a138c">xOff</a>/=samples;</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  <a class="code" href="classmy_r_i_o_1_1_gyro.html#ae673ba32f3762cd3429532c76f1de591">yOff</a>/=samples;</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  <a class="code" href="classmy_r_i_o_1_1_gyro.html#aa9bf1d1c4459f25e973b58166876c431">zOff</a>/=samples;</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span> }</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span> </div><div class="line"><a name="l00070"></a><span class="lineno"><a class="line" href="classmy_r_i_o_1_1_gyro.html#abfb7a8963eea0c13dd7278f55e5ee884"> 70</a></span> <span class="keywordtype">void</span> <a class="code" href="classmy_r_i_o_1_1_gyro.html#abfb7a8963eea0c13dd7278f55e5ee884">Gyro::readGyro</a>(<span class="keywordtype">double</span>&vx, <span class="keywordtype">double</span>&vy, <span class="keywordtype">double</span>&vz) {</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  <a class="code" href="classmy_r_i_o_1_1_gyro.html#ae5465f4d912d9e2d266be2658d1ade0f">gyroStatusVal</a> = 0;</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span> </div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  <span class="keywordflow">if</span>(!<a class="code" href="classmy_r_i_o_1_1_gyro.html#ad782b97fd2a5438f04eb098be47dc5d8">gyro</a>-><a class="code" href="classmy_r_i_o_1_1_i2_c.html#a3067e3c1553f3b0a8d17c5ab9807d5db">readFrom</a>(<a class="code" href="namespacemy_r_i_o_1_1_gyro_registers.html#adb2e0d9d2a77d779853c894a982e7fc1">L3G4200D_OUT_X_L</a>, <a class="code" href="classmy_r_i_o_1_1_gyro.html#ac797934d5520bf12ba5e40cc1cae51c7">regs</a>, 6) || <a class="code" href="namespacemy_r_i_o.html#a4a95a51adb92d1bfede6144d499c1cff">status</a> != 0) {</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  <a class="code" href="namespacemy_r_i_o.html#a4a95a51adb92d1bfede6144d499c1cff">status</a> = -1;</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  <span class="keywordflow">return</span>;</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  }</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span> </div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  vx = (short)((<a class="code" href="classmy_r_i_o_1_1_gyro.html#ac797934d5520bf12ba5e40cc1cae51c7">regs</a>[1]<<8) | <a class="code" href="classmy_r_i_o_1_1_gyro.html#ac797934d5520bf12ba5e40cc1cae51c7">regs</a>[0]);</div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  vx*=0.00875;</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  vx-=<a class="code" href="classmy_r_i_o_1_1_gyro.html#a3daeedc2b8243087bf825c6fde5a138c">xOff</a>;</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span> </div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  vy = (short)((<a class="code" href="classmy_r_i_o_1_1_gyro.html#ac797934d5520bf12ba5e40cc1cae51c7">regs</a>[3]<<8) | <a class="code" href="classmy_r_i_o_1_1_gyro.html#ac797934d5520bf12ba5e40cc1cae51c7">regs</a>[2]);</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  vy*=0.00875;</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  vy-=<a class="code" href="classmy_r_i_o_1_1_gyro.html#ae673ba32f3762cd3429532c76f1de591">yOff</a>;</div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span> </div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  vz = (short)((<a class="code" href="classmy_r_i_o_1_1_gyro.html#ac797934d5520bf12ba5e40cc1cae51c7">regs</a>[5]<<8) | <a class="code" href="classmy_r_i_o_1_1_gyro.html#ac797934d5520bf12ba5e40cc1cae51c7">regs</a>[4]);</div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  vz*=0.00875;</div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  vz-=<a class="code" href="classmy_r_i_o_1_1_gyro.html#aa9bf1d1c4459f25e973b58166876c431">zOff</a>;</div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span> }</div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span> </div><div class="line"><a name="l00095"></a><span class="lineno"><a class="line" href="classmy_r_i_o_1_1_gyro.html#a068f42293e1363c51a8a59d08b71168b"> 95</a></span> <span class="keywordtype">void</span> <a class="code" href="classmy_r_i_o_1_1_gyro.html#a068f42293e1363c51a8a59d08b71168b">Gyro::startFreeRunningMode</a>(std::function<<span class="keywordtype">void</span>(<span class="keywordtype">double</span>&, <span class="keywordtype">double</span>&)> func) {</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  *<a class="code" href="classmy_r_i_o_1_1_gyro.html#ab352d6a42edb7425fc17a990db5755c9">run</a> = <span class="keyword">true</span>;</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span> </div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  <span class="keywordflow">if</span>(<a class="code" href="classmy_r_i_o_1_1_gyro.html#a0f8555f6d90f64e13802f2376ab434dd">th</a>!=<span class="keyword">nullptr</span>) <span class="keyword">delete</span> <a class="code" href="classmy_r_i_o_1_1_gyro.html#a0f8555f6d90f64e13802f2376ab434dd">th</a>;</div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span> </div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <a class="code" href="classmy_r_i_o_1_1_gyro.html#a0f8555f6d90f64e13802f2376ab434dd">th</a> = <span class="keyword">new</span> std::thread([<span class="keyword">this</span>, func](<span class="keywordtype">bool</span>* running) {</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  <a class="code" href="classmy_r_i_o_1_1_time.html">Time</a> stopwatch = <a class="code" href="classmy_r_i_o_1_1_time.html#a92732a8e1b40acc9735440b3996cda51">Time::stopwatch</a>();</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  <span class="keywordtype">double</span> vx, oldvx = 0, dt;</div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  <span class="keywordflow">while</span>(*<a class="code" href="classmy_r_i_o_1_1_gyro.html#ab352d6a42edb7425fc17a990db5755c9">run</a>) {</div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  <span class="comment">// wait for new data on the gyro</span></div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  <span class="keywordflow">while</span>(!<a class="code" href="classmy_r_i_o_1_1_gyro.html#ae5465f4d912d9e2d266be2658d1ade0f">gyroStatusVal</a>&(1<<3)) {</div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  <span class="keywordflow">if</span>(!<a class="code" href="classmy_r_i_o_1_1_gyro.html#ad782b97fd2a5438f04eb098be47dc5d8">gyro</a>-><a class="code" href="classmy_r_i_o_1_1_i2_c.html#a0885faa777f4c62e70979c84d5133090">read</a>(<a class="code" href="namespacemy_r_i_o_1_1_gyro_registers.html#a7c670ca0062f1cc0c00fc8eb9ee7196c">L3G4200D_STATUS_REG</a>, &<a class="code" href="classmy_r_i_o_1_1_gyro.html#ae5465f4d912d9e2d266be2658d1ade0f">gyroStatusVal</a>) || <a class="code" href="namespacemy_r_i_o.html#a4a95a51adb92d1bfede6144d499c1cff">status</a>!=0) {</div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span>  <a class="code" href="namespacemy_r_i_o.html#a4a95a51adb92d1bfede6144d499c1cff">status</a> = -1;</div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  printf(<span class="stringliteral">"Gyro - Error\n"</span>);</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="keywordflow">return</span>;</div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  }</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  }</div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span> </div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  <span class="comment">// read that new data</span></div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  <span class="keywordflow">if</span>(!<a class="code" href="classmy_r_i_o_1_1_gyro.html#ad782b97fd2a5438f04eb098be47dc5d8">gyro</a>-><a class="code" href="classmy_r_i_o_1_1_i2_c.html#a3067e3c1553f3b0a8d17c5ab9807d5db">readFrom</a>(<a class="code" href="namespacemy_r_i_o_1_1_gyro_registers.html#adb2e0d9d2a77d779853c894a982e7fc1">L3G4200D_OUT_X_L</a>, <a class="code" href="classmy_r_i_o_1_1_gyro.html#ac797934d5520bf12ba5e40cc1cae51c7">regs</a>, 2) || <a class="code" href="namespacemy_r_i_o.html#a4a95a51adb92d1bfede6144d499c1cff">status</a> != 0) {</div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  <a class="code" href="namespacemy_r_i_o.html#a4a95a51adb92d1bfede6144d499c1cff">status</a> = -1;</div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  printf(<span class="stringliteral">"Gyro - Error\n"</span>);</div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  <span class="keywordflow">return</span>;</div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  }</div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span> </div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  <span class="comment">// registers are L_H, we need it H_L</span></div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  vx = (short)((<a class="code" href="classmy_r_i_o_1_1_gyro.html#ac797934d5520bf12ba5e40cc1cae51c7">regs</a>[1]<<8) | <a class="code" href="classmy_r_i_o_1_1_gyro.html#ac797934d5520bf12ba5e40cc1cae51c7">regs</a>[0]);</div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  <span class="comment">// 250dps sensitivity</span></div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  vx*=0.00875;</div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span>  <span class="comment">// remove the offset</span></div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span>  vx-=<a class="code" href="classmy_r_i_o_1_1_gyro.html#a3daeedc2b8243087bf825c6fde5a138c">xOff</a>;</div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span> </div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span>  <span class="comment">// do not trust too much that value</span></div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  vx = vx*0.3 + oldvx*0.7;</div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span>  oldvx = vx;</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  </div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  dt = stopwatch.<a class="code" href="classmy_r_i_o_1_1_time.html#a35a43f1d728b65aecc047c48691dc317">elapsed_ns</a>() * 1e-9;</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span> </div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  func(vx, dt);</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span> </div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  stopwatch.<a class="code" href="classmy_r_i_o_1_1_time.html#afe661f7ba15818a24bf76e83da2889a0">reset</a>();</div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  }</div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span>  }, std::ref(<a class="code" href="classmy_r_i_o_1_1_gyro.html#ab352d6a42edb7425fc17a990db5755c9">run</a>));</div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span>  <a class="code" href="classmy_r_i_o_1_1_gyro.html#a0f8555f6d90f64e13802f2376ab434dd">th</a>->detach();</div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span> }</div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span> </div><div class="line"><a name="l00144"></a><span class="lineno"><a class="line" href="classmy_r_i_o_1_1_gyro.html#ab9c4dc9bdc1e8ce2302347653fc467e2"> 144</a></span> <span class="keywordtype">void</span> <a class="code" href="classmy_r_i_o_1_1_gyro.html#ab9c4dc9bdc1e8ce2302347653fc467e2">Gyro::stopFreeRunningMode</a>() {</div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  *<a class="code" href="classmy_r_i_o_1_1_gyro.html#ab352d6a42edb7425fc17a990db5755c9">run</a> = <span class="keyword">false</span>;</div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span> }</div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span> </div><div class="line"><a name="l00151"></a><span class="lineno"><a class="line" href="classmy_r_i_o_1_1_gyro.html#af58b57914897b22014110908326eace2"> 151</a></span> <a class="code" href="classmy_r_i_o_1_1_gyro.html#af58b57914897b22014110908326eace2">Gyro::~Gyro</a>() {</div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span>  <span class="keywordflow">if</span>(*<a class="code" href="classmy_r_i_o_1_1_gyro.html#ab352d6a42edb7425fc17a990db5755c9">run</a>)</div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  *<a class="code" href="classmy_r_i_o_1_1_gyro.html#ab352d6a42edb7425fc17a990db5755c9">run</a> = <span class="keyword">false</span>;</div><div class="line"><a name="l00154"></a><span class="lineno"> 154</span>  <span class="keyword">delete</span> [] <a class="code" href="classmy_r_i_o_1_1_gyro.html#ac797934d5520bf12ba5e40cc1cae51c7">regs</a>;</div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span> }</div><div class="ttc" id="_gyro_8h_html"><div class="ttname"><a href="_gyro_8h.html">Gyro.h</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_time_html_a35a43f1d728b65aecc047c48691dc317"><div class="ttname"><a href="classmy_r_i_o_1_1_time.html#a35a43f1d728b65aecc047c48691dc317">myRIO::Time::elapsed_ns</a></div><div class="ttdeci">long elapsed_ns()</div><div class="ttdoc">Elapsed time nanoseconds If you get elapsed_ns() = 1000, 1000ns are elapsed, or 1000e-9 seconds WARNI...</div><div class="ttdef"><b>Definition:</b> <a href="_time_8cpp_source.html#l00034">Time.cpp:34</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_a8ff2fdb2417c677f4694fa23fc0ce6da"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#a8ff2fdb2417c677f4694fa23fc0ce6da">myRIO::Gyro::Gyro</a></div><div class="ttdeci">Gyro()</div><div class="ttdoc">Constructs a helper for sensor L3G4200D.</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8cpp_source.html#l00009">Gyro.cpp:9</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_ac797934d5520bf12ba5e40cc1cae51c7"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#ac797934d5520bf12ba5e40cc1cae51c7">myRIO::Gyro::regs</a></div><div class="ttdeci">uint8_t * regs</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8h_source.html#l00049">Gyro.h:49</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_i2_c_html_a46c2a82b1a8146fc6b4a688a82a0970d"><div class="ttname"><a href="classmy_r_i_o_1_1_i2_c.html#a46c2a82b1a8146fc6b4a688a82a0970d">myRIO::I2C::slave</a></div><div class="ttdeci">I2C * slave(uint8_t addr)</div><div class="ttdoc">Set the slave address to talk to.</div><div class="ttdef"><b>Definition:</b> <a href="_i2_c_8cpp_source.html#l00041">I2C.cpp:41</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_ac7186293f827c8c5a91bec9048bf1b7f"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#ac7186293f827c8c5a91bec9048bf1b7f">myRIO::Gyro::calibrate</a></div><div class="ttdeci">void calibrate(short samples=100)</div><div class="ttdoc">Compute the offset from error of the last X samples The gyro must be on a plane surface.</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8cpp_source.html#l00032">Gyro.cpp:32</a></div></div>
<div class="ttc" id="namespacemy_r_i_o_1_1_gyro_registers_html_a7c670ca0062f1cc0c00fc8eb9ee7196c"><div class="ttname"><a href="namespacemy_r_i_o_1_1_gyro_registers.html#a7c670ca0062f1cc0c00fc8eb9ee7196c">myRIO::GyroRegisters::L3G4200D_STATUS_REG</a></div><div class="ttdeci">constexpr uint8_t L3G4200D_STATUS_REG</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8h_source.html#l00025">Gyro.h:25</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_i2_c_html_a3067e3c1553f3b0a8d17c5ab9807d5db"><div class="ttname"><a href="classmy_r_i_o_1_1_i2_c.html#a3067e3c1553f3b0a8d17c5ab9807d5db">myRIO::I2C::readFrom</a></div><div class="ttdeci">bool readFrom(uint8_t reg, uint8_t *data, uint8_t dataSize)</div><div class="ttdoc">Read multiple registers, starting to reg.</div><div class="ttdef"><b>Definition:</b> <a href="_i2_c_8cpp_source.html#l00080">I2C.cpp:80</a></div></div>
<div class="ttc" id="namespacemy_r_i_o_html_a4a95a51adb92d1bfede6144d499c1cff"><div class="ttname"><a href="namespacemy_r_i_o.html#a4a95a51adb92d1bfede6144d499c1cff">myRIO::status</a></div><div class="ttdeci">static NiFpga_Status status</div><div class="ttdoc">This global variable allow the user to keep track of errors if not 0.</div><div class="ttdef"><b>Definition:</b> <a href="_my_r_i_o_8h_source.html#l00030">MyRIO.h:30</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_i2_c_html_af38bb693bc9c445ca675faeb9bacd6ee"><div class="ttname"><a href="classmy_r_i_o_1_1_i2_c.html#af38bb693bc9c445ca675faeb9bacd6ee">myRIO::I2C::open</a></div><div class="ttdeci">static I2C * open()</div><div class="ttdoc">You can use this to open multiple I2C channels, for exemple use I2CB.</div><div class="ttdef"><b>Definition:</b> <a href="_i2_c_8cpp_source.html#l00030">I2C.cpp:30</a></div></div>
<div class="ttc" id="namespacemy_r_i_o_1_1_gyro_registers_html_adb2e0d9d2a77d779853c894a982e7fc1"><div class="ttname"><a href="namespacemy_r_i_o_1_1_gyro_registers.html#adb2e0d9d2a77d779853c894a982e7fc1">myRIO::GyroRegisters::L3G4200D_OUT_X_L</a></div><div class="ttdeci">constexpr uint8_t L3G4200D_OUT_X_L</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8h_source.html#l00026">Gyro.h:26</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_time_html_a92732a8e1b40acc9735440b3996cda51"><div class="ttname"><a href="classmy_r_i_o_1_1_time.html#a92732a8e1b40acc9735440b3996cda51">myRIO::Time::stopwatch</a></div><div class="ttdeci">static Time stopwatch()</div><div class="ttdoc">Get the current time.</div><div class="ttdef"><b>Definition:</b> <a href="_time_8cpp_source.html#l00012">Time.cpp:12</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_abfb7a8963eea0c13dd7278f55e5ee884"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#abfb7a8963eea0c13dd7278f55e5ee884">myRIO::Gyro::readGyro</a></div><div class="ttdeci">void readGyro(double &vx, double &vy, double &vz)</div><div class="ttdoc">Read all X, Y and Z values from the gyro registers.</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8cpp_source.html#l00070">Gyro.cpp:70</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_ae673ba32f3762cd3429532c76f1de591"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#ae673ba32f3762cd3429532c76f1de591">myRIO::Gyro::yOff</a></div><div class="ttdeci">double yOff</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8h_source.html#l00052">Gyro.h:52</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_time_html"><div class="ttname"><a href="classmy_r_i_o_1_1_time.html">myRIO::Time</a></div><div class="ttdoc">Stopwatch or countdown.</div><div class="ttdef"><b>Definition:</b> <a href="_time_8h_source.html#l00014">Time.h:14</a></div></div>
<div class="ttc" id="namespacemy_r_i_o_1_1_gyro_registers_html_ab10f36b188796cfe13e850f1051ae89c"><div class="ttname"><a href="namespacemy_r_i_o_1_1_gyro_registers.html#ab10f36b188796cfe13e850f1051ae89c">myRIO::GyroRegisters::L3G4200D_CTRL_REG5</a></div><div class="ttdeci">constexpr uint8_t L3G4200D_CTRL_REG5</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8h_source.html#l00024">Gyro.h:24</a></div></div>
<div class="ttc" id="namespacemy_r_i_o_1_1_gyro_registers_html_a527b412376904baaea708aecf4a20924"><div class="ttname"><a href="namespacemy_r_i_o_1_1_gyro_registers.html#a527b412376904baaea708aecf4a20924">myRIO::GyroRegisters::L3G4200D_WHO_AM_I</a></div><div class="ttdeci">constexpr uint8_t L3G4200D_WHO_AM_I</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8h_source.html#l00019">Gyro.h:19</a></div></div>
<div class="ttc" id="namespacemy_r_i_o_1_1_gyro_registers_html_ac31c5e5a0a125a8407e600f8f234f69b"><div class="ttname"><a href="namespacemy_r_i_o_1_1_gyro_registers.html#ac31c5e5a0a125a8407e600f8f234f69b">myRIO::GyroRegisters::L3G4200D_CTRL_REG1</a></div><div class="ttdeci">constexpr uint8_t L3G4200D_CTRL_REG1</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8h_source.html#l00020">Gyro.h:20</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_ae5465f4d912d9e2d266be2658d1ade0f"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#ae5465f4d912d9e2d266be2658d1ade0f">myRIO::Gyro::gyroStatusVal</a></div><div class="ttdeci">uint8_t gyroStatusVal</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8h_source.html#l00050">Gyro.h:50</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_a0f8555f6d90f64e13802f2376ab434dd"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#a0f8555f6d90f64e13802f2376ab434dd">myRIO::Gyro::th</a></div><div class="ttdeci">std::thread * th</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8h_source.html#l00053">Gyro.h:53</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_i2_c_html_a17cbf8d61e1ecaf6dc21a2aa0def1f27"><div class="ttname"><a href="classmy_r_i_o_1_1_i2_c.html#a17cbf8d61e1ecaf6dc21a2aa0def1f27">myRIO::I2C::write</a></div><div class="ttdeci">bool write(uint8_t reg, uint8_t data)</div><div class="ttdoc">Write 8 bits data to the given registry on a previously set slave.</div><div class="ttdef"><b>Definition:</b> <a href="_i2_c_8cpp_source.html#l00051">I2C.cpp:51</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_af58b57914897b22014110908326eace2"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#af58b57914897b22014110908326eace2">myRIO::Gyro::~Gyro</a></div><div class="ttdeci">~Gyro()</div><div class="ttdoc">Close the thread if it was running.</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8cpp_source.html#l00151">Gyro.cpp:151</a></div></div>
<div class="ttc" id="namespacemy_r_i_o_html"><div class="ttname"><a href="namespacemy_r_i_o.html">myRIO</a></div><div class="ttdef"><b>Definition:</b> <a href="_acc_8h_source.html#l00008">Acc.h:8</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_ab9c4dc9bdc1e8ce2302347653fc467e2"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#ab9c4dc9bdc1e8ce2302347653fc467e2">myRIO::Gyro::stopFreeRunningMode</a></div><div class="ttdeci">void stopFreeRunningMode()</div><div class="ttdoc">Stop the running thread.</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8cpp_source.html#l00144">Gyro.cpp:144</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_time_html_afe661f7ba15818a24bf76e83da2889a0"><div class="ttname"><a href="classmy_r_i_o_1_1_time.html#afe661f7ba15818a24bf76e83da2889a0">myRIO::Time::reset</a></div><div class="ttdeci">void reset()</div><div class="ttdoc">Reset timer to the current time.</div><div class="ttdef"><b>Definition:</b> <a href="_time_8cpp_source.html#l00021">Time.cpp:21</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_a3daeedc2b8243087bf825c6fde5a138c"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#a3daeedc2b8243087bf825c6fde5a138c">myRIO::Gyro::xOff</a></div><div class="ttdeci">double xOff</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8h_source.html#l00052">Gyro.h:52</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_i2_c_html_a0885faa777f4c62e70979c84d5133090"><div class="ttname"><a href="classmy_r_i_o_1_1_i2_c.html#a0885faa777f4c62e70979c84d5133090">myRIO::I2C::read</a></div><div class="ttdeci">bool read(uint8_t reg, uint8_t *data)</div><div class="ttdoc">Read a register and get that data back to data.</div><div class="ttdef"><b>Definition:</b> <a href="_i2_c_8cpp_source.html#l00070">I2C.cpp:70</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_ad782b97fd2a5438f04eb098be47dc5d8"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#ad782b97fd2a5438f04eb098be47dc5d8">myRIO::Gyro::gyro</a></div><div class="ttdeci">I2C * gyro</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8h_source.html#l00051">Gyro.h:51</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_aa9bf1d1c4459f25e973b58166876c431"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#aa9bf1d1c4459f25e973b58166876c431">myRIO::Gyro::zOff</a></div><div class="ttdeci">double zOff</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8h_source.html#l00052">Gyro.h:52</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_a068f42293e1363c51a8a59d08b71168b"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#a068f42293e1363c51a8a59d08b71168b">myRIO::Gyro::startFreeRunningMode</a></div><div class="ttdeci">void startFreeRunningMode(std::function< void(double &, double &)> func)</div><div class="ttdoc">Start a thread to run infinitely that will check the gyro values.</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8cpp_source.html#l00095">Gyro.cpp:95</a></div></div>
<div class="ttc" id="classmy_r_i_o_1_1_gyro_html_ab352d6a42edb7425fc17a990db5755c9"><div class="ttname"><a href="classmy_r_i_o_1_1_gyro.html#ab352d6a42edb7425fc17a990db5755c9">myRIO::Gyro::run</a></div><div class="ttdeci">bool * run</div><div class="ttdef"><b>Definition:</b> <a href="_gyro_8h_source.html#l00054">Gyro.h:54</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="dir_98fb12f9c07806436144af22cad486e4.html">Eclipse</a></li><li class="navelem"><a class="el" href="dir_e17da8bc7b823c1f82c904fefd57a078.html">workspace</a></li><li class="navelem"><a class="el" href="dir_814e4b17f8683e03c2431c0e57f58eb6.html">APIForRIO</a></li><li class="navelem"><a class="el" href="dir_c047dd42b8eba02cf6377cb404ab9432.html">src</a></li><li class="navelem"><a class="el" href="_gyro_8cpp.html">Gyro.cpp</a></li>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
</ul>
</div>
</body>
</html>