VectorNav C/C++ Library
|
Here is an example of using compling the library on Windows using Microsoft's Visual Studio. This example will open a connection to a VN-100 device, display the current yaw, pitch, roll attitude for ten seconds, and then close the connection to the device. Note that in this examples, the thread calling the function vn100_getYawPitchRoll will block for several milliseconds while the underlying function mechanisms sends a request to the VN-100 sensor over the serial port and waits for a response. If it is important to not block the thread, consider only retrieving the latest asynchronous data packet received from the sensor by calling the function vn100_getCurrentAsyncData. An example of using this function may be found in windows_async.c.
#include <stdio.h> #include <tchar.h> #include "vectornav.h" /* Change the connection settings to your configuration. */ const char* const COM_PORT = "COM1"; const int BAUD_RATE = 115200; int _tmain(int argc, _TCHAR* argv[]) { VnYpr ypr; Vn100 vn100; int i; vn100_connect(&vn100, COM_PORT, BAUD_RATE); for (i = 0; i < 10; i++) { vn100_getYawPitchRoll(&vn100, &ypr); printf("YPR: %+#7.2f %+#7.2f %+#7.2f\n", ypr.yaw, ypr.pitch, ypr.roll); Sleep(1000); } vn100_disconnect(&vn100); return 0; }