TCM User Manual r09.2
TCM User Manual r09.2
TCM
High-Performance Tilt-Compensated Compass Module
Table of Contents
1 COPYRIGHT & WARRANTY INFORMATION ................................................. 1
2 INTRODUCTION ......................................................................................... 2
3 SPECIFICATIONS ......................................................................................... 3
3.1 Characteristics & Requirements ........................................................... 3
3.2 Mechanical Drawings ............................................................................ 6
4 SET-UP ....................................................................................................... 8
4.1 Electrical Connections ........................................................................... 8
4.2 Installation Location.............................................................................. 9
4.2.1 Operate within the TCM’s dynamic range ................................... 9
4.2.2 Locate away from changing magnetic fields ............................... 9
4.2.3 Mount in a physically stable location .......................................... 9
4.2.4 Location-verification testing ........................................................ 9
4.3 Mechanical Mounting ......................................................................... 10
4.3.1 Pitch and Roll Conventions ........................................................ 10
4.3.2 Mounting Orientation ................................................................ 11
5 USER CALIBRATION .................................................................................. 12
5.1 Magnetic Calibration........................................................................... 13
5.1.1 Full-Range Calibration ................................................................ 15
5.1.2 2D Calibration ............................................................................ 16
5.1.3 Limited Tilt Range Calibration .................................................... 17
5.1.4 Hard-Iron-Only Calibration ........................................................ 18
5.2 Accelerometer Calibration .................................................................. 18
5.2.1 Accelerometer-Only Calibration ................................................ 19
5.2.2 Mag-and-Accel Calibration ........................................................ 20
6 OPERATION WITH TCM STUDIO ............................................................... 21
6.1 Installation .......................................................................................... 21
6.2 Connection Tab ................................................................................... 22
6.2.1 Initial Connection ....................................................................... 22
6.2.2 Changing Baud Rate ................................................................... 22
6.2.3 Changing Modules ..................................................................... 23
6.3 Configuration Tab ............................................................................... 23
6.3.1 Mounting Options ...................................................................... 23
6.3.2 North Reference......................................................................... 24
6.3.3 Endianess ................................................................................... 24
6.3.4 Output ........................................................................................ 25
6.3.5 Enable 3D Model ........................................................................ 25
6.3.6 Filter Setting (Taps) .................................................................... 25
6.3.7 Acquisition Settings.................................................................... 25
6.3.8 HPR During Calibration .............................................................. 26
6.3.9 Calibration Settings .................................................................... 26
List of Figures
Figure 3-1: TCM XB Mechanical Drawing 6
Figure 3-2: TCM XB Pigtailed Cable Drawing 6
Figure 3-3: TCM MB Mechanical Drawing 7
Figure 4-1: Positive & Negative Roll and Pitch Definition 10
Figure 4-2: Mounting Orientations 11
Figure 5-1: 12 Point Full-Range Calibration 15
Figure 5-2: Accelerometer Calibration Starting Orientations 20
Figure 7-1: Datagram Structure 36
Parameter Value
≤65° of pitch after Full-Range
<0.3° rms
Calibration
≤80° of pitch after Full-Range
<0.5° rms
Accuracy Calibration
Heading ≤5° of pitch after 2D calibration <2.0° rms
≤2 times the calibration tilt angle when
<2.0° rms
using limited-tilt calibration2
Resolution 0.1°
Repeatability 0.05° rms
Pitch ± 90°
Range
Roll ± 180°
Pitch 0.2° rms
≤65° of pitch 0.2° rms
Attitude Accuracy
Roll ≤80° of pitch 0.4° rms
≤86° of pitch 1.0° rms
Resolution 0.01°
Repeatability 0.05° rms
3
Maximum Operational Dip Angle 85°
Calibrated Field Range ± 125 µT
Magnetometers Resolution 0.05 µT
Repeatability ± 0.1 µT
Footnotes:
1. Specifications are subject to change. Assumes the TCM is motionless and the local magnetic field
is clean relative to the user calibration.
2. For example, if the calibration was performed over ±10° of tilt, then the TCM would provide <2° rms
accuracy over ±20° of tilt.
3. Performance at maximum operational dip angle will be somewhat degraded.
CAUTION:
Stresses beyond those listed above may cause permanent damage to the device. These are
stress ratings only. Operation of the device at these or other conditions beyond those indicated
in the operational sections of the specifications is not implied.
Parameter Value
TCM XB 3.8 to 9 VDC
Supply Voltage
TCM MB 3.3 to 9 VDC
High Level Input 2.4 V minimum
Low Level Input 0.6 V maximum
TCM XB
Output Voltage Swing ±5.2 V typ., ±5.0 V min.
Communication Tx Output Resistance 300 Ω
Lines High Level Input 2.0 V minimum
Low Level Input 0.8 V maximum
TCM MB
Output Voltage Swing 0 – 3.3 V typical
Tx Output Resistance 330 Ω
@ max. sample rate 20 mA typical
TCM XB
Average @ 8 Hz sample rate 16 mA typical
Current Draw @ max. sample rate 17 mA typical
TCM MB
@ 8 Hz sample rate 13 mA typical
During application of external 120 mA pk, 60 mA avg
Peak Current power over 2 ms
Draw During logical power up/down or 135 mA pk, 60 mA avg
Sync Trigger over 4 ms
Sleep Mode TCM XB 0.3 mA typical
Current Draw TCM MB 0.1 mA typical
Parameter Value
Communication TCM XB RS232 UART
Interface TCM MB CMOS/TTL UART
Communication Protocol PNI Binary
Communication Rate 300 to 115200 baud
Maximum Sample Rate1 ~30 samples/sec
Time to Initial Initial power up <210 ms
Good Data2 Sleep Mode recovery <80 ms
Footnotes:
1. The maximum sample rate is dependent on the strength of the magnetic field,
and typically will be from 25 to 32 samples/sec.
2. FIR taps set to “0”.
Parameter Value
1
Operating Temperature -40C to +85C
Storage Temperature -40C to +85C
Footnote:
1. To meet performance specifications across this range,
recalibration will be necessary as the temperature varies.
Parameter Value
Dimensions TCM XB 35 x 43 x 13 mm
(l x w x h) TCM MB 33 x 31 x 13 mm
TCM XB 6.8 gm
Weight
TCM MB 5.3 gm
TCM XB 9-pin Molex, pn 53780-0970
Connector
TCM MB 4-pin MIL-MAX, pn 850-10-004-10-001000
The default orientation is for the silk-screened arrow to point in the “forward” direction.
TCM XB TCM MB
Pin
Number1 9 Pin Cable Wire 4 Pin
Connector Color Connector
1 GND Black GND
2 GND Gray Vin
3 GND Green UART Tx
4 NC Orange UART Rx
5 NC Violet
6 NC Brown
7 UART Tx Yellow
8 UART Rx Blue
9 Vin Red
Footnote:
1. For the TCM XB, pin #1 is indicated on Figure 3-1, while for the TCM MB, pin
#1 is the pin closest to the corner.
After making the electrical connections, it is a good idea to perform some simple tests to ensure
the TCM is working as expected. See Section 5 for how to operate the TCM with TCM Studio,
or Section 7 for how to operate the TCM using the PNI binary protocol.
Note: Ensure that when attaching the TCM to the host system, the mounting method does not
introduce stresses on the board, as this can affect the performance of the accelerometer, and therefore
also negatively affect heading accuracy.
Note: TCM XB is shown. The Z axis sensor and the connector are on the module’s top surface,
regardless of model.
Number of Samples
Calibration Tilt Range
Accuracy
Mode during Cal Minimum Allowable
Recommend Range
Full Range 0.3° rms >±45° 12 10 – 18
2D Calibration <2° <±5° 12 10 – 18
Limited Tilt <2° over 2x tilt 10 – 18
±5° to ±45° 12
Range range
Restores prior 4 - 18
Hard Iron Only >±3° 6
accuracy
Note: While Figure 5-1 shows the location of the device changing, this is for illustration purposes and
it is best for the location of the device to remain constant while only the orientation is changed.
5.1.2 2D Calibration
A 2D Calibration is intended for very low tilt operation (<5°) where calibrating the TCM
with greater tilt is not practical.
This procedure calibrates for hard and soft iron effects in only two dimensions, and in
general is effective for operation and calibration in the tilt range of -5° to +5°. The
recommended 12 point calibration pattern is a circle of evenly spaced points, as given in
Table 5-3.
Note: TCM Studio v3.X and higher is compatible with the TCM XB, TCM MB and legacy TCM 6, but not
other legacy TCM models. The TCM XB also will work with TCM Studio v3 and higher, while the TCM MB
will work with TCM Studio v4 and higher. The version of Studio is identified in the upper left corner of the
GUI.
The TCM Studio evaluation software communicates with the TCM through the RS232 serial port
of a computer. The TCM MB requires a user-supplied level shifter to make it compatible with the
computer’s RS232 interface.
6.1 Installation
TCM Studio is provided as an executable program which can be downloaded from PNI’s
website. It will work with Windows XP, Windows Vista, Windows 7, and Mac OS X operating
systems. Check the PNI web page at www.pnicorp.com for the latest version.
For Windows computers, copy the TCMStudio.msi file onto your computer. Then, open the
file and step through the Setup Wizard.
For Mac computers, copy the TCMStudio.zip file onto your computer. This automatically
places the application in the working directory of your computer. The Quesa plug-in, also in
the .zip file, needs to be moved to /Library/CFMSupport, if it is not already there.
Note: While the TCM can operate at a baud rate of 230400, a PC serial port normally will not
operate this fast.
Note: No settings will be changed in the module until the <SAVE> button has been selected.
Magnetic
When the <Magnetic> button is selected, heading will be relative to magnetic north.
True
When the <True> button is selected, heading will be relative to true north. In this case,
the declination needs to be set in the “Declination” window.
6.3.3 Endianess
Select either the <Big> or <Little> Endian button. The default setting is <Big>. See
Sections 7.2 and 7.3 for additional information.
6.3.10 Default
Clicking this button restores the TCM Studio program to the factory default settings.
6.3.11 Retrieve
Clicking on this button causes TCM Studio to read the settings from the module and display
them on the screen.
Note: The default settings are recommended for the highest accuracy and quality of calibration.
6.4.1 Samples
Before proceeding, refer to Section 5 for the recommended calibration procedure
corresponding to the calibration method selected on the Configuration tab.
Clicking the <Start> button begins the calibration process.
If “Automatic Sampling” is not checked on the Configuration tab, it is necessary to click
the <Take Sample> button to take a calibration sample point. This should be repeated until
the total number of samples, as set on the Configuration tab, is taken while changing the
orientation of the module between samples as discussed in Section 5.
If “Automatic Sampling” is checked, the module will need to be held steady for a short
time and then a sample automatically will be taken. Once the window indicates the next
number, the module’s orientation should be changed and held steady for the next sample.
Once the pre-set number of samples has been taken (as set on the Configuration tab) the
calibration is complete.
Note: If a calibration is aborted, all the score’s will read “179.80”, and the calibration coefficients
will not be changed. (Clicking the <Save> button will not change the calibration coefficients.)
Mag CalScore
Represents the over-riding indicator of the quality of the magnetometer calibration.
Acceptable scores will be <1 for Full-Range Calibration, <2 for other methods. Note
that it is possible to get acceptable scores for Dist Error and Tilt Error and still have a
rather high Mag CalScore value. The most likely reason for this is the TCM is close to
a source of local magnetic distortion that is not fixed with respect to the module.
Dist Error
Indicates the quality of the sample point distribution, primarily looking for an even yaw
distribution. Significant clumping or a lack of sample points in a particular section can
result in a poor score. The score should be <1 and close to 0.
Tilt Error
Indicates the contribution to the Mag CalScore caused by tilt or lack thereof, and takes
into account the calibration method. The score should be <1 and close to 0.
Tilt Range
This reports the larger of either half the full pitch range or half the full roll range of
sample points. For example, if the module is pitched +10° to -20º, and rolled +25º to -
15º, the Tilt Range value would be 20º, as derived half the full roll range. For Full-
Range Calibration and Hard-Iron-Only Calibration, this should be ≥45°. For 2D
Calibration, this ideally should be ≈2°. For Limited Tilt Range Calibration the value
should be as large a possible given the user’s constraints.
Accel CalScore
Represents the over-riding indicator of the quality of the accelerometer calibration.
Acceptable scores will be <1.
6.4.4 Options
This window indicates how many samples are to be taken and provides real time heading,
pitch, and roll information if “HPR During Calibration” is set to <On>, both as defined on
the Configuration tab.
Audible Feedback
If selected TCM Studio will give an audible signal once a calibration point has been
taken. Note that an audible signal also will occur when the <Start> button is clicked,
but no data will be taken.
6.4.5 Clear
Clear Mag Cal to Factory
This button clears the user’s calibration of the magnetometers. Once selected, the
module reverts to its factory magnetometer calibration. To save this action in
nonvolatile memory, click the <Save> button. It is not necessary to clear the current
calibration in order to perform a new calibration.
Clear Accel Cal to Factory
This button clears the user’s calibration of the accelerometer. Once selected, the
module reverts back to its factory accelerometer calibration. To save this action in non-
volatile memory, click the <Save> button. It is not necessary to clear the current
calibration in order to perform a new calibration.
6.5.2 3D Model
The helicopter will follow the movement of the TCM and give a visual representation of
the module’s orientation, assuming the “Enable 3D Model Display” box is selected on the
Configuration tab.
TCM Studio can capture measurement data and then export it to a text file. To acquire data
and export it, follow the procedure below:
Select the parameters you wish to log in the “Data” window. Use Shift -Click and
Ctrl-Click to select multiple items. In the screen shot above, “Heading”, “Pitch”, and
“Roll” were selected.
Click the <Go> button to start logging. The <Go> button changes to a <Stop> button
after data logging begins.
Click the <Stop> button to stop logging data.
Click the <Export> button to save the data to a file.
Click the <Clear> button to clear the data from the window.
Note: The data logger use ticks for time reference. A tick is 1/60 second.
The graph provides a 2-axis (X,Y) plot of the measured field strength. If “w/o User Cal” graph
data is selected, the plot and data provide magnetic field strength measurements after the FIR
taps are applied, but prior to applying the user calibration coefficients. If “with User Cal”
graph data is selected, the plot and data provide data after applying the FIR filter and the user
calibration coefficients. The sample plot shows a 360° rotation in the horizontal plane, with
both “w/o User Cal” and “with User Cal” selected. The offset between these two plots
represents the effect of the calibration coefficients. The graph can be used to visually see hard
and soft iron effects within the environment measured by the TCM, as well as corrected output
after a user calibration has been performed.
The System Log tab shows all communication between TCM Studio and the TCM module
since launching TCM Studio. Closing TCM Studio will erase the system log. Select the
<Export> button, at the bottom right of the screen, to save the system log to a text file.
Parameter Value
Number of Data Bits 8
Start Bits 1
Stop Bits 1
Parity none
Frame
Payload
ID
(1 - 4091 UInt8)
(UInt8)
The ByteCount is the total number of bytes in the packet including the CRC-16 checksum.
CRC-16 is calculated starting from the ByteCount to the last byte of the Packet Frame. The
ByteCount and CRC-16 are always transmitted in big Endian. Two examples follow.
Example: The complete packet for the kGetModInfo command, which has no payload is:
00 05 01 EF D4
00 09 0A 00 00 00 14 5C F9
63 62 52 51 0
S Exponent Mantissa
The value (v) is determined as: “if and only if” 0 < Exponent < 2047, then
v = (-1)*S*2(Exponent-1023)*1.Mantissa
32-Bit Floating Point (Float32)
Shown below is the 32-bit float format in big Endian. In little Endian format, the 4
bytes are in reverse order, with LSB first.
3130 23 22 0
S Exponent Mantissa
The value (v) is determined as: “if and only if” 0 < Exponent < 255, then
v = (-1)*S*2(Exponent-127)*1.Mantissa
Signed 32-Bit Integer (SInt32)
SInt32-based parameters are signed 32-bit numbers, in 2’s compliment. Bit 31
represents the sign of the value, where 0=positive and 1=negative.
31 24 23 16 15 8 7 0
msb lsb
Big Endian
7 0 15 8 23 16 31 24
lsb msb
Little Endian
15 8 7 0 7 0 15 8
7 0
byte
msb lsb
Big Endian
7 0 15 8 23 16 31 24
lsb msb
Little Endian
15 8 7 0 7 0 15 8
7 0
byte
Boolean
Boolean is a 1-byte parameter that MUST have the value 0 (FALSE) or 1 (TRUE).
7 0
byte
Frame
Command Description
IDd
1 kGetModInfo Queries the device’s type and firmware revision.
2 kGetModInfoResp Response to kGetModInfo
3 kSetDataComponents Sets the data components to be output.
4 kGetData Queries the TCM for data
5 kGetDataResp Response to kGetData
6 kSetConfig Sets internal configurations in TCM
Queries TCM for the current internal
7 kGetConfig
configuration
8 kGetConfigResp Response to kGetConfig
Saves the current internal configuration and any
9 kSave new user calibration coefficients to non-volatile
memory.
10 kStartCal Commands the TCM to start user calibration
11 kStopCal Commands the TCM to stop user calibration
Sets the FIR filter settings for the magnetometer
12 kSetFIRFilters
& accelerometer sensors.
Queries for the FIR filter settings for the
13 kGetFIRFilters
magnetometer & accelerometer sensors.
Contains the FIR filter settings for the
14 kGetFIRFiltersResp
magnetometer & accelerometer sensors.
15 kPowerDown Powers down the module
16 kSaveDone Response to kSave
Type Revision
UInt32 UInt32
Note that the Type and Revision can be decoded from the binary format to character format
using the ASCII standard. For example, the hex string “00 0D 02 54 43 4D 35 31 32 30
ID Count ID 1 ID 2 ID 3 ……….
Example: To query for heading and pitch, the payload should contain:
Payload
2 5 24
When querying for data (kGetData frame), the sequence of the data component output
follows the sequence of the data component IDs as set in this frame.
Component
Component Format Units
IDd
kHeading 5 Float32 degrees
kPitch 24 Float32 degrees
kRoll 25 Float32 degrees
kTemperature 7 Float32 ˚ Celsius
True or False
kDistortion 8 Boolean
(Default)
True or False
kCalStatus 9 Boolean
(Default)
kAccelX 21 Float32 G
kAccelY 22 Float32 G
kAccelZ 23 Float32 G
kMagX 27 Float32 T
kMagY 28 Float32 T
kMagZ 29 Float32 T
2 5 359.9 24 10.5
Config ID Value
UInt8 ID Specific
Payload
1 10.0
Declination ID Declination
Angle (Float32)
Number of Samples
Calibration Mode Allowable Minimum
Range Recommended
Full Range 10 to 32 12
2D Calibration 10 to 32 12
Limited Tilt Range 10 to 32 12
Hard Iron Only 4 to 32 6
Accelerometer Only 12 to 32 18
Accel and Mag 12 to 32 18
Config ID
UInt8
Config ID Value
UInt8 ID Specific
Example: If a request to get the set declination angle, the payload would look like:
Payload
1 10.0
Declination ID Declination
Angle (Float32)
Note: The payload needs to be 4 bytes. If no payload is entered, or if less than 4 bytes are entered,
the unit will default to the previous calibration method.
Payload
Cal Option
UInt32
00 09 0A 00 00 00 14 5C F9
Heading, pitch and roll information is output via the kGetDataResp frame during the
calibration process. This feature provides guidance during the calibration regarding
calibration sample point coverage. During calibration, in the kGetDataResp frame, the
number of data components is set to be 3 and then followed by the data component ID-
value pairs. The sequence of the component IDs are kHeading, kPitch and kRoll.
The steps below provide an example of the steps to perform a user calibration.
Using the kSetConfig command, set kUserCalAutoSampling. FALSE allows for
more direct control, but TRUE may be more convenient.
Using the kSetConfig command, establish the coefficient set number for the new
calibration coefficient by setting the value for kMagCoeffSet (value 0-7) and/or
kAccelCoeffSet (value 0-2).
Using the kSetConfig command again, set kUserCalNumPoints to the appropriate
number of calibration points.
Byte 1 should be set to 3 and Byte 2 should be set to 1. The third payload byte indicates
the number of FIR taps to use, which can be 0 (no filtering), 4, 8, 16, or 32. This is followed
by the tap values, where 0 to 32 total Values can be in the payload, and with each Value
being a Float64, with suggested values given in Table 7-6.
Byte 1 Byte 2
UInt8 UInt8
Error Code
UInt16
SampleCount#
UInt32
MagCalScore:
MagCalScore provides an over-riding quality indicator of the magnetometer
calibration. Acceptable scores will be ≤1 for Full-Range Calibration, ≤2 for other
methods. Note that it is possible to get acceptable scores for DistError and TiltError
and still have a rather high MagCalScore value. The most likely reason for this is the
TCM is close to a source of local magnetic distortion that is not fixed with respect to
the device. In the event of an aborted calibration the score will be 179.8d, or in the
event of an accel-only calibration the score will be 99.99d.
AccelCalScore:
This score represents the over-riding quality of the accelerometer calibration. An
acceptable score is ≤1. In the event of an aborted calibration the score will be 179.8d,
or in the event of a mag-only calibration the score will be 99.99d.
AcquisitionMode
This flag sets whether output will be presented in Continuous or Polled Acquisition
Mode. Its default value is 0 (FALSE), indicating Polled Mode. Polled Mode should
be selected when the host system will poll the TCM for each data set. Continuous
Mode (value 1 as TRUE) should be selected if the user will have the TCM output data
to the host system at a relatively fixed rate.
FlushFilter
Setting this flag to TRUE results in the FIR filter being flushed (cleared) after every
measurement. The default is FALSE.
Flushing the filter clears all tap values, thus purging old data. This can be useful if a
significant change in heading has occurred since the last reading, as the old heading
data would be in the filter. Once the taps are cleared, it is necessary to fully repopulate
the filter before data is output. For example, if 32 FIR taps is set, 32 new samples must
be taken before a reading will be output. The length of the delay before outputting data
is directly correlated to the number of FIR taps.
AcquireDelay
When operating in Continuous Acquisition Mode, the AcquireDelay sets the time
between samples taken by the module, in seconds. The default is 0.0 seconds, which
means the module will reacquire data immediately after the last acquisition. This is an
internal setting that is NOT tied to the time with which the module transmits data to the
host system. Generally speaking, the AcquireDelay is either set to 0, in which case the
TCM is constantly sampling, or set to equal the SampleDelay value. The advantage of
Note: When Sync Mode is selected, the TCM will acknowledge the change in mode and
immediately trigger the Sync Mode and send a data frame.
This frame allows the module to be placed in Sync Mode. The payload contains the Mode
ID requested, as given below.
Payload
Mode ID: Normal Mode = 0
Mode ID Sync Mode = 100
UInt8
If the module is in Sync Mode and the user desires to switch back to Normal Mode, an
“FFh” string first must be sent, followed by some minimum delay time prior to sending the
kSetSyncMode frame. The minimum delay time is dependent on the baud rate, and for a
baud rate equal to or slower than 9600 there is no delay. For baud rates greater than 9600
the minimum delay is equal to:
Minimum delay after sending “FFh” (in seconds) = 7E-3 – (10/baud rate)
Payload
Mode ID
UInt8
The ability to store and access multiple calibration coefficients sets the FieldForce TCM apart
from our Prime or legacy TCM. This section will detail the command list and provide two
examples for utilizing this functionality.
Magnetometer Calibration
0x06 0x12 0-7 Set kCoeffCopySet to 0x00 0x0A 0x06 0x00 0x05 0x13 0xDD
be copy 0 0x12 0x00 0x00 0xA7
0x00 0x00 0x3E
0x76
Set kCoeffCopySet to 0x00 0x0A 0x06 0x00 0x05 0x13 0xDD
be copy 1 0x12 0x00 0x00 0xA8
0x00 0x01 0x2E
0x57
Set kCoeffCopySet to 0x00 0x0A 0x06 0x00 0x05 0x13 0xDD
be copy 4 0x12 0x00 0x00 0xA9
0x00 0x04 0x7E
0xF2
kGetConfig kCoeffCopySet Value Command
Examples TCM Response
(frame ID) (config ID) (UInt32) Bytes
0x07 0x12 get kCoeffCopySet 0x00 0x06 0x07 0x00 0x0A 0x08 0x12
value which is 0x12 0x19 0x44 0x00 0x00 0x00 0x??
currently used in CRC1 CRC2
TCM
Accelerometer Calibration
0x07 0x13 get 0x00 0x06 0x07 0x00 0x0A 0x08 0x13
kAccelCoeffCopySet 0x13 0x09 0x65 0x00 0x00 0x00 0x??
value which is CRC1 CRC2
currently used in
TCM
Examples
Example 1: Save Magnetic Calibration result to Coeff Copy Set 4.
Set the kCoeffCopySet to copy 4 by sending the following command.
0x00 0x0A 0x06 0x12 0x00 0x00 0x00 0x04 0x7E 0xF2
Get the kCoeffCopySet to verify by sending the following command. (Optional)
0x00 0x06 0x07 0x12 0x19 0x44
Send kSave command to save the kCoeffCopySet to flash so that it will be still available
after power cycle. The kSave command is as following.
0x00 0x05 0x09 0x6E 0xDC
Start a user calibration, when completes, save calibration coeffs to TCM. The coeffs have
been saved into coeff set copy 4.
Example 2: Use Magnetic Coeff Copy Set 1 in TCM. (The assumption is user has saved
calibration coeffs to set 1 before)
Set the kCoeffCopySet to copy 1 by sending the following command.
0x00 0x0A 0x06 0x12 0x00 0x00 0x00 0x01 0x2E 0x57
Get the kCoeffCopySet to verify by sending the following command. (Optional)
0x00 0x06 0x07 0x12 0x19 0x44
Send kSave command to save the kCoeffCopySet to flash so that it will be still available
after power cycle. The kSave command is as following.
0x00 0x05 0x09 0x6E 0xDC
Note: The following files are not included in the sample codes and need to be created by the user:
Processes.h & TickGenerator.h. The comments in the code explain what is needed to be sent or
received from these functions so the user can write this section for the user’s platform. For example,
with the TickGenerator.h, the user needs to write a routing that generates 10 msec ticks.
typedef struct
{
Float32 MagCalScore;
Float32 reserve1;
Float32 AccelCalScore;
Float32 DistError;
Float32 TiltError;
Float32 TiltRange;
} __attribute__ ((packed)) MagCalScore;
enum
{
// Frame IDs (Commands)
kGetModInfo = 1, // 1
kGetModInfoResp, // 2
kSetDataComponents, // 3
kGetData, // 4
kGetDataResp, // 5
kSetConfig, // 6
kGetConfig, // 7
kGetConfigResp, // 8
kSave, // 9
kStartCal, // 10
kStopCal, // 11
kSetFilters, // 12
kGetFilters, // 13
kGetFiltersResp, // 14
kPowerDown, // 15
kSaveDone, // 16
kUserCalSampCount, // 17
kCalScore, // 18
// Param IDs
kSetDataComponents =3, // 3-AxisID(UInt8) + Count(UInt8) +
// Value (Float64) +...
// Result IDs
kErrNone = 0, // 0
kErrSave, // 1
};
#pragma once
#include "SystemSerPort.h"
#include "Processes.h"
//
//CommHandler is a base class that provides a callback for
//incoming messages.
//
class CommHandler
{
public:
// Call back to be implemented in derived class.
virtual void HandleComm(UInt8 frameType, void * dataPtr
=
NULL, UInt16 dataLen = 0) {}
};
//
// CommProtocol handles the actual serial communication with the //
module.
// Process is a base class that provides CommProtocol with
// cooperative parallel processing. The Control method will be
// called by a process manager on a continuous basis.
//
class CommProtocol : public Process
{
public:
enum
{
// Frame IDs (Commands)
kGetModInfo // 1
kGetModInfoResp, // 2
kSetDataComponents, // 3
kGetData, // 4
kGetDataResp, // 5
protected:
CommHandler * mHandler;
SerPort * mSerialPort;
#include "CommProtocol.h"
//
// Put together the frame to send to the module
//
void CommProtocol::SendData(UInt8 frameType, void * dataPtr, UInt32
len)
{
UInt8 * data = (UInt8 *)dataPtr; // the data to send
UInt32 index = 0;
// our location in the frame we are putting together
UInt16 crc;
// the CRC to add to the end of the packet
UInt16 count;
// the total length the packet will be
// Store the total len of the packet including the len bytes
// (2), the frame ID (1),
// the data (len), and the crc (2). If no data is sent, the
// min len is 5
mOutData[index++] = count >> 8;
mOutData[index++] = count & 0xFF;
// Write block will copy and send the data out the serial port
mSerialPort->WriteBlock(mOutData, index);
}
//
// Call the functions in serial port necessary to change the
// baud rate
//
void CommProtocol::SetBaud(U Int32 baud)
{
mSerialPort->SetBaudRate(baud);
mSerialPort->InClear();
// clear any data that was already waiting in the buffer
}
//
// Update the CRC for transmitted and received data using the
// CCITT 16bit algorithm (X^16 + X^12 + X^5 + 1).
//
UInt16 crc = 0;
while(len--)
//
// This is called each time this process gets a turn to execute.
//
void CommProtocol::Control()
{
// InLen returns the number of bytes in the input buffer of
//the serial object that are available for us to read.
UInt32 inLen = mSerialPort ->InLen();
switch(mStep)
{
case 1:
{
// wait for length bytes to be received by the serial object
if(inLen >= 2)
{
// Read block will return the number of requested (or available)
// bytes that are in the serial objects input buffer.
// read the byte count
mSerialPort->ReadBlock(mInData, 2);
case 2:
{
// wait for msg complete or timeout
if(inLen >= mExpectedLen - 2)
{
if(crc == crcReceived)
{
// the crc is correct, so pass the frame up for processing.
if(mHandler) mHandler-
>HandleComm(mInData[2], &mInData[3], mExpectedLen - kPacketMinSize);
}
else
{
// crc's don't match so clear everything that is currently in the
// input buffer since the data is not reliable.
mSerialPort->InClear();
}
default:
break ;
}
}
#pragma once
#include "Processes.h"
#include "CommProtocol.h"
//
// This file contains the object providing communication to the TCM
// It will set up the module and parse packets received.
// Process is a base class that provides TCM with cooperative
// parallel processing. The Control method will be
// called by a process manager on a continuous basis.
//
class TCM : public Process, public CommHandler
{
public:
TCM(SerPort * serPort);
~TCM();
protected:
CommProtocol * mComm;
void Control();
};
#include "TCM.h"
#include "TickGenerator.h"
TCM::TCM(SerPort * serPort)
: Process("TCM")
{
// Let the CommProtocol know this object will handle any
// serial data returned by the module
mComm = new CommProtocol(this, serPort);
mTime = 0;
mStep = 1;
}
TCM::~TCM()
{
}
//
// Called by the CommProtocol object when a frame is completel y //
received
//
void TCM::HandleComm(UInt8 frameType, void * dataPtr, UInt16
dataLen)
{
UInt8 * data = (UInt8 *)dataPtr;
switch(frameType)
{
case CommProtocol::kGetDataResp:
{
// Parse the data response
UInt8 count = data[0];
// The number of data elements returned
UInt32 pntr = 1;
// Used to retrieve the returned elements
case CommProtocol::kPitch:
{
// Move(source, destination, size (bytes)). Move copies the
// specified number of bytes from the source pointer to the
// destination pointer. Store the pitch.
Move(&(data[pntr]), &pitch,
sizeof(pitch));
case CommProtocol::kRoll:
{
// Move(source, destination, size (bytes)). Move copies the
// specified number of bytes from the source pointer to the
// destination pointer. Store the roll.
Move(&(data[pntr]), &roll,
sizeof(roll));
case CommProtocol::kTemperature:
{
// Move(source, destination, size (bytes)). Move copies the
// specified number of bytes from the source pointer to the
// destination pointer. Store the heading.
Move(&(data[pntr]), &temperature,
sizeof(temperature));
default:
// Message is a function that displays a formatted string
// (similar to printf)
Message("Unknown type: %02X\r\n",
data[pntr - 1]);
// unknown data type, so size is unknown, so skip everything
return;
break;
}
count--;
// One less element to read in
}
default:
{
// Message is a function that displays a formatted string
// (similar to printf)
Message("Unknown frame %02X received \r\n",
(UInt16)frameType);
break;
}
//
// Have the CommProtocol build and send the fra me to the module.
//
void TCM::SendComm(UInt8 frameType, void * dataPtr, UInt16 dataLen)
{
if(mComm) mComm->SendData(frameType, dataPtr, dataLen);
// Ticks is a timer function. 1 tick = 10msec.
mResponseTime = Ticks() + 300; // Expect a response
within 3 seconds
}
//
// This is called each time this process gets a turn to execute.
//
void TCM::Control()
{
switch(mStep)
{
case 1:
{
UInt8 pkt[kDataCount + 1];
// the compents we are requesting, preceded by the number of
// components being requested
pkt[0] = kDataCount;
pkt[1] = CommProtocol::kHeading;
pkt[2] = CommProtocol::kPitch;
pkt[3] = CommProtocol::kRoll;
pkt[4] = CommProtocol::kTemperature;
SendComm(CommProtocol::kSetDataComponents, pkt,
kDataCount + 1);
case 2:
{
// Ticks is a timer function. 1 tick = 10msec.
if(Ticks() > mTime)
{
// tell the module to take a sample
SendComm(CommProtocol::kGetData);
case 3:
{
// Ticks is a timer function. 1 tick = 10msec.
if(Ticks() > mResponseTime)
{
Message("No response from the module. Check
connection and try again\r\n");
mStep = 0;
}
break;
}
default:
break;
}
}