386 lines
36 KiB
HTML
386 lines
36 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: sensor/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 Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="modules.html"><span>Modules</span></a></li>
|
|
<li><a href="annotated.html"><span>Data 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">sensor/main.c</div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<p>This example illustrates using the high-level <a class="el" href="struct_vn_sensor.html" title="Helpful structure for working with VectorNav sensors. ">VnSensor</a> structure to access a VectorNav sensor on a system with an operating system. This example is in contrast with the getting_started/main.c example which is lower-level protocol handling and requires the user to supply external communication functions.</p>
|
|
<h1><a class="anchor" id="vsCSensor"></a>
|
|
Visual Studio (Windows)</h1>
|
|
<ol type="1">
|
|
<li>Open the solution file for your specific Visual Studio version located at <code><root>/c/examples/sensor/projects/vs20XX/sensor.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 -> Build Solution</code>.</li>
|
|
<li>Right-click the project <code>sensor</code> and select <code>Debug -> Start new instance</code>.</li>
|
|
</ol>
|
|
<h1><a class="anchor" id="makeCSensor"></a>
|
|
Make (Linux/Mac OS X)</h1>
|
|
<ol type="1">
|
|
<li>Open a terminal and change to the directory <code><root>/c/examples/sensor</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 ./sensor</code> .</li>
|
|
</ol>
|
|
<h1><a class="anchor" id="clionCSensor"></a>
|
|
CLion (Windows/Linux/Mac OS X)</h1>
|
|
<ol type="1">
|
|
<li>Open the project file located at <code><root>/c/examples/sensor</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>sensor</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>sensor</code>.</li>
|
|
<li>Build the solution by going to the menu <code>Run -> Build</code>.</li>
|
|
<li>Run the example by going to the menu <code>Run -> Run 'sensor'</code>.</li>
|
|
</ol>
|
|
<h1><a class="anchor" id="otherCSensor"></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><root>/c/src</code> along with the file located at <code><root>/c/examples/sensor/main.c</code> to your project for compilation. You will also need to add <code><root>/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 <stdio.h></span></div>
|
|
<div class="line"><span class="preprocessor">#include <inttypes.h></span></div>
|
|
<div class="line"></div>
|
|
<div class="line"><span class="comment">/* Include files needed to use VnSensor. */</span></div>
|
|
<div class="line"><span class="preprocessor">#include "<a class="code" href="sensors_8h.html">vn/sensors.h</a>"</span></div>
|
|
<div class="line"></div>
|
|
<div class="line"><span class="keywordtype">void</span> asciiAsyncMessageReceived(<span class="keywordtype">void</span> *userData, <a name="_a0"></a><a class="code" href="struct_vn_uart_packet.html">VnUartPacket</a> *packet, <span class="keywordtype">size_t</span> runningIndex);</div>
|
|
<div class="line"><span class="keywordtype">void</span> asciiOrBinaryAsyncMessageReceived(<span class="keywordtype">void</span> *userData, <a class="code" href="struct_vn_uart_packet.html">VnUartPacket</a> *packet, <span class="keywordtype">size_t</span> runningIndex);</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="_a1"></a><a class="code" href="struct_vn_sensor.html">VnSensor</a> vs;</div>
|
|
<div class="line"> <span class="keywordtype">char</span> modelNumber[30];</div>
|
|
<div class="line"> <span class="keywordtype">char</span> strConversions[50];</div>
|
|
<div class="line"> <a name="_a2"></a><a class="code" href="unionvec3f.html">vec3f</a> ypr;</div>
|
|
<div class="line"> <a name="_a3"></a><a class="code" href="struct_yaw_pitch_roll_magnetic_acceleration_and_angular_rates_register.html">YawPitchRollMagneticAccelerationAndAngularRatesRegister</a> reg;</div>
|
|
<div class="line"> <a name="_a4"></a><a class="code" href="struct_vpe_basic_control_register.html">VpeBasicControlRegister</a> vpeReg;</div>
|
|
<div class="line"> uint32_t oldHz, newHz;</div>
|
|
<div class="line"> VnAsciiAsync asyncType;</div>
|
|
<div class="line"> <a name="_a5"></a><a class="code" href="struct_binary_output_register.html">BinaryOutputRegister</a> bor;</div>
|
|
<div class="line"> VnError error;</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* This example walks through using the VectorNav C Library to connect to</span></div>
|
|
<div class="line"><span class="comment"> * and interact with a VectorNav sensor using the VnSensor structure. */</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">"COM1"</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[] = "/dev/ttyS1"; */</span> <span class="comment">/* Linux format for physical serial port. */</span></div>
|
|
<div class="line"> <span class="comment">/*const char SENSOR_PORT[] = "/dev/ttyUSB0"; */</span> <span class="comment">/* Linux format for virtual (USB) serial port. */</span></div>
|
|
<div class="line"> <span class="comment">/*const char SENSOR_PORT[] = "/dev/tty.usbserial-FTXXXXXX"; */</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[] = "/dev/ttyS0"; */</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 first need to initialize our VnSensor structure. */</span></div>
|
|
<div class="line"> <a name="a6"></a><a class="code" href="sensors_8h.html#aa85a300484816d7e49f32aaccfd07553">VnSensor_initialize</a>(&vs);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Now connect to our sensor. */</span></div>
|
|
<div class="line"> <span class="keywordflow">if</span> ((error = <a name="a7"></a><a class="code" href="sensors_8h.html#a4119849871592f17e73a0069c35b212e">VnSensor_connect</a>(&vs, SENSOR_PORT, SENSOR_BAUDRATE)) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error connecting to sensor."</span>, error);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Let's query the sensor's model number. */</span></div>
|
|
<div class="line"> <span class="keywordflow">if</span> ((error = <a name="a8"></a><a class="code" href="group__register_access_methods.html#ga828407d537f5c56ff24f6b53300cd849">VnSensor_readModelNumber</a>(&vs, modelNumber, <span class="keyword">sizeof</span>(modelNumber))) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error reading model number."</span>, error);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"Model Number: %s\n"</span>, modelNumber);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Get some orientation data from the sensor. */</span></div>
|
|
<div class="line"> <span class="keywordflow">if</span> ((error = <a name="a9"></a><a class="code" href="group__register_access_methods.html#gaa6dae4194856ca741805cf2e0e5eb77e">VnSensor_readYawPitchRoll</a>(&vs, &ypr)) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error reading yaw pitch roll."</span>, error);</div>
|
|
<div class="line"> str_vec3f(strConversions, ypr);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"Current YPR: %s\n"</span>, strConversions);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Get some orientation and IMU data. */</span></div>
|
|
<div class="line"> <span class="keywordflow">if</span> ((error = <a name="a10"></a><a class="code" href="group__register_access_methods.html#ga626456fecf0b2f69d14a38315e59477c">VnSensor_readYawPitchRollMagneticAccelerationAndAngularRates</a>(&vs, &reg)) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error reading orientation and IMU data."</span>, error);</div>
|
|
<div class="line"> str_vec3f(strConversions, reg.<a name="a11"></a><a class="code" href="struct_yaw_pitch_roll_magnetic_acceleration_and_angular_rates_register.html#a422bd966180f1f455de6f4d6b9e60d17">yawPitchRoll</a>);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"Current YPR: %s\n"</span>, strConversions);</div>
|
|
<div class="line"> str_vec3f(strConversions, reg.<a name="a12"></a><a class="code" href="struct_yaw_pitch_roll_magnetic_acceleration_and_angular_rates_register.html#a6d7a8470b23c03065744577e1cd50509">mag</a>);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"Current Magnetic: %s\n"</span>, strConversions);</div>
|
|
<div class="line"> str_vec3f(strConversions, reg.<a name="a13"></a><a class="code" href="struct_yaw_pitch_roll_magnetic_acceleration_and_angular_rates_register.html#abc4f9f3b3459f809b15eeffb87fc06e1">accel</a>);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"Current Acceleration: %s\n"</span>, strConversions);</div>
|
|
<div class="line"> str_vec3f(strConversions, reg.<a name="a14"></a><a class="code" href="struct_yaw_pitch_roll_magnetic_acceleration_and_angular_rates_register.html#ab890584ad2f34c8fd0b63ecd8ef5e29b">gyro</a>);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"Current Angular Rates: %s\n"</span>, strConversions);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Let's do some simple reconfiguration of the sensor. As it comes from the</span></div>
|
|
<div class="line"><span class="comment"> * factory, the sensor outputs asynchronous data at 40 Hz. We will change</span></div>
|
|
<div class="line"><span class="comment"> * this to 2 Hz for demonstration purposes. */</span></div>
|
|
<div class="line"> <span class="keywordflow">if</span> ((error = <a name="a15"></a><a class="code" href="group__register_access_methods.html#ga8697185242ceebeb9a014d923e3efc49">VnSensor_readAsyncDataOutputFrequency</a>(&vs, &oldHz)) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error reading async data output frequency."</span>, error);</div>
|
|
<div class="line"> <span class="keywordflow">if</span> ((error = <a name="a16"></a><a class="code" href="group__register_access_methods.html#ga182ff64ec8d0abf4591b12b7d888eba9">VnSensor_writeAsyncDataOutputFrequency</a>(&vs, 2, <span class="keyword">true</span>)) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error writing async data output frequency."</span>, error);</div>
|
|
<div class="line"> <span class="keywordflow">if</span> ((error = <a class="code" href="group__register_access_methods.html#ga8697185242ceebeb9a014d923e3efc49">VnSensor_readAsyncDataOutputFrequency</a>(&vs, &newHz)) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error reading async data output frequency."</span>, error);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"Old Async Frequency: %d Hz\n"</span>, oldHz);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"New Async Frequency: %d Hz\n"</span>, newHz);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* For the registers that have more complex configuration options, it is</span></div>
|
|
<div class="line"><span class="comment"> * convenient to read the current existing register configuration, change</span></div>
|
|
<div class="line"><span class="comment"> * only the values of interest, and then write the configuration to the</span></div>
|
|
<div class="line"><span class="comment"> * register. This allows preserving the current settings for the register's</span></div>
|
|
<div class="line"><span class="comment"> * other fields. Below, we change the heading mode used by the sensor. */</span></div>
|
|
<div class="line"> <span class="keywordflow">if</span> ((error = <a name="a17"></a><a class="code" href="group__register_access_methods.html#ga9151c8f37e12b6c9967c09d2466fea77">VnSensor_readVpeBasicControl</a>(&vs, &vpeReg)) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error reading VPE basic control."</span>, error);</div>
|
|
<div class="line"> <a name="a18"></a><a class="code" href="sensors_8h.html#a2930ef60abd21d0523be4da88b3e4446">strFromHeadingMode</a>(strConversions, vpeReg.<a name="a19"></a><a class="code" href="struct_vpe_basic_control_register.html#a2a92eaae7f0850d6e2eedd6ba2eedb07">headingMode</a>);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"Old Heading Mode: %s\n"</span>, strConversions);</div>
|
|
<div class="line"> vpeReg.<a class="code" href="struct_vpe_basic_control_register.html#a2a92eaae7f0850d6e2eedd6ba2eedb07">headingMode</a> = VNHEADINGMODE_ABSOLUTE;</div>
|
|
<div class="line"> <span class="keywordflow">if</span> ((error = <a name="a20"></a><a class="code" href="group__register_access_methods.html#ga4a5de1b8deb2f82ed44ade6974a15e02">VnSensor_writeVpeBasicControl</a>(&vs, vpeReg, <span class="keyword">true</span>)) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error writing VPE basic control."</span>, error);</div>
|
|
<div class="line"> <span class="keywordflow">if</span> ((error = <a class="code" href="group__register_access_methods.html#ga9151c8f37e12b6c9967c09d2466fea77">VnSensor_readVpeBasicControl</a>(&vs, &vpeReg)) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error reading VPE basic control."</span>, error);</div>
|
|
<div class="line"> <a class="code" href="sensors_8h.html#a2930ef60abd21d0523be4da88b3e4446">strFromHeadingMode</a>(strConversions, vpeReg.<a class="code" href="struct_vpe_basic_control_register.html#a2a92eaae7f0850d6e2eedd6ba2eedb07">headingMode</a>);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"New Heading Mode: %s\n"</span>, strConversions);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Up to now, we have shown some examples of how to configure the sensor</span></div>
|
|
<div class="line"><span class="comment"> * and query for the latest measurements. However, this querying is a</span></div>
|
|
<div class="line"><span class="comment"> * relatively slow method for getting measurements since the CPU has to</span></div>
|
|
<div class="line"><span class="comment"> * send out the command to the sensor and also wait for the command</span></div>
|
|
<div class="line"><span class="comment"> * response. An alternative way of receiving the sensor's latest</span></div>
|
|
<div class="line"><span class="comment"> * measurements without the waiting for a query response, you can configure</span></div>
|
|
<div class="line"><span class="comment"> * the library to alert you when new asynchronous data measurements are</span></div>
|
|
<div class="line"><span class="comment"> * received. We will illustrate hooking up to our current VnSensor to</span></div>
|
|
<div class="line"><span class="comment"> * receive these notifications of asynchronous messages. */</span></div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* First let's configure the sensor to output a known asynchronous data</span></div>
|
|
<div class="line"><span class="comment"> * message type. */</span></div>
|
|
<div class="line"> <span class="keywordflow">if</span> ((error = <a name="a21"></a><a class="code" href="group__register_access_methods.html#gaf36c1e47164b6462c07708b5971f97cf">VnSensor_writeAsyncDataOutputType</a>(&vs, VNYPR, <span class="keyword">true</span>)) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error writing to async data output type."</span>, error);</div>
|
|
<div class="line"> <span class="keywordflow">if</span> ((error = <a name="a22"></a><a class="code" href="group__register_access_methods.html#gaa112c59da2d15f92cc5a5bcea1938ed5">VnSensor_readAsyncDataOutputType</a>(&vs, &asyncType)) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error reading async data output type."</span>, error);</div>
|
|
<div class="line"> strFromVnAsciiAsync(strConversions, asyncType);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"ASCII Async Type: %s\n"</span>, strConversions);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* You will need to define a method which has the appropriate</span></div>
|
|
<div class="line"><span class="comment"> * signature for receiving notifications. This is implemented with the</span></div>
|
|
<div class="line"><span class="comment"> * method asciiAsyncMessageReceived. Now we register the method with the</span></div>
|
|
<div class="line"><span class="comment"> * VnSensor structure. */</span></div>
|
|
<div class="line"> <a name="a23"></a><a class="code" href="sensors_8h.html#ac2ae8a9a36c04703afd6f281a455a422">VnSensor_registerAsyncPacketReceivedHandler</a>(&vs, asciiAsyncMessageReceived, NULL);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Now sleep for 5 seconds so that our asynchronous callback method can</span></div>
|
|
<div class="line"><span class="comment"> * receive and display receive yaw, pitch, roll packets. */</span></div>
|
|
<div class="line"> printf(<span class="stringliteral">"Starting sleep...\n"</span>);</div>
|
|
<div class="line"> <a name="a24"></a><a class="code" href="thread_8h.html#a4f80a22d8ebeab270653deeb86199726">VnThread_sleepSec</a>(5);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Unregister our callback method. */</span></div>
|
|
<div class="line"> <a name="a25"></a><a class="code" href="sensors_8h.html#a6cf70cc3ef2c164ac5ac4b7ab68df687">VnSensor_unregisterAsyncPacketReceivedHandler</a>(&vs);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* As an alternative to receiving notifications of new ASCII asynchronous</span></div>
|
|
<div class="line"><span class="comment"> * messages, the binary output configuration of the sensor is another</span></div>
|
|
<div class="line"><span class="comment"> * popular choice for receiving data since it is compact, fast to parse,</span></div>
|
|
<div class="line"><span class="comment"> * and can be output at faster rates over the same connection baudrate.</span></div>
|
|
<div class="line"><span class="comment"> * Here we will configure the binary output register and process packets</span></div>
|
|
<div class="line"><span class="comment"> * with a new callback method that can handle both ASCII and binary</span></div>
|
|
<div class="line"><span class="comment"> * packets. */</span></div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* First we create a structure for setting the configuration information</span></div>
|
|
<div class="line"><span class="comment"> * for the binary output register to send yaw, pitch, roll data out at</span></div>
|
|
<div class="line"><span class="comment"> * 4 Hz. */</span></div>
|
|
<div class="line"> <a name="a26"></a><a class="code" href="group__register_structures.html#gab3061f669ecafade5b67ce11fef27bd1">BinaryOutputRegister_initialize</a>(</div>
|
|
<div class="line"> &bor,</div>
|
|
<div class="line"> ASYNCMODE_PORT1,</div>
|
|
<div class="line"> 200,</div>
|
|
<div class="line"> COMMONGROUP_TIMESTARTUP | COMMONGROUP_YAWPITCHROLL, <span class="comment">/* Note use of binary OR to configure flags. */</span></div>
|
|
<div class="line"> TIMEGROUP_NONE,</div>
|
|
<div class="line"> IMUGROUP_NONE,</div>
|
|
<div class="line"> GPSGROUP_NONE,</div>
|
|
<div class="line"> ATTITUDEGROUP_NONE,</div>
|
|
<div class="line"> INSGROUP_NONE);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="keywordflow">if</span> ((error = <a name="a27"></a><a class="code" href="group__register_access_methods.html#ga1eb72c717997c23e449cfc5de8571935">VnSensor_writeBinaryOutput1</a>(&vs, &bor, <span class="keyword">true</span>)) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error writing binary output 1."</span>, error);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <a class="code" href="sensors_8h.html#ac2ae8a9a36c04703afd6f281a455a422">VnSensor_registerAsyncPacketReceivedHandler</a>(&vs, asciiOrBinaryAsyncMessageReceived, NULL);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> printf(<span class="stringliteral">"Starting sleep...\n"</span>);</div>
|
|
<div class="line"> <a class="code" href="thread_8h.html#a4f80a22d8ebeab270653deeb86199726">VnThread_sleepSec</a>(5);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <a class="code" href="sensors_8h.html#a6cf70cc3ef2c164ac5ac4b7ab68df687">VnSensor_unregisterAsyncPacketReceivedHandler</a>(&vs);</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 = <a name="a28"></a><a class="code" href="sensors_8h.html#a74157c344356b64aeaae97970ccab34a">VnSensor_disconnect</a>(&vs)) != E_NONE)</div>
|
|
<div class="line"> <span class="keywordflow">return</span> processErrorReceived(<span class="stringliteral">"Error disconnecting from sensor."</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="comment">/* This is our basic callback handler for notifications of new asynchronous</span></div>
|
|
<div class="line"><span class="comment"> * data packets received. The userData parameter is a pointer to the data we</span></div>
|
|
<div class="line"><span class="comment"> * supplied when we called registerAsyncPacketReceivedHandler. In this case</span></div>
|
|
<div class="line"><span class="comment"> * we didn't need any user data so we just set this to NULL. Alternatively you</span></div>
|
|
<div class="line"><span class="comment"> * can provide a pointer to user data which you can use in the callback method.</span></div>
|
|
<div class="line"><span class="comment"> * One use for this is help in calling back to a member method instead of just</span></div>
|
|
<div class="line"><span class="comment"> * a global or static method. The Packet p parameter is an encapsulation of</span></div>
|
|
<div class="line"><span class="comment"> * the data packet. At this state, it has already been validated and identified</span></div>
|
|
<div class="line"><span class="comment"> * as an asynchronous data message. However, some processing is required on the</span></div>
|
|
<div class="line"><span class="comment"> * user side to make sure it is the right type of asynchronous message type so</span></div>
|
|
<div class="line"><span class="comment"> * we can parse it correctly. The index parameter is an advanced usage item and</span></div>
|
|
<div class="line"><span class="comment"> * can be safely ignored for now. */</span></div>
|
|
<div class="line"><span class="keywordtype">void</span> asciiAsyncMessageReceived(<span class="keywordtype">void</span> *userData, <a class="code" href="struct_vn_uart_packet.html">VnUartPacket</a> *packet, <span class="keywordtype">size_t</span> runningIndex)</div>
|
|
<div class="line">{</div>
|
|
<div class="line"> <a class="code" href="unionvec3f.html">vec3f</a> ypr;</div>
|
|
<div class="line"> <span class="keywordtype">char</span> strConversions[50];</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Silence 'unreferenced formal parameters' warning in Visual Studio. */</span></div>
|
|
<div class="line"> (userData);</div>
|
|
<div class="line"> (runningIndex);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Make sure we have an ASCII packet and not a binary packet. */</span></div>
|
|
<div class="line"> <span class="keywordflow">if</span> (VnUartPacket_type(packet) != PACKETTYPE_ASCII)</div>
|
|
<div class="line"> <span class="keywordflow">return</span>;</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Make sure we have a VNYPR data packet. */</span></div>
|
|
<div class="line"> <span class="keywordflow">if</span> (VnUartPacket_determineAsciiAsyncType(packet) != VNYPR)</div>
|
|
<div class="line"> <span class="keywordflow">return</span>;</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* We now need to parse out the yaw, pitch, roll data. */</span></div>
|
|
<div class="line"> <a name="a29"></a><a class="code" href="group__uart_packet_ascii_async_parsers.html#gabcab9b6803cb8b3da74abc2601cd40a2">VnUartPacket_parseVNYPR</a>(packet, &ypr);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Now print out the yaw, pitch, roll measurements. */</span></div>
|
|
<div class="line"> str_vec3f(strConversions, ypr);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"ASCII Async YPR: %s\n"</span>, strConversions);</div>
|
|
<div class="line">}</div>
|
|
<div class="line"></div>
|
|
<div class="line"><span class="keywordtype">void</span> asciiOrBinaryAsyncMessageReceived(<span class="keywordtype">void</span> *userData, <a class="code" href="struct_vn_uart_packet.html">VnUartPacket</a> *packet, <span class="keywordtype">size_t</span> runningIndex)</div>
|
|
<div class="line">{</div>
|
|
<div class="line"> <a class="code" href="unionvec3f.html">vec3f</a> ypr;</div>
|
|
<div class="line"> <span class="keywordtype">char</span> strConversions[50];</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Silence 'unreferenced formal parameters' warning in Visual Studio. */</span></div>
|
|
<div class="line"> (userData);</div>
|
|
<div class="line"> (runningIndex);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="keywordflow">if</span> (VnUartPacket_type(packet) == PACKETTYPE_ASCII && VnUartPacket_determineAsciiAsyncType(packet) == VNYPR)</div>
|
|
<div class="line"> {</div>
|
|
<div class="line"> <a class="code" href="group__uart_packet_ascii_async_parsers.html#gabcab9b6803cb8b3da74abc2601cd40a2">VnUartPacket_parseVNYPR</a>(packet, &ypr);</div>
|
|
<div class="line"> str_vec3f(strConversions, ypr);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"ASCII Async YPR: %s\n"</span>, strConversions);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="keywordflow">return</span>;</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="keywordflow">if</span> (VnUartPacket_type(packet) == PACKETTYPE_BINARY)</div>
|
|
<div class="line"> {</div>
|
|
<div class="line"> uint64_t timeStartup;</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* First make sure we have a binary packet type we expect since there</span></div>
|
|
<div class="line"><span class="comment"> * are many types of binary output types that can be configured. */</span></div>
|
|
<div class="line"> <span class="keywordflow">if</span> (!VnUartPacket_isCompatible(packet,</div>
|
|
<div class="line"> COMMONGROUP_TIMESTARTUP | COMMONGROUP_YAWPITCHROLL,</div>
|
|
<div class="line"> TIMEGROUP_NONE,</div>
|
|
<div class="line"> IMUGROUP_NONE,</div>
|
|
<div class="line"> GPSGROUP_NONE,</div>
|
|
<div class="line"> ATTITUDEGROUP_NONE,</div>
|
|
<div class="line"> INSGROUP_NONE))</div>
|
|
<div class="line"> <span class="comment">/* Not the type of binary packet we are expecting. */</span></div>
|
|
<div class="line"> <span class="keywordflow">return</span>;</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">/* Ok, we have our expected binary output packet. Since there are many</span></div>
|
|
<div class="line"><span class="comment"> * ways to configure the binary data output, the burden is on the user</span></div>
|
|
<div class="line"><span class="comment"> * to correctly parse the binary packet. However, we can make use of</span></div>
|
|
<div class="line"><span class="comment"> * the parsing convenience methods provided by the Packet structure.</span></div>
|
|
<div class="line"><span class="comment"> * When using these convenience methods, you have to extract them in</span></div>
|
|
<div class="line"><span class="comment"> * the order they are organized in the binary packet per the User Manual. */</span></div>
|
|
<div class="line"> timeStartup = <a name="a30"></a><a class="code" href="group__uart_packet_binary_extractors.html#ga6fe1746b5fec18983245f1bd020f39e9">VnUartPacket_extractUint64</a>(packet);</div>
|
|
<div class="line"> ypr = <a name="a31"></a><a class="code" href="group__uart_packet_binary_extractors.html#gab50c5ac1ff646d31e2648fe67c8977e4">VnUartPacket_extractVec3f</a>(packet);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> str_vec3f(strConversions, ypr);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"Binary Async TimeStartup: %"</span> PRIu64 <span class="stringliteral">"\n"</span>, timeStartup);</div>
|
|
<div class="line"> printf(<span class="stringliteral">"Binary Async YPR: %s\n"</span>, strConversions);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="keywordflow">return</span>;</div>
|
|
<div class="line"> }</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">"%s\nERROR: %s\n"</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  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
|
</a> 1.8.10
|
|
</small></address>
|
|
</body>
|
|
</html>
|