1044 User Guide: Difference between revisions

From Phidgets Support
(23 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOINDEX__
<metadesc>The PhidgetSpatial 3/3/3 Precision has a 3-axis accelerometer, gyroscope and compass with high resolution readings at low magnitudes.</metadesc>
[[Category:UserGuide]]
[[Category:UserGuide]]
{{UserguideTOC|1044.jpg|1044}}
==Getting Started==
==Getting Started==
{{UGIntro|1044}}
*[{{SERVER}}/products.php?product_id=1044 1044 Spatial Phidget]
*USB cable and computer


===Checking the Contents===
{{UGbox|
'''You should have received:'''
* A PhidgetSpatial 3/3/3 High Resolution
* A Mini-B USB cable
|||}}


===Connecting the Pieces===
Next, you will need to connect the pieces:
{{UGbox|
[[Image:1056_0_Connecting_The_Hardware.jpg|500px|right|link=]]
Connect the PhidgetSpatial 3/3/3 to your PC using the Mini-B USB cable.
# Connect your device to your computer using the USB cable.
|
[[File:1056_0_Connecting_The_Hardware.jpg|400px|link=]]
||}}


===Testing Using Windows 2000 / XP / Vista / 7===
<br clear="all">
{{UGIntroDone|1044}}


{{UGwin}}
==Using the 1044==


===Running Phidgets Sample Program===
{{UGcontrolpanel|1044}}


{{UGwin2|'''Spatial-full'''}}
{{ugAccelerometer|1044|}}


{{UGbox|
{{ugGyroscope|1044}}
Double Click on the [[File:Ph.jpg|link=]] icon to activate the Phidget Control Panel and make sure that the '''Phidget Spatial 3/3/3''' is properly attached  to your PC.
|[[File:1042_0_Control_Panel.jpg|400px|link=]]
|
# Double Click on '''Phidget Spatial 3/3/3''' in the Phidget Control Panel to bring up Spatial-full and check that the box labelled Attached contains the word True.
# You can adjust the Data Rate by moving the slider.
# Move the 1044 board around and you should see the data change to reflect the change of position along the 3 axes.
|[[File:1042_0_Spatial_Screen.jpg|400px|link=]]
}}


===Testing Using Mac OS X===
{{ugMagnetometer|1044}}


{{UGmac|Phidget Spatial 3/3/3|Spatial-full}}
{{ugSpatial|1044}}


===Using Linux===
{{ugAddressingInformation}}


{{UGlinux}}
{{ugUsingYourOwnProgram|This Phidget is compatible with the following examples:
 
* {{ExampleLink|Spatial}}
===Using Windows Mobile / CE 5.0 / CE 6.0===
* {{ExampleLink|Accelerometer}}
 
* {{ExampleLink|Gyroscope}}
{{UGce}}
* {{ExampleLink|Magnetometer}}.
}}


==Technical Details==
==Technical Details==


===High Resolution Mode===
===Using Quarternion Algorithms===


When the PhidgetSpatial High Resolution 3/3/3 measures an acceleration value with magnitude less than 2g, it will acquire its data from a higher precision accelerometer chip. For these measurements, the average white noise on each axis will be reduced by approximately a factor of ten, and the resolution will increase from 976 μg to 76 μg. Likewise, when the gyroscope measures a rotation value with magnitude less than 300 °/s on the Z-axis or 400 °/s on the X or Y-axis, the noise per axis will be approximately six times lower, and the resolution will increase from 0.07 °/s to 0.02 °/s.
====What is Quarternion?====
The transition from normal to high precision or vice-versa is seamless, with no additional code or equations needed.
For the 1044_1, we have added support for quarternions which can be used instead of raw acceleration, gyroscope and magnetometer data.  


===3-Axis Accelerometer===
[[Image:quarternion.jpg|link=]]


The PhidgetSpatial 3/3/3 has a 3-Axis accelerometer that can measure ±8 g (±78 m/s2) per axis. It will measure both dynamic acceleration (change in velocity) and static acceleration (gravity vector).
Quarternions use three variables (X, Y and Z) to specify the tilt of an axis, and one additional variable (W) to specify the rotation around that axis. The main advantage of using quarternions with Phidgets is that you don't need to manually calculate heading using data from all three sensors. It also avoids problems like [https://en.wikipedia.org/wiki/Gimbal_lock#In_applied_mathematics gimbal lock] that can occur in situations where you are adding rotation angles (pitch, roll and yaw) together in real-time. Quarternions are also the preferred rotation system for programs that deal with 3D objects, like {{ARTICLE|UsingPhidgetsWithUnity|Unity}}. Quarternions are not meant to be modified directly, instead the program or library that uses them will often have functions that perform calculations using them.  


For more information on how to use the accelerometer, check the [[Accelerometer Primer]].
====How to Get Quarternions from the 1044_1====


===3-Axis Gyroscope===
In order to use quarternions, you need to use the {{Code|Spatial}} object instead of the individual {{Code|Accelerometer}}, {{Code|Gyroscope}} and {{Code|Magnetometer}} objects. Normally you'd use the {{Code|SpatialData}} event to have your program respond to the Phidget's motion but to get updates in quarternions, use the {{Code|AlgorithmData}} event.


For more information on the gyroscope, see the [[Gyroscope Primer]].
For specific function and variable names, see the {{Phidget22API|Phidget API}} for the 1044 Spatial object in the language of your choice. Here is a quick overview of the new properties and methods available:


===3-Axis Magnetometer (Compass)===
{{Code|Algorithm}} - This property allows you to choose between the AHRS and IMU algorithm (it is AHRS by default). The main difference is that IMU does not use magnetometer data, so it may perform better in applications with heavy electromagnetic noise.


The magnetometer reports the sum of all magnetic fields acting on the 1044 device. The earth’s magnetic field is only one source that affects this measurement. In order to get accurate bearing data from the magnetometer - ie. to find magnetic north as a compass - any interfering magnetic effects need to be calibrated out. For more information about calibration, see the [[#Magnetic Error Correction (Calibration)|section below]], or the [[Compass Primer]].
{{Code|AlgorithmMagnetometerGain}} - If using AHRS, you can lower the value of this property to reduce sensor noise at the cost of slowing down response time. Default value is 0.005.


Any magnetic field that is stationary with respect to the 1044 device, and less than ± 3 Gauss, can be calibrated out of the magnetic field measurement. This includes both hard and soft iron effects caused by nearby ferrous and magnetic materials. Interfering magnetic fields that vary in strength and orientation with respect to the 1044 device cannot be easily calibrated out.


Magnetic field data will become unavailable during every other sample as the compass performs internal calibrations. When this happens, the magneticField array in the SpatialData structure will either have a length of zero, or each element will equal <code>PUNK_DBL</code>, depending on the API being used. This needs to be handled explicitly in the event handling code to avoid erroneous program behavior. The maximum sampling rate of the compass is 125 Hz.
{{Code|zeroAlgorithm}} - This method will zero the AHRS heading to match the current reading from the compass.  


====Converting from Quarternions into Pitch, Roll and Yaw====


====Magnetic Error Correction (Calibration)====
If you're not using a library that explicitly supports quarternions, you may want to convert this data into pitch, roll and yaw (also called Euler angles). The code sample below shows how you would use the x,y,z and w quarternion values to calculate pitch, roll and yaw in C#.


In order to get numbers of useful accuracy from the 1044's compass you will need to provide calibration parameters.  To make determining them easy, we distribute a program with our drivers that does this for you.
<syntaxhighlight lang=cSharp>


'''To calibrate your compass:'''
private void convert(Quarternion q) {
[[image:calibration1.png|thumb|200px|link={{SERVER}}/wiki/images/3/32/Calibration1.png]]
*Navigate to the Phidgets installation folder on your computer.  Open the 'examples' folder and find the Compass Calibrator program.
<br clear = "all">
[[image:calibration2.png|thumb|200px|link={{SERVER}}/wiki/images/b/b5/Calibration2.png]]
*Start the program and find the link in the Settings/Status text box.  Go to the website listed.  (http://www.ngdc.noaa.gov/geomag-web/#igrfwmm)
<br clear = "all">
[[image:calibration3.png|thumb|200px|link={{SERVER}}/wiki/images/3/3a/Calibration3.png]]
*Select your country and city.  Click 'Get Location' and then 'Compute'.  A table of values will show up in an overlaid window.  The value you will need is the 'Total Field' value in nT.
<br clear="all">
[[image:calibration4.png|thumb|200px|link={{SERVER}}/wiki/images/0/02/Calibration4.png]]
*Enter the magnetic field value into the calibration program.
*Depending on what your application is this step as well as the next step might be a bit different.  If you are intending on mounting the 1044 onto a large vehicle such as a car then you should mount the 1044 securely to the vehicle in its final intended position then check the 2-axis bubble, click the 'Start' button.
*If you are using a smaller, more easily handled vehicle such as a small robot (something you could physically pick up) you will mount the 1044 and use the 3-axis calibration instead.  Click 'Start'.
<br clear="all">
[[image:calibration5.png|thumb|200px|link={{SERVER}}/wiki/images/6/67/Calibration5.png]]
*Rotate the compass around (including whatever equipment you have mounted it to) such that the red dots being generated on screen outline as much of a full sphere (in 3-axis) as possible.  This will take several minutes.  Being perfect is not necessary but try to be as thorough as time permits.  Once done, click stop.
*If you are in a large vehicle, you will be aiming to fill out a disc instead of a sphere.  This can be done by simply driving around for a few minutes making sure to do complete 360° turns in the process.
<br clear="all">
[[image:calibration6.png|thumb|200px|link={{SERVER}}/wiki/images/8/88/Calibration6.png]]
*The calibration tool will automatically write these values to the Flash memory on board and are remembered until the device is calibrated again.
<br clear="all">


For more information on magnetometers (compasses), see the [[Compass Primer]].
double roll = (float)Math.Atan2(2f * (q.X * q.W + q.Y * q.Z), 1 - 2f * (q.X * q.X + q.Y * q.Y));
double pitch = (float)Math.Asin(2f * (q.W * q.Y - q.Z * q.X));
double yaw = (float)Math.Atan2(2f * (q.W * q.Z + q.X * q.Y), 1 - 2f * (q.Y * q.Y + q.Z * q.Z));


==API==
// Convert radians to degrees
{{UGapih}}
yaw = yaw * 180 / Math.PI;
pitch = pitch * 180 / Math.PI;
roll = roll * 180 / Math.PI;


===Data Structures===
}
<b>
</syntaxhighlight>
SpatialData {
:double acceleration[3];
:double angularRate[3];
:double magneticField[3];
:Timestamp time;
};


Timestamp {
You'll need a math library to perform the [https://en.wikipedia.org/wiki/Atan2 atan2] and arcsin functions.
:int seconds;    -time since attach event
:int microseconds;  -time since last second
};
</b>


The SpatialData Structure is used by the OnSpatialData event. This contains acceleration data, angular rate data, magnetic field data, and a timestamp. The timestamp is an accurate measurement streamed from the hardware,and can be trusted over a local software timestamp. This timestamp is generally used for integrating angular rate into a heading over time.
===High Resolution Mode===
When the 1044 measures an acceleration value with magnitude less than 2g, it will acquire its data from a higher precision accelerometer chip. For these measurements, the average white noise on each axis will be reduced by approximately a factor of ten, and the resolution will increase from 976 μg to 76 μg. Likewise, when the gyroscope measures a rotation value with magnitude less than 300 °/s on the Z-axis or 400 °/s on the X or Y-axis, the noise per axis will be approximately six times lower, and the resolution will increase from 0.07 °/s to 0.02 °/s.
The transition from normal to high precision or vice-versa is seamless, with no additional code or equations needed.


===Properties===
===3-Axis Accelerometer===
{{UGapi|int AccelerationAxisCount() [get] : Constant <nowiki>=</nowiki> 3
The 1044 has a 3-Axis accelerometer that can measure ±8 g's (±78 m/s2) per axis.  It will measure both dynamic acceleration (change in velocity) and static acceleration (gravity vector).
|Returns the number of axes the PhidgetSpatial can measure acceleration on.
}}


{{UGapi|double Acceleration (int AxisIndex) [get] : Units <nowiki>=</nowiki> g (standard gravity <nowiki>=</nowiki> 9.81m/s2)
====Orientation====
|Returns the acceleration of an axis. At a standstill each axis will measure between -1.0 and 1.0 g’s depending on orientation - the effect of gravity.
This value will always be between AccelerationMin and AccelerationMax.
}}


{{UGapi|double AccelerationMax (int AxisIndex) [get] : Constant <nowiki>=</nowiki> 8.1g
[[File:1041 0 Axis Diagram.jpg|500px|link=]]
|Returns the maximum acceleration value that this axis will report.  Acceleration can be accurately measured up to 8.0g - any value past this will be reported as 8.1g, which represents saturation.  If the acceleration data is equal to AccelerationMax, it should be treated as suspect, as the real acceleration could be far greater than the reported number.
}}


{{UGapi|double AccelerationMin (int AxisIndex) [get] : Constant <nowiki>=</nowiki> -8.1g
When working with an accelerometer it is important to know which is the positive and negative direction on each of the axesThis can be determined by orienting the accelerometer along each axis and checking the output. The above image shows what the axis readings should be for each orientation of the 1044.
|Returns the maximum negative acceleration value that this axis will reportNegative acceleration can be accurately measured up to -8.0g - any value past this will be reported as -8.1g, which represents saturation.  If the acceleration data is equal to AccelerationMin, it should be treated as suspect, as the real acceleration could be far greater than the reported number.
}}


{{UGapi|int GyroAxisCount() [get] : Constant <nowiki>=</nowiki> 3
|Returns the number of axes the PhidgetSpatial can measure angular momentum on.
}}


{{UGapi|int AngularRate(int AxisIndex) [get] : Units <nowiki>=</nowiki> °/s (degrees/second)
For more information on how to use the accelerometer, check the [[Accelerometer Primer]].
|Returns the angular momentum on an axis.  This value will always be between AngularRateMax and AngularRateMin.  If the value is equal to AngularRateMax or Min, the data should be treated as suspect, as the sensor may be saturated.
}}


{{UGapi|int AngularRateMax(int AxisIndex) [get] : Constant <nowiki>=</nowiki> 2000°/s
===3-Axis Gyroscope===
|Returns the maximum angular momentum that this axis will report. If the angular rate is reported as 2000°/s, this should be considered saturated, and any heading integration will have errors.
For more information on the gyroscope, see the [[Gyroscope Primer]].
}}


{{UGapi|int AngularRateMin(int AxisIndex) [get] : Constant <nowiki>=</nowiki> -2000°/s
===3-Axis Magnetometer (Compass)===
|Returns the maximum negative angular momentum that this axis will report. If the angular rate is reported as -2000°/s, this should be considered saturated, and any heading integration will have errors.
The magnetometer reports the sum of all magnetic fields acting on the 1044. The earth's magnetic field is only one source that affects this measurement. In order to get accurate bearing data from the magnetometer - (i.e. to find magnetic north as a compass) any interfering magnetic effects need to be calibrated out. For more information about calibration, see the [[#Magnetic Error Correction (Calibration)|section below]], or the [[Compass Primer]].
}}


{{UGapi|int CompassAxisCount() [get] : Constant <nowiki>=</nowiki> 3
Any magnetic field that is stationary with respect to the 1044, and less than ± 3 Gauss, can be calibrated out of the magnetic field measurement. This includes both hard and soft iron effects caused by nearby ferrous and magnetic materials. Interfering magnetic fields that vary in strength and orientation with respect to the 1044 cannot be easily calibrated out.
|Returns the number of axes the PhidgetSpatial can measure magnetic field strength on.
}}


{{UGapi|int MagneticField(int AxisIndex) [get] : Units <nowiki>=</nowiki> G (gauss)
Magnetic field data will become unavailable during every other sample as the compass performs internal calibrations. When this happens, the magneticField array in the SpatialData structure will either have a length of zero, or each element will equal <code>PUNK_DBL</code>, depending on the API being used. This needs to be handled explicitly in the event handling code to avoid erroneous program behavior. The maximum sampling rate of the compass is 125 Hz.
|Returns the magnetic field on an axis. This value will always be between MagneticFieldMax and MagneticFieldMin. If the reported value is equal to MagneticFieldMax or Min, the data should be treated as suspect, as the sensor may be saturated. Magnetic field measurements can be combined to calculate compass bearing (magnetic north).


If your data rate is set to 4ms (the default is 8ms), Magnetic field data will become unavailable for every other sample. When this happens, this function will return <code>EPHIDGET_UNKNOWNVAL</code>, or throw an <code>UNKNOWNVAL</code> exception, depending on the API being used. Also, the magneticField array in the SpatialData structure will either have a length of zero, or each element will equal <code>PUNK_DBL</code>, depending on the API being used. This needs to be handled explicitly in the event handling code to avoid erroneous program behavior when using a sampling rate of 4ms.
}}


{{UGapi|int MagneticFieldMax(int AxisIndex) [get] : Constant <nowiki>=</nowiki> 5.6G
{{compasscalibration|1044}}
|Returns the maximum magnetic field that this axis will report. Magnetic field strength can be accurately measured up to 5.5G - any value past this will be reported as 5.6G, which represents saturation.  If the magnetic field data is equal to MagneticFieldMax, it should be treated as suspect, as the real magnetic field could be far greater than the reported number.
}}


{{UGapi|int MagneticFieldMin(int AxisIndex) [get] : Constant <nowiki>=</nowiki> -5.6G
For more information on magnetometers (compasses), see the [[Compass Primer]].
|Returns the maximum negative magnetic field that this axis will report. Magnetic field strength can be accurately measured down to -5.5G - any value past this will be reported as -5.6G, which represents saturation.  If the magnetic field data is equal to MagneticFieldMin, it should be treated as suspect, as the real magnetic field could be far greater than the reported number.
}}
 
{{UGapi|int DataRate () [get,set] : Units <nowiki>=</nowiki> ms (milliseconds)
|Gets/sets the data rate. This is corresponds to the time interval at which SpatialData events will be fired. This is bound by DataRateMax and DataRateMin. When set to less then the maximum data rate, data is still sampled at the maximum rate, and averaged before being sent to the user.
Supported data rates are: 4ms, 8ms and every multiple of 8 up to 1000ms (ie. 8, 16, 24, 32, etc). The default data rate is 8ms.
Data rate is limited to at most 16ms when opening over the Phidget Webservice. Actual data rate will depend on network latency.
}}
 
{{UGapi|int DataRateMax () [get] : Constant <nowiki>=</nowiki> 4ms
|The maximum supported data rate.
}}
 
{{UGapi|int DataRateMin () [get] : Constant <nowiki>=</nowiki> 1000ms
|The minimum supported data rate.
}}
 
===Functions===
{{UGapi|void zeroGyro();
|Re-zeroes the gyroscope. This takes 1-2 seconds of gyro samples and uses this data as a new zero point. The 1044 must remain stationary during the zeroing process. The angular rate will be reported as zero during zeroing.
}}
 
===Events===
{{UGapi|OnSpatialData (SpatialData[] data) [event]
|An event issued at the specified data rate. If the data rate is set faster then 8ms, then there will be multiple items in the data array - use the timestamp field to get the timing data. When the data rate is <nowiki>>=</nowiki> 8ms, there will only beone item in the data array.
 
If your data rate is set to 4ms (the default is 8ms), Magnetic field data will become unavailable for every other sample. When this happens, this function will return <code>EPHIDGET_UNKNOWNVAL</code>, or throw an <code>UNKNOWNVAL</code> exception, depending on the API being used. Also, the magneticField array in the SpatialData structure will either have a length of zero, or each element will equal <code>PUNK_DBL</code>, depending on the API being used. This needs to be handled explicitly in the event handling code to avoid erroneous program behavior when using a sampling rate of 4ms.
}}


==Product History==
{{UGnext|}}
{{UGhist}}
{{UGrow|September 2012|0|400|Product Release}}
{{UGrow|September 2012|0|401|Fixed USB bug}}

Revision as of 19:57, 10 June 2019


Getting Started

Welcome to the 1044 user guide! In order to get started, make sure you have the following hardware on hand:


Next, you will need to connect the pieces:

1056 0 Connecting The Hardware.jpg
  1. Connect your device to your computer using the USB cable.


Now that you have everything together, let's start using the 1044!

Using the 1044

Phidget Control Panel

In order to demonstrate the functionality of the 1044, the Phidget Control Panel running on a Windows machine will be used.


The Phidget Control Panel is available for use on both macOS and Windows machines.

Windows

To open the Phidget Control Panel on Windows, find the Ph.jpg icon in the taskbar. If it is not there, open up the start menu and search for Phidget Control Panel

Windows PhidgetTaskbar.PNG

macOS

To open the Phidget Control Panel on macOS, open Finder and navigate to the Phidget Control Panel in the Applications list. Double click on the Ph.jpg icon to bring up the Phidget Control Panel.


For more information, take a look at the getting started guide for your operating system:


Linux users can follow the getting started with Linux guide and continue reading here for more information about the 1044.

First Look

After plugging the 1044 into your computer and opening the Phidget Control Panel, you will see something like this:

1044 Panel.jpg


The Phidget Control Panel will list all connected Phidgets and associated objects, as well as the following information:

  • Serial number: allows you to differentiate between similar Phidgets.
  • Channel: allows you to differentiate between similar objects on a Phidget.
  • Version number: corresponds to the firmware version your Phidget is running. If your Phidget is listed in red, your firmware is out of date. Update the firmware by double-clicking the entry.


The Phidget Control Panel can also be used to test your device. Double-clicking on an object will open an example.

Accelerometer

Double-click on the Accelerometer object in order to run the example:

1044 Accelerometer Example.jpg


General information about the selected object will be displayed at the top of the window. You can also experiment with the following functionality:

  • Modify the change trigger and/or data interval value by dragging the sliders. For more information on these settings, see the data interval/change trigger page.
  • The measured values reported in g-force can be seen via labels as well as graphical dials. Try tilting the 1044 in different directions to see the labels and graphics change.
  • An extremely accurate timestamp is also reported with the g-force values.


Gyroscope

Double-click on the Gyroscope object in order to run the example:

1044 Gyroscope Example.jpg


General information about the selected object will be displayed at the top of the window. You can also experiment with the following functionality:

  • Modify the change trigger and/or data interval value by dragging the sliders. For more information on these settings, see the data interval/change trigger page.
  • The Zero Gyro button is used to compensate for the drift that is inherent to all gyroscopes. The gyroscope primer has more information about this subject.
  • The measured values reported in degrees per second can be seen via labels as well as graphical dials. Try rotating the 1044 in different directions to see the labels and graphics change.
  • An extremely accurate timestamp is also reported with the g-force values.


Magnetometer

Double-click on the Magnetometer object in order to run the example:

1044 Magnetometer Example.jpg


General information about the selected object will be displayed at the top of the window. You can also experiment with the following functionality:

  • Modify the change trigger and/or data interval value by dragging the sliders. For more information on these settings, see the data interval/change trigger page.
  • Use the Set Params... button to set the calibration parameters. For more information about calibration, see the technical section.
  • The measured values reported in Gauss can be seen via labels as well as a graphical diagram. The diagram can help you visualize the magnetic field vector.
  • An extremely accurate timestamp is also reported with the Gauss values.


Spatial

Double-click on the Spatial object in order to run the example:

1044 Spatial Example.jpg


The Spatial example demonstrates that you can receive data from the accelerometer, gyroscope, and magnetometer all at once by using the Spatial object rather than the other three objects individually.

Finding The Addressing Information

Before you can access the device in your own code, and from our examples, you'll need to take note of the addressing parameters for your Phidget. These will indicate how the Phidget is physically connected to your application. For simplicity, these parameters can be found by clicking the button at the top of the Control Panel example for that Phidget.

The locate Phidget button is found in the device information box

In the Addressing Information window, the section above the line displays information you will need to connect to your Phidget from any application. In particular, note the Channel Class field as this will be the API you will need to use with your Phidget, and the type of example you should use to get started with it. The section below the line provides information about the network the Phidget is connected on if it is attached remotely. Keep track of these parameters moving forward, as you will need them once you start running our examples or your own code.

All the information you need to address your Phidget

Using Your Own Program

You are now ready to start writing your own code for the device. The best way to do that is to start from our [https://www.phidgets.com?view=code_samples&product_id=This Phidget is compatible with the following examples:

Code Samples].

Select your programming language of choice from the drop-down list to get an example for your device. You can use the options provided to further customize the example to best suit your needs.

link=https://www.phidgets.com?view=code_samples&product_id=This Phidget is compatible with the following examples: * Spatial Examples * Accelerometer Examples * Gyroscope Examples * Magnetometer Examples.


Once you have your example, you will need to follow the instructions on the page for your programming language to get it running. To find these instructions, select your programming language from the Programming Languages page.

Technical Details

Using Quarternion Algorithms

What is Quarternion?

For the 1044_1, we have added support for quarternions which can be used instead of raw acceleration, gyroscope and magnetometer data.

Quarternion.jpg

Quarternions use three variables (X, Y and Z) to specify the tilt of an axis, and one additional variable (W) to specify the rotation around that axis. The main advantage of using quarternions with Phidgets is that you don't need to manually calculate heading using data from all three sensors. It also avoids problems like gimbal lock that can occur in situations where you are adding rotation angles (pitch, roll and yaw) together in real-time. Quarternions are also the preferred rotation system for programs that deal with 3D objects, like Unity. Quarternions are not meant to be modified directly, instead the program or library that uses them will often have functions that perform calculations using them.

How to Get Quarternions from the 1044_1

In order to use quarternions, you need to use the Spatial object instead of the individual Accelerometer, Gyroscope and Magnetometer objects. Normally you'd use the SpatialData event to have your program respond to the Phidget's motion but to get updates in quarternions, use the AlgorithmData event.

For specific function and variable names, see the Phidget22 API for the 1044 Spatial object in the language of your choice. Here is a quick overview of the new properties and methods available:

Algorithm - This property allows you to choose between the AHRS and IMU algorithm (it is AHRS by default). The main difference is that IMU does not use magnetometer data, so it may perform better in applications with heavy electromagnetic noise.

AlgorithmMagnetometerGain - If using AHRS, you can lower the value of this property to reduce sensor noise at the cost of slowing down response time. Default value is 0.005.


zeroAlgorithm - This method will zero the AHRS heading to match the current reading from the compass.

Converting from Quarternions into Pitch, Roll and Yaw

If you're not using a library that explicitly supports quarternions, you may want to convert this data into pitch, roll and yaw (also called Euler angles). The code sample below shows how you would use the x,y,z and w quarternion values to calculate pitch, roll and yaw in C#.

private void convert(Quarternion q) {

double roll = (float)Math.Atan2(2f * (q.X * q.W + q.Y * q.Z), 1 - 2f * (q.X * q.X + q.Y * q.Y));
double pitch = (float)Math.Asin(2f * (q.W * q.Y - q.Z * q.X));
double yaw = (float)Math.Atan2(2f * (q.W * q.Z + q.X * q.Y), 1 - 2f * (q.Y * q.Y + q.Z * q.Z));

// Convert radians to degrees
yaw = yaw * 180 / Math.PI;
pitch = pitch * 180 / Math.PI;
roll = roll * 180 / Math.PI;

}

You'll need a math library to perform the atan2 and arcsin functions.

High Resolution Mode

When the 1044 measures an acceleration value with magnitude less than 2g, it will acquire its data from a higher precision accelerometer chip. For these measurements, the average white noise on each axis will be reduced by approximately a factor of ten, and the resolution will increase from 976 μg to 76 μg. Likewise, when the gyroscope measures a rotation value with magnitude less than 300 °/s on the Z-axis or 400 °/s on the X or Y-axis, the noise per axis will be approximately six times lower, and the resolution will increase from 0.07 °/s to 0.02 °/s. The transition from normal to high precision or vice-versa is seamless, with no additional code or equations needed.

3-Axis Accelerometer

The 1044 has a 3-Axis accelerometer that can measure ±8 g's (±78 m/s2) per axis. It will measure both dynamic acceleration (change in velocity) and static acceleration (gravity vector).

Orientation

1041 0 Axis Diagram.jpg

When working with an accelerometer it is important to know which is the positive and negative direction on each of the axes. This can be determined by orienting the accelerometer along each axis and checking the output. The above image shows what the axis readings should be for each orientation of the 1044.


For more information on how to use the accelerometer, check the Accelerometer Primer.

3-Axis Gyroscope

For more information on the gyroscope, see the Gyroscope Primer.

3-Axis Magnetometer (Compass)

The magnetometer reports the sum of all magnetic fields acting on the 1044. The earth's magnetic field is only one source that affects this measurement. In order to get accurate bearing data from the magnetometer - (i.e. to find magnetic north as a compass) any interfering magnetic effects need to be calibrated out. For more information about calibration, see the section below, or the Compass Primer.

Any magnetic field that is stationary with respect to the 1044, and less than ± 3 Gauss, can be calibrated out of the magnetic field measurement. This includes both hard and soft iron effects caused by nearby ferrous and magnetic materials. Interfering magnetic fields that vary in strength and orientation with respect to the 1044 cannot be easily calibrated out.

Magnetic field data will become unavailable during every other sample as the compass performs internal calibrations. When this happens, the magneticField array in the SpatialData structure will either have a length of zero, or each element will equal PUNK_DBL, depending on the API being used. This needs to be handled explicitly in the event handling code to avoid erroneous program behavior. The maximum sampling rate of the compass is 125 Hz.


Template:Compasscalibration

For more information on magnetometers (compasses), see the Compass Primer.

What to do Next

  • Programming Languages - Find your preferred programming language here and learn how to write your own code with Phidgets!
  • Phidget Programming Basics - Once you have set up Phidgets to work with your programming environment, we recommend you read our page on to learn the fundamentals of programming with Phidgets.