VectorNav C/C++ Library
linux_async.c

This example shows how to retrieve the lastest asynchronous data packet received from the VN-100 sensor by using the function vn100_getCurrentAsyncData. This function is useful since it does not block while a command transaction is performed with the sensor. The library's backend thread is constantly servicing the COM port and when asychronous data is received from the sensor, it saves a copy in memory making it immediately accessible on the call to vn100_getCurrentAsyncData.

#include <stdio.h>
#include <unistd.h>
#include "vectornav.h"

/* Change the connection settings to your configuration. */
const char* const COM_PORT = "//dev//ttyS1";
const int BAUD_RATE = 115200;

int main()
{
    Vn100 vn100;
    VnYpr ypr;
    int i;

    vn100_connect(&vn100, COM_PORT, BAUD_RATE);

    /* Pause to ensure we have received the first asynchronous data record from the sensor. */
    sleep(1);

    for (i = 0; i < 10; i++) {
        Vn100CompositeData data;
        vn100_getCurrentAsyncData(&vn100, &data);
        printf("YPR: %+#7.2f %+#7.2f %+#7.2f\n", data.ypr.yaw, data.ypr.pitch, data.ypr.roll);
        sleep(1);
    }
    
    vn100_disconnect(&vn100);

    return 0;
}
 All Data Structures Files Functions Variables Typedefs Defines