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/sensor/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 <inttypes.h>
void asciiAsyncMessageReceived(
void *userData,
VnUartPacket *packet,
size_t runningIndex);
void asciiOrBinaryAsyncMessageReceived(
void *userData,
VnUartPacket *packet,
size_t runningIndex);
int processErrorReceived(char* errorMessage, VnError errorCode);
int main(void)
{
char modelNumber[30];
char strConversions[50];
uint32_t oldHz, newHz;
VnAsciiAsync asyncType;
VnError error;
const char SENSOR_PORT[] = "COM1";
const uint32_t SENSOR_BAUDRATE = 115200;
return processErrorReceived("Error connecting to sensor.", error);
return processErrorReceived("Error reading model number.", error);
printf("Model Number: %s\n", modelNumber);
return processErrorReceived("Error reading yaw pitch roll.", error);
str_vec3f(strConversions, ypr);
printf("Current YPR: %s\n", strConversions);
return processErrorReceived("Error reading orientation and IMU data.", error);
printf("Current YPR: %s\n", strConversions);
str_vec3f(strConversions, reg.
mag);
printf("Current Magnetic: %s\n", strConversions);
str_vec3f(strConversions, reg.
accel);
printf("Current Acceleration: %s\n", strConversions);
str_vec3f(strConversions, reg.
gyro);
printf("Current Angular Rates: %s\n", strConversions);
return processErrorReceived("Error reading async data output frequency.", error);
return processErrorReceived("Error writing async data output frequency.", error);
return processErrorReceived("Error reading async data output frequency.", error);
printf("Old Async Frequency: %d Hz\n", oldHz);
printf("New Async Frequency: %d Hz\n", newHz);
return processErrorReceived("Error reading VPE basic control.", error);
printf("Old Heading Mode: %s\n", strConversions);
return processErrorReceived("Error writing VPE basic control.", error);
return processErrorReceived("Error reading VPE basic control.", error);
printf("New Heading Mode: %s\n", strConversions);
return processErrorReceived("Error writing to async data output type.", error);
return processErrorReceived("Error reading async data output type.", error);
strFromVnAsciiAsync(strConversions, asyncType);
printf("ASCII Async Type: %s\n", strConversions);
printf("Starting sleep...\n");
&bor,
ASYNCMODE_PORT1,
200,
COMMONGROUP_TIMESTARTUP | COMMONGROUP_YAWPITCHROLL,
TIMEGROUP_NONE,
IMUGROUP_NONE,
GPSGROUP_NONE,
ATTITUDEGROUP_NONE,
INSGROUP_NONE);
return processErrorReceived("Error writing binary output 1.", error);
printf("Starting sleep...\n");
return processErrorReceived("Error disconnecting from sensor.", error);
return 0;
}
void asciiAsyncMessageReceived(
void *userData,
VnUartPacket *packet,
size_t runningIndex)
{
char strConversions[50];
(userData);
(runningIndex);
if (VnUartPacket_type(packet) != PACKETTYPE_ASCII)
return;
if (VnUartPacket_determineAsciiAsyncType(packet) != VNYPR)
return;
str_vec3f(strConversions, ypr);
printf("ASCII Async YPR: %s\n", strConversions);
}
void asciiOrBinaryAsyncMessageReceived(
void *userData,
VnUartPacket *packet,
size_t runningIndex)
{
char strConversions[50];
(userData);
(runningIndex);
if (VnUartPacket_type(packet) == PACKETTYPE_ASCII && VnUartPacket_determineAsciiAsyncType(packet) == VNYPR)
{
str_vec3f(strConversions, ypr);
printf("ASCII Async YPR: %s\n", strConversions);
return;
}
if (VnUartPacket_type(packet) == PACKETTYPE_BINARY)
{
uint64_t timeStartup;
if (!VnUartPacket_isCompatible(packet,
COMMONGROUP_TIMESTARTUP | COMMONGROUP_YAWPITCHROLL,
TIMEGROUP_NONE,
IMUGROUP_NONE,
GPSGROUP_NONE,
ATTITUDEGROUP_NONE,
INSGROUP_NONE))
return;
str_vec3f(strConversions, ypr);
printf("Binary Async TimeStartup: %" PRIu64 "\n", timeStartup);
printf("Binary Async YPR: %s\n", strConversions);
return;
}
}
int processErrorReceived(char* errorMessage, VnError errorCode)
{
char errorCodeStr[100];
strFromVnError(errorCodeStr, errorCode);
printf("%s\nERROR: %s\n", errorMessage, errorCodeStr);
return -1;
}