Files
INS-VN-200/vnproglib/cpp/help/getting_started_2main_8cpp-example.html
r.koeppe 2d22ccd2d6 initial
2024-05-14 02:14:13 +02:00

329 lines
31 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: getting_started/main.cpp</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>Classes</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">getting_started/main.cpp</div> </div>
</div><!--header-->
<div class="contents">
<p>This example illustrates basic connectivity and interaction with a VectorNav sensor over a serial port.</p>
<h1><a class="anchor" id="vsCppGettingStarted"></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;/cpp/examples/getting_started/projects/vs20XX/getting_started.sln</code>.</li>
<li>Open the project file <code>main.cpp</code> and edit the <code>SensorPort</code> and <code>SensorBaudrate</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>getting_started</code> and select <code>Debug -&gt; Start new instance</code>.</li>
</ol>
<h1><a class="anchor" id="makeCppGettingStarted"></a>
Make (Linux/Mac OS X)</h1>
<ol type="1">
<li>You will first need to open the file <code>&lt;root&gt;/cpp/examples/getting_started/main.cpp</code> and edit the <code>SensorPort</code> and <code>SensorBaudrate</code> constants at the top of the <code>main()</code> function to the settings used by your attached VectorNav sensor.</li>
<li>Open a terminal and change to the directory <code>&lt;root&gt;/cpp/examples/getting_started</code> .</li>
<li>To build the example, run the command <code>make</code> .</li>
<li>Run the example by executing the command <code>sudo ./getting_started</code> . Note that it is required to run the command using <code>sudo</code> since administrator privileges are required to access the serial ports on Linux.</li>
</ol>
<h1><a class="anchor" id="cpplionCGettingStarted"></a>
CLion (Windows/Linux/Mac OS X)</h1>
<ol type="1">
<li>Open the project file located at <code>&lt;root&gt;/cpp/examples/getting_started</code> in CLion.</li>
<li>Open the project file <code>main.cpp</code> and edit the <code>SensorPort</code> and <code>SensorBaudrate</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>getting_started</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>getting_started</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 'gettings_started'</code>.</li>
</ol>
<h1><a class="anchor" id="otherCppGettingStarted"></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/getting_started/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.cpp</code> and edit the <code>SensorPort</code> and <code>SensorBaudrate</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;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="comment">// Include this header file to get access to VectorNav sensors.</span></div>
<div class="line"><span class="preprocessor">#include &quot;vn/sensors.h&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="comment">// We need this file for our sleep function.</span></div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="thread_8h.html">vn/thread.h</a>&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span>std;</div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacevn_1_1math.html">vn::math</a>;</div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacevn_1_1sensors.html">vn::sensors</a>;</div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacevn_1_1protocol_1_1uart.html">vn::protocol::uart</a>;</div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacevn_1_1xplat.html">vn::xplat</a>;</div>
<div class="line"></div>
<div class="line"><span class="comment">// Method declarations for future use.</span></div>
<div class="line"><span class="keywordtype">void</span> asciiAsyncMessageReceived(<span class="keywordtype">void</span>* userData, <a name="_a0"></a><a class="code" href="structvn_1_1protocol_1_1uart_1_1_packet.html">Packet</a>&amp; p, <span class="keywordtype">size_t</span> index);</div>
<div class="line"><span class="keywordtype">void</span> asciiOrBinaryAsyncMessageReceived(<span class="keywordtype">void</span>* userData, <a class="code" href="structvn_1_1protocol_1_1uart_1_1_packet.html">Packet</a>&amp; p, <span class="keywordtype">size_t</span> index);</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</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.</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">string</span> SensorPort = <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 string SensorPort = &quot;/dev/ttyS1&quot;; // Linux format for physical serial port.</span></div>
<div class="line"> <span class="comment">// const string SensorPort = &quot;/dev/ttyUSB0&quot;; // Linux format for virtual (USB) serial port.</span></div>
<div class="line"> <span class="comment">// const string SensorPort = &quot;/dev/tty.usbserial-FTXXXXXX&quot;; // Mac OS X format for virtual (USB) serial port.</span></div>
<div class="line"> <span class="comment">// const string SensorPort = &quot;/dev/ttyS0&quot;; // 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 SensorBaudrate = 115200;</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Now let&#39;s create a VnSensor object and use it to connect to our sensor.</span></div>
<div class="line"> <a name="_a1"></a><a class="code" href="classvn_1_1sensors_1_1_vn_sensor.html">VnSensor</a> vs;</div>
<div class="line"> vs.<a name="a2"></a><a class="code" href="classvn_1_1sensors_1_1_vn_sensor.html#a849dd745841f155f18c1f86f3fa89786">connect</a>(SensorPort, SensorBaudrate);</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Let&#39;s query the sensor&#39;s model number.</span></div>
<div class="line"> <span class="keywordtype">string</span> mn = vs.<a name="a3"></a><a class="code" href="group__register_access_methods.html#gab89a2be8a23cba39628101d4e3722a50">readModelNumber</a>();</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;Model Number: &quot;</span> &lt;&lt; mn &lt;&lt; endl;</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Get some orientation data from the sensor.</span></div>
<div class="line"> <a name="_a4"></a><a class="code" href="structvn_1_1math_1_1vec.html">vec3f</a> ypr = vs.<a name="a5"></a><a class="code" href="group__register_access_methods.html#ga631794e00fbffd4e21842f3378787548">readYawPitchRoll</a>();</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;Current YPR: &quot;</span> &lt;&lt; ypr &lt;&lt; endl;</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Get some orientation and IMU data.</span></div>
<div class="line"> <a name="_a6"></a><a class="code" href="structvn_1_1sensors_1_1_yaw_pitch_roll_magnetic_acceleration_and_angular_rates_register.html">YawPitchRollMagneticAccelerationAndAngularRatesRegister</a> reg;</div>
<div class="line"> reg = vs.<a name="a7"></a><a class="code" href="group__register_access_methods.html#gaead622fc48bacabafe2fd637a8e09b6f">readYawPitchRollMagneticAccelerationAndAngularRates</a>();</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;Current YPR: &quot;</span> &lt;&lt; reg.<a name="a8"></a><a class="code" href="structvn_1_1sensors_1_1_yaw_pitch_roll_magnetic_acceleration_and_angular_rates_register.html#a8a36f1848066280a778915a0601cc858">yawPitchRoll</a> &lt;&lt; endl;</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;Current Magnetic: &quot;</span> &lt;&lt; reg.<a name="a9"></a><a class="code" href="structvn_1_1sensors_1_1_yaw_pitch_roll_magnetic_acceleration_and_angular_rates_register.html#a4df09c2f0f33d99182ac187ff1969519">mag</a> &lt;&lt; endl;</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;Current Acceleration: &quot;</span> &lt;&lt; reg.<a name="a10"></a><a class="code" href="structvn_1_1sensors_1_1_yaw_pitch_roll_magnetic_acceleration_and_angular_rates_register.html#aa2b7c1918403c428ded9b25af16c1389">accel</a> &lt;&lt; endl;</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;Current Angular Rates: &quot;</span> &lt;&lt; reg.<a name="a11"></a><a class="code" href="structvn_1_1sensors_1_1_yaw_pitch_roll_magnetic_acceleration_and_angular_rates_register.html#a801b3c3d768811a119b150144eb9b21b">gyro</a> &lt;&lt; endl;</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Let&#39;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"> uint32_t oldHz = vs.<a name="a12"></a><a class="code" href="group__register_access_methods.html#ga154ea7816760504df04eada69fee03f9">readAsyncDataOutputFrequency</a>();</div>
<div class="line"> vs.<a name="a13"></a><a class="code" href="group__register_access_methods.html#ga18883286254c23e521bd2f6e5df4057e">writeAsyncDataOutputFrequency</a>(2);</div>
<div class="line"> uint32_t newHz = vs.<a class="code" href="group__register_access_methods.html#ga154ea7816760504df04eada69fee03f9">readAsyncDataOutputFrequency</a>();</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;Old Async Frequency: &quot;</span> &lt;&lt; oldHz &lt;&lt; <span class="stringliteral">&quot; Hz&quot;</span> &lt;&lt; endl;</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;New Async Frequency: &quot;</span> &lt;&lt; newHz &lt;&lt; <span class="stringliteral">&quot; Hz&quot;</span> &lt;&lt; endl;</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&#39;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"> <a name="_a14"></a><a class="code" href="structvn_1_1sensors_1_1_vpe_basic_control_register.html">VpeBasicControlRegister</a> vpeReg = vs.<a name="a15"></a><a class="code" href="group__register_access_methods.html#gae0b3980ce322bd866f533fa6df56d969">readVpeBasicControl</a>();</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;Old Heading Mode: &quot;</span> &lt;&lt; vpeReg.<a name="a16"></a><a class="code" href="structvn_1_1sensors_1_1_vpe_basic_control_register.html#a2c270077786fe14d6b00d9b4b8df5eff">headingMode</a> &lt;&lt; endl;</div>
<div class="line"> vpeReg.<a class="code" href="structvn_1_1sensors_1_1_vpe_basic_control_register.html#a2c270077786fe14d6b00d9b4b8df5eff">headingMode</a> = HEADINGMODE_ABSOLUTE;</div>
<div class="line"> vs.<a name="a17"></a><a class="code" href="group__register_access_methods.html#gad5d32d18516de69050a68ec01dfd9e9f">writeVpeBasicControl</a>(vpeReg);</div>
<div class="line"> vpeReg = vs.<a class="code" href="group__register_access_methods.html#gae0b3980ce322bd866f533fa6df56d969">readVpeBasicControl</a>();</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;New Heading Mode: &quot;</span> &lt;&lt; vpeReg.<a class="code" href="structvn_1_1sensors_1_1_vpe_basic_control_register.html#a2c270077786fe14d6b00d9b4b8df5eff">headingMode</a> &lt;&lt; endl;</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&#39;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&#39;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"> vs.<a name="a18"></a><a class="code" href="group__register_access_methods.html#gac63e50c05591e083bbd6c6e20ca04482">writeAsyncDataOutputType</a>(VNYPR);</div>
<div class="line"> AsciiAsync asyncType = vs.<a name="a19"></a><a class="code" href="group__register_access_methods.html#ga785f43ae43668bbdadee558e16ea7f1c">readAsyncDataOutputType</a>();</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;ASCII Async Type: &quot;</span> &lt;&lt; asyncType &lt;&lt; endl;</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 object.</span></div>
<div class="line"> vs.<a name="a20"></a><a class="code" href="group__vn_sensor_events.html#ga9de94eba5ecda9fde06098265c0150c2">registerAsyncPacketReceivedHandler</a>(NULL, asciiAsyncMessageReceived);</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"> cout &lt;&lt; <span class="stringliteral">&quot;Starting sleep...&quot;</span> &lt;&lt; endl;</div>
<div class="line"> Thread::sleepSec(5);</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Unregister our callback method.</span></div>
<div class="line"> vs.<a name="a21"></a><a class="code" href="group__vn_sensor_events.html#gafa6a1671d3ab64c76fd7de2e27dc6d35">unregisterAsyncPacketReceivedHandler</a>();</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="_a22"></a><a class="code" href="structvn_1_1sensors_1_1_binary_output_register.html">BinaryOutputRegister</a> 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"> vs.<a name="a23"></a><a class="code" href="group__register_access_methods.html#ga5906fa2c66c3b9a1c2cbfb723cc1d7e5">writeBinaryOutput1</a>(bor);</div>
<div class="line"></div>
<div class="line"> vs.<a class="code" href="group__vn_sensor_events.html#ga9de94eba5ecda9fde06098265c0150c2">registerAsyncPacketReceivedHandler</a>(NULL, asciiOrBinaryAsyncMessageReceived);</div>
<div class="line"></div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;Starting sleep...&quot;</span> &lt;&lt; endl;</div>
<div class="line"> Thread::sleepSec(5);</div>
<div class="line"></div>
<div class="line"> vs.<a class="code" href="group__vn_sensor_events.html#gafa6a1671d3ab64c76fd7de2e27dc6d35">unregisterAsyncPacketReceivedHandler</a>();</div>
<div class="line"></div>
<div class="line"> vs.<a name="a24"></a><a class="code" href="classvn_1_1sensors_1_1_vn_sensor.html#aba1542f76232ed4e43ff38ba2677542c">disconnect</a>();</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&#39;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="structvn_1_1protocol_1_1uart_1_1_packet.html">Packet</a>&amp; p, <span class="keywordtype">size_t</span> index)</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> (p.<a name="a25"></a><a class="code" href="structvn_1_1protocol_1_1uart_1_1_packet.html#a673e63cf13227931bc6c1309b47bbc7c">type</a>() != Packet::TYPE_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> (p.<a name="a26"></a><a class="code" href="structvn_1_1protocol_1_1uart_1_1_packet.html#aac35580a613fcb4677b31bde124787f5">determineAsciiAsyncType</a>() != 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 class="code" href="structvn_1_1math_1_1vec.html">vec3f</a> ypr;</div>
<div class="line"> p.<a name="a27"></a><a class="code" href="group__uart_packet_ascii_async_parsers.html#ga735d308e88a91038631d1bad57cdaa26">parseVNYPR</a>(&amp;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"> cout &lt;&lt; <span class="stringliteral">&quot;ASCII Async YPR: &quot;</span> &lt;&lt; ypr &lt;&lt; endl;</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="structvn_1_1protocol_1_1uart_1_1_packet.html">Packet</a>&amp; p, <span class="keywordtype">size_t</span> index)</div>
<div class="line">{</div>
<div class="line"> <span class="keywordflow">if</span> (p.<a class="code" href="structvn_1_1protocol_1_1uart_1_1_packet.html#a673e63cf13227931bc6c1309b47bbc7c">type</a>() == Packet::TYPE_ASCII &amp;&amp; p.<a class="code" href="structvn_1_1protocol_1_1uart_1_1_packet.html#aac35580a613fcb4677b31bde124787f5">determineAsciiAsyncType</a>() == VNYPR)</div>
<div class="line"> {</div>
<div class="line"> <a class="code" href="structvn_1_1math_1_1vec.html">vec3f</a> ypr;</div>
<div class="line"> p.<a class="code" href="group__uart_packet_ascii_async_parsers.html#ga735d308e88a91038631d1bad57cdaa26">parseVNYPR</a>(&amp;ypr);</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;ASCII Async YPR: &quot;</span> &lt;&lt; ypr &lt;&lt; endl;</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> (p.<a class="code" href="structvn_1_1protocol_1_1uart_1_1_packet.html#a673e63cf13227931bc6c1309b47bbc7c">type</a>() == Packet::TYPE_BINARY)</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> (!p.<a name="a28"></a><a class="code" href="structvn_1_1protocol_1_1uart_1_1_packet.html#afa1df5ba1214f4359a3b3b0d02446f0a">isCompatible</a>(</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"> uint64_t timeStartup = p.<a name="a29"></a><a class="code" href="group__uart_packet_binary_extractors.html#ga4792b2e7cd05e47792c8eda1402f521a">extractUint64</a>();</div>
<div class="line"> <a class="code" href="structvn_1_1math_1_1vec.html">vec3f</a> ypr = p.<a name="a30"></a><a class="code" href="group__uart_packet_binary_extractors.html#ga9d966dba94a885948aa1c734a76f12f6">extractVec3f</a>();</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;Binary Async TimeStartup: &quot;</span> &lt;&lt; timeStartup &lt;&lt; endl;</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;Binary Async YPR: &quot;</span> &lt;&lt; ypr &lt;&lt; endl;</div>
<div class="line"> }</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:27:03 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>