INS-VN-200/vnproglib/c/help/ez_async_data_2main_8c-example.html
2024-05-14 02:14:13 +02:00

205 lines
15 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://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.10"/>
<title>VectorNav C Library: ez_async_data/main.c</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="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>
<script type="text/javascript">
$(document).ready(function() { init_search(); });
</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="projectlogo"><img alt="Logo" src="proglib.png"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">VectorNav C Library
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.10 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
</div><!-- top -->
<!-- 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">ez_async_data/main.c</div> </div>
</div><!--header-->
<div class="contents">
<p>This example illustrates using the high-level <a class="el" href="struct_vn_ez_async_data.html" title="Structure supporting easy and reliable access to asynchronous data from a VectorNav sensor at the cos...">VnEzAsyncData</a> structure to access and easily connect to a VectorNav sensor on a system with an operating system and display current data from the VectorNav sensor.</p>
<h1><a class="anchor" id="vsCEzAsyncData"></a>
Visual Studio (Windows)</h1>
<ol type="1">
<li>Open the solution file for your specific Visual Studio version located at <code>&lt;root&gt;/c/examples/ez_async_data/projects/vs20XX/ez_async_data.sln</code>.</li>
<li>Open the project file <code>main.c</code> and edit the <code>SENSOR_PORT</code> and <code>SENSOR_BAUDRATE</code> constants at the top of the <code>main()</code> function to the settings used by your attached VectorNav sensor.</li>
<li>Build the entire solution by going to the menu <code>BUILD -&gt; Build Solution</code>.</li>
<li>Right-click the project <code>ez_async_data</code> and select <code>Debug -&gt; Start new instance</code>.</li>
</ol>
<h1><a class="anchor" id="makeCEzAsyncData"></a>
Make (Linux/Mac OS X)</h1>
<ol type="1">
<li>Open a terminal and change to the directory <code>&lt;root&gt;/c/examples/ez_async_data</code> .</li>
<li>Open the file <code>main.c</code> and edit the <code>SENSOR_PORT</code> and <code>SENSOR_BAUDRATE</code> constants at the top of the <code>main()</code> function to the settings used by your attached VectorNav sensor.</li>
<li>To build the example, run the command <code>make</code> .</li>
<li>Run the example by executing the command <code>sudo ./ez_async_data</code> .</li>
</ol>
<h1><a class="anchor" id="clionCEzAsyncData"></a>
CLion (Windows/Linux/Mac OS X)</h1>
<ol type="1">
<li>Open the project file located at <code>&lt;root&gt;/c/examples/ez_async_data</code> in CLion.</li>
<li>Open the project file <code>main.c</code> and edit the <code>SENSOR_PORT</code> and <code>SENSOR_BAUDRATE</code> constants at the top of the <code>main()</code> function to the settings used by your attached VectorNav sensor.</li>
<li>Make sure the <code>ez_async_data</code> configuration is active. You can set this by clicking the small drop-down list in the upper-right corner and selecting the option <code>ez_async_data</code>.</li>
<li>Build the solution by going to the menu <code>Run -&gt; Build</code>.</li>
<li>Run the example by going to the menu <code>Run -&gt; Run 'ez_async_data'</code>.</li>
</ol>
<h1><a class="anchor" id="otherCEzAsyncData"></a>
Other</h1>
<p>To compile and run for an environment not listed here, you will need to add all of the <code>*.c</code> files in the directory <code>&lt;root&gt;/c/src</code> along with the file located at <code>&lt;root&gt;/c/examples/ez_async_data/main.c</code> to your project for compilation. You will also need to add <code>&lt;root&gt;/c/include</code> to your include directories. Finally, before compiling, open the file <code>main.c</code> and edit the <code>SENSOR_PORT</code> and <code>SENSOR_BAUDRATE</code> constants at the top of the <code>main()</code> function to the settings used by your attached VectorNav sensor.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="comment">/* Include files needed to use VnEzAsyncData. */</span></div>
<div class="line"><span class="preprocessor">#include &quot;vn/sensors/ezasyncdata.h&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> processErrorReceived(<span class="keywordtype">char</span>* errorMessage, VnError errorCode);</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line"> <a name="_a0"></a><a class="code" href="struct_vn_ez_async_data.html">VnEzAsyncData</a> ez;</div>
<div class="line"> VnError error = E_NONE;</div>
<div class="line"> <span class="keywordtype">size_t</span> i = 0;</div>
<div class="line"> <span class="keywordtype">char</span> strConversions[50];</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* This example walks through using the VnEzAsyncData structure to easily access</span></div>
<div class="line"><span class="comment"> * asynchronous data from a VectorNav sensor at a slight performance hit which is</span></div>
<div class="line"><span class="comment"> * acceptable for many applications, especially simple data logging. */</span></div>
<div class="line"></div>
<div class="line"> <span class="comment">/* First determine which COM port your sensor is attached to and update the</span></div>
<div class="line"><span class="comment"> * constant below. Also, if you have changed your sensor from the factory</span></div>
<div class="line"><span class="comment"> * default baudrate of 115200, you will need to update the baudrate</span></div>
<div class="line"><span class="comment"> * constant below as well. */</span></div>
<div class="line"> <span class="keyword">const</span> <span class="keywordtype">char</span> SENSOR_PORT[] = <span class="stringliteral">&quot;COM1&quot;</span>; <span class="comment">/* Windows format for physical and virtual (USB) serial port. */</span></div>
<div class="line"> <span class="comment">/*const char SENSOR_PORT[] = &quot;/dev/ttyS1&quot;; */</span> <span class="comment">/* Linux format for physical serial port. */</span></div>
<div class="line"> <span class="comment">/*const char SENSOR_PORT[] = &quot;/dev/ttyUSB0&quot;; */</span> <span class="comment">/* Linux format for virtual (USB) serial port. */</span></div>
<div class="line"> <span class="comment">/*const char SENSOR_PORT[] = &quot;/dev/tty.usbserial-FTXXXXXX&quot;; */</span> <span class="comment">/* Mac OS X format for virtual (USB) serial port. */</span></div>
<div class="line"> <span class="comment">/*const char SENSOR_PORT[] = &quot;/dev/ttyS0&quot;; */</span> <span class="comment">/* CYGWIN format. Usually the Windows COM port number minus 1. This would connect to COM1. */</span></div>
<div class="line"> <span class="keyword">const</span> uint32_t SENSOR_BAUDRATE = 115200;</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* We call the initialize and connect method to connect with our VectorNav sensor. */</span></div>
<div class="line"> <span class="keywordflow">if</span> ((error = VnEzAsyncData_initializeAndConnect(&amp;ez, SENSOR_PORT, SENSOR_BAUDRATE)) != E_NONE)</div>
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">&quot;Error connecting to sensor.&quot;</span>, error);</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* Now let&#39;s display the latest yaw, pitch, roll data at 5 Hz for 5 seconds. */</span></div>
<div class="line"> printf(<span class="stringliteral">&quot;Displaying yaw, pitch, roll at 5 Hz for 5 seconds.\n&quot;</span>);</div>
<div class="line"> <span class="keywordflow">for</span> (i = 0; i &lt; 25; i++)</div>
<div class="line"> {</div>
<div class="line"> <a name="_a1"></a><a class="code" href="struct_vn_composite_data.html">VnCompositeData</a> cd;</div>
<div class="line"></div>
<div class="line"> <a name="a2"></a><a class="code" href="thread_8h.html#ae184a96ccf6c94c4b9d7b937655b0c44">VnThread_sleepMs</a>(200);</div>
<div class="line"></div>
<div class="line"> cd = VnEzAsyncData_currentData(&amp;ez);</div>
<div class="line"></div>
<div class="line"> str_vec3f(strConversions, cd.<a name="a3"></a><a class="code" href="struct_vn_composite_data.html#a422bd966180f1f455de6f4d6b9e60d17">yawPitchRoll</a>);</div>
<div class="line"> printf(<span class="stringliteral">&quot;Current YPR: %s\n&quot;</span>, strConversions);</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* Most of the asynchronous data handling is done by VnEzAsyncData but there are times</span></div>
<div class="line"><span class="comment"> * when we wish to configure the sensor directly while still having VnEzAsyncData do</span></div>
<div class="line"><span class="comment"> * most of the grunt work. This is easily accomplished and we show changing the ASCII</span></div>
<div class="line"><span class="comment"> * asynchronous data output type here. */</span></div>
<div class="line"> <span class="keywordflow">if</span> ((error = <a name="a4"></a><a class="code" href="group__register_access_methods.html#gaf36c1e47164b6462c07708b5971f97cf">VnSensor_writeAsyncDataOutputType</a>(VnEzAsyncData_sensor(&amp;ez), VNYPR, <span class="keyword">true</span>)) != E_NONE)</div>
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">&quot;Error setting async data output type.&quot;</span>, error);</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* We can now display yaw, pitch, roll data from the new ASCII asynchronous data type. */</span></div>
<div class="line"> printf(<span class="stringliteral">&quot;Displaying yaw, pitch, roll from new ASCII async type.\n&quot;</span>);</div>
<div class="line"> <span class="keywordflow">for</span> (i = 0; i &lt; 25; i++)</div>
<div class="line"> {</div>
<div class="line"> <a class="code" href="struct_vn_composite_data.html">VnCompositeData</a> cd;</div>
<div class="line"></div>
<div class="line"> <a class="code" href="thread_8h.html#ae184a96ccf6c94c4b9d7b937655b0c44">VnThread_sleepMs</a>(200);</div>
<div class="line"></div>
<div class="line"> cd = VnEzAsyncData_currentData(&amp;ez);</div>
<div class="line"></div>
<div class="line"> str_vec3f(strConversions, cd.<a class="code" href="struct_vn_composite_data.html#a422bd966180f1f455de6f4d6b9e60d17">yawPitchRoll</a>);</div>
<div class="line"> printf(<span class="stringliteral">&quot;Current YPR: %s\n&quot;</span>, strConversions);</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* Now disconnect from the sensor since we are finished. */</span></div>
<div class="line"> <span class="keywordflow">if</span> ((error = VnEzAsyncData_disconnectAndUninitialize(&amp;ez)) != E_NONE)</div>
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">&quot;Error disconnecting from sensor.&quot;</span>, error);</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> processErrorReceived(<span class="keywordtype">char</span>* errorMessage, VnError errorCode)</div>
<div class="line">{</div>
<div class="line"> <span class="keywordtype">char</span> errorCodeStr[100];</div>
<div class="line"> strFromVnError(errorCodeStr, errorCode);</div>
<div class="line"> printf(<span class="stringliteral">&quot;%s\nERROR: %s\n&quot;</span>, errorMessage, errorCodeStr);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 3 2017 18:26:57 for VectorNav C Library by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
</body>
</html>