This example will connect to two VectorNav sensors and display the shortest angle difference (principle rotation angle) between the orientations reported by the two sensors. Such a scenario is useful for applications involving alignment between two sensors.
Visual Studio (Windows)
- Open the solution file for your specific Visual Studio version located at
<root>/net/examples/angle_difference/projects/vs20XX/angle_difference.sln.
- Open the project file
Program.cs and edit the SensorPort1, SensorPort2, SensorBaudrate1 and SensorBaudrate2 constants at the top of the Main() method to the settings used by your attached VectorNav sensors.
- Build the entire solution by going to the menu
BUILD -> Build Solution.
- Right-click the project
angle_difference and select Debug -> Start new instance.
Make (Linux)
- You will first need to open the file
<root>/net/examples/angle_difference/Program.cs and edit the SensorPort and SensorBaudrate constants at the top of the Main() method to the settings used by your attached VectorNav sensors.
- Open a terminal and change to the directory
<root>/net/examples/angle_difference .
- To build the example, run the command
make .
- Run the example by executing the command
sudo ./angle_difference . Note that running the command using sudo is required since administrator privileges are required to access the serial ports on Linux.
class Program
{
static void Main(string[] args)
{
const float MaxAlignmentErrorInDegs = 10.0f;
const string SensorPort1 = "COM1";
const UInt32 SensorBaudrate1 = 115200;
const string SensorPort2 = "COM2";
const UInt32 SensorBaudrate2 = 115200;
var ez1 = EzAsyncData.Connect(SensorPort1, SensorBaudrate1);
var ez2 = EzAsyncData.Connect(SensorPort2, SensorBaudrate2);
for (var i = 0; i < 50; i++)
{
Thread.Sleep(200);
var cd1 = ez1.CurrentData;
var cd2 = ez2.CurrentData;
if (!cd1.HasAnyAttitude || !cd2.HasAnyAttitude)
{
Console.WriteLine("Attitude data from both sensors is not available.");
continue;
}
var q1 = cd1.AnyAttitude.Quat;
var q2 = cd2.AnyAttitude.Quat;
var rotationDiff = q1 - q2;
var angleDiff = rotationDiff.PrincipleRotationAngleInDegs();
var passFailMsg = angleDiff > MaxAlignmentErrorInDegs ? "FAIL" : "PASS";
Console.WriteLine("Angle Diff: {0} {1}", angleDiff, passFailMsg);
}
ez1.Disconnect();
ez2.Disconnect();
}
}