VectorNav C Library
ez_async_data/main.c

This example illustrates using the high-level VnEzAsyncData 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.

Visual Studio (Windows)

  1. Open the solution file for your specific Visual Studio version located at <root>/c/examples/ez_async_data/projects/vs20XX/ez_async_data.sln.
  2. Open the project file main.c and edit the SENSOR_PORT and SENSOR_BAUDRATE constants at the top of the main() function to the settings used by your attached VectorNav sensor.
  3. Build the entire solution by going to the menu BUILD -> Build Solution.
  4. Right-click the project ez_async_data and select Debug -> Start new instance.

Make (Linux/Mac OS X)

  1. Open a terminal and change to the directory <root>/c/examples/ez_async_data .
  2. Open the file main.c and edit the SENSOR_PORT and SENSOR_BAUDRATE constants at the top of the main() function to the settings used by your attached VectorNav sensor.
  3. To build the example, run the command make .
  4. Run the example by executing the command sudo ./ez_async_data .

CLion (Windows/Linux/Mac OS X)

  1. Open the project file located at <root>/c/examples/ez_async_data in CLion.
  2. Open the project file main.c and edit the SENSOR_PORT and SENSOR_BAUDRATE constants at the top of the main() function to the settings used by your attached VectorNav sensor.
  3. Make sure the ez_async_data configuration is active. You can set this by clicking the small drop-down list in the upper-right corner and selecting the option ez_async_data.
  4. Build the solution by going to the menu Run -> Build.
  5. Run the example by going to the menu Run -> Run 'ez_async_data'.

Other

To compile and run for an environment not listed here, you will need to add all of the *.c files in the directory <root>/c/src along with the file located at <root>/c/examples/ez_async_data/main.c to your project for compilation. You will also need to add <root>/c/include to your include directories. Finally, before compiling, open the file main.c and edit the SENSOR_PORT and SENSOR_BAUDRATE constants at the top of the main() function to the settings used by your attached VectorNav sensor.

#include <stdio.h>
/* Include files needed to use VnEzAsyncData. */
#include "vn/sensors/ezasyncdata.h"
int processErrorReceived(char* errorMessage, VnError errorCode);
int main(void)
{
VnError error = E_NONE;
size_t i = 0;
char strConversions[50];
/* This example walks through using the VnEzAsyncData structure to easily access
* asynchronous data from a VectorNav sensor at a slight performance hit which is
* acceptable for many applications, especially simple data logging. */
/* First determine which COM port your sensor is attached to and update the
* constant below. Also, if you have changed your sensor from the factory
* default baudrate of 115200, you will need to update the baudrate
* constant below as well. */
const char SENSOR_PORT[] = "COM1"; /* Windows format for physical and virtual (USB) serial port. */
/*const char SENSOR_PORT[] = "/dev/ttyS1"; */ /* Linux format for physical serial port. */
/*const char SENSOR_PORT[] = "/dev/ttyUSB0"; */ /* Linux format for virtual (USB) serial port. */
/*const char SENSOR_PORT[] = "/dev/tty.usbserial-FTXXXXXX"; */ /* Mac OS X format for virtual (USB) serial port. */
/*const char SENSOR_PORT[] = "/dev/ttyS0"; */ /* CYGWIN format. Usually the Windows COM port number minus 1. This would connect to COM1. */
const uint32_t SENSOR_BAUDRATE = 115200;
/* We call the initialize and connect method to connect with our VectorNav sensor. */
if ((error = VnEzAsyncData_initializeAndConnect(&ez, SENSOR_PORT, SENSOR_BAUDRATE)) != E_NONE)
return processErrorReceived("Error connecting to sensor.", error);
/* Now let's display the latest yaw, pitch, roll data at 5 Hz for 5 seconds. */
printf("Displaying yaw, pitch, roll at 5 Hz for 5 seconds.\n");
for (i = 0; i < 25; i++)
{
cd = VnEzAsyncData_currentData(&ez);
str_vec3f(strConversions, cd.yawPitchRoll);
printf("Current YPR: %s\n", strConversions);
}
/* Most of the asynchronous data handling is done by VnEzAsyncData but there are times
* when we wish to configure the sensor directly while still having VnEzAsyncData do
* most of the grunt work. This is easily accomplished and we show changing the ASCII
* asynchronous data output type here. */
if ((error = VnSensor_writeAsyncDataOutputType(VnEzAsyncData_sensor(&ez), VNYPR, true)) != E_NONE)
return processErrorReceived("Error setting async data output type.", error);
/* We can now display yaw, pitch, roll data from the new ASCII asynchronous data type. */
printf("Displaying yaw, pitch, roll from new ASCII async type.\n");
for (i = 0; i < 25; i++)
{
cd = VnEzAsyncData_currentData(&ez);
str_vec3f(strConversions, cd.yawPitchRoll);
printf("Current YPR: %s\n", strConversions);
}
/* Now disconnect from the sensor since we are finished. */
if ((error = VnEzAsyncData_disconnectAndUninitialize(&ez)) != E_NONE)
return processErrorReceived("Error disconnecting from sensor.", error);
return 0;
}
int processErrorReceived(char* errorMessage, VnError errorCode)
{
char errorCodeStr[100];
strFromVnError(errorCodeStr, errorCode);
printf("%s\nERROR: %s\n", errorMessage, errorCodeStr);
return -1;
}