Phidget Basic Compass Bearing

C, C++, and Visual C++
Post Reply
Neutronito
Fresh meat
Posts: 3
Joined: Sun Nov 13, 2022 11:12 pm
Contact:

Phidget Basic Compass Bearing

Post by Neutronito »

Hello,

I have a Phidget Basic 1042_0, and I was wondering if I would be able to use the library to find the compass bearing, or if I need to run the calculations myself. Using the phidget control panel on Windows, I can see the compass bearing under the Spatial tab, so I know you have the software available to do this. According to this post, your libraries should now be able to do these calculations for me, but the example is in Python, and I can't seem to find any information on how this works for C in the API.

Any help would be greatly appreciated!
User avatar
Patrick
Lead Developer
Posts: 634
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Phidget Basic Compass Bearing

Post by Patrick »

Hi,

You'll need to open the spatial channel, and use the getEulerAngles() function. The compass bearing is the yaw. Make sure you use the compass calibration program first, to flash calibration for your setup into the board.

-Patrick
Neutronito
Fresh meat
Posts: 3
Joined: Sun Nov 13, 2022 11:12 pm
Contact:

Re: Phidget Basic Compass Bearing

Post by Neutronito »

Hello,

Thank you for your reply!
I can't figure out how to use the getEulerAngles function however, I've had a look at the C API documentation for the 1042 and I can't find any mention of this function. Is there any chance you could tell me how to use it, or perhaps I am not looking for the documentation in the right spot.

Thanks again.
jdecoux
Labview Developer
Posts: 180
Joined: Mon Nov 13, 2017 10:20 am
Contact:

Re: Phidget Basic Compass Bearing

Post by jdecoux »

1042 is an older Phidget that doesn't support new features such as internal heading calculation and tracking.

In this case, you will have to do some math, or migrate to an MOT1102, with accompanying VINT hub.
User avatar
Patrick
Lead Developer
Posts: 634
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Phidget Basic Compass Bearing

Post by Patrick »

Have a look at the Spatial C# example code to see how the Compass calculation is done from accelerometer and magnetometer data:

https://www.phidgets.com/downloads/phid ... ows_Ex.zip

Code: Select all

//Roll Angle - about axis 0
//  tan(roll angle) = gy/gz
//  Use Atan2 so we have an output os (-180 - 180) degrees
double rollAngle = Math.Atan2(gravity[1], gravity[2]);

//Pitch Angle - about axis 1
//  tan(pitch angle) = -gx / (gy * sin(roll angle) * gz * cos(roll angle))
//  Pitch angle range is (-90 - 90) degrees
double pitchAngle = Math.Atan(-gravity[0] / (gravity[1] * Math.Sin(rollAngle) + gravity[2] * Math.Cos(rollAngle)));

//Yaw Angle - about axis 2
//  tan(yaw angle) = (mz * sin(roll) – my * cos(roll)) /
//                   (mx * cos(pitch) + my * sin(pitch) * sin(roll) + mz * sin(pitch) * cos(roll))
//  Use Atan2 to get our range in (-180 - 180)
//
//  Yaw angle == 0 degrees when axis 0 is pointing at magnetic north
double yawAngle = Math.Atan2(magField[2] * Math.Sin(rollAngle) - magField[1] * Math.Cos(rollAngle), magField[0] * Math.Cos(pitchAngle) + magField[1] * Math.Sin(pitchAngle) * Math.Sin(rollAngle) + magField[2] * Math.Sin(pitchAngle) * Math.Cos(rollAngle));
-Patrick
Neutronito
Fresh meat
Posts: 3
Joined: Sun Nov 13, 2022 11:12 pm
Contact:

Re: Phidget Basic Compass Bearing

Post by Neutronito »

Hi all,

Thank you for your replies, greatly appreciated! I was able to adapt the C# example code for C and get the compass bearing, so all is good now :D .

Thank you once again for your time.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests