LRAUV  revA
AHRS_sp3003D.h
Go to the documentation of this file.
1 
12 #ifndef SP3003D_H
13 #define SP3003D_H
14 
16 #include "io/LoadControl.h"
17 #include "io/UartStream.h"
18 #include "logger/Logger.h"
19 
20 #include "data/Matrix3x3.h"
21 
24 
37 {
38 public:
39 
40  AHRS_sp3003D( const Module* module );
41 
42  virtual ~AHRS_sp3003D();
43 
44  virtual void run();
45 
48  virtual RunState start();
49 
51  virtual RunState starting();
52 
54  virtual RunState pause();
55 
57  virtual RunState paused();
58 
60  virtual RunState resume();
61 
63  virtual RunState resuming();
64 
66  virtual RunState runnable();
67 
69  virtual RunState resetting()
70  {
71  return stop();
72  }
73 
75  virtual RunState stop();
76 
77  virtual RunState stopping();
78 
80  virtual RunState stopped();
81 
82  virtual void uninitialize();
83 
84  typedef enum
85  {
86  CAL_OFF, // Normal Operation, no calibration underway
87  CAL_RESET, // Normal Operation, but calibration reset to factory default
88  CAL_AUTOVAR, // Normal Operation, but magnetic variability calculated
89  CAL_MANUAL, // Manual calibration mode, outputs disabled
90  CAL_AUTO, // Auto calibration mode, outputs disabled
92 
95  static bool SetCalMode( CalibrateSpartonMode calMode );
96 
98  virtual ConfigURI getConfigURI( ConfigOption configOption ) const;
99 
100 private:
101 
102  // Note that the copy constructor below is private and not given a body.
103  // Any attempt to call it will return a compiler error.
104  AHRS_sp3003D( const AHRS_sp3003D& old ); // disallow copy constructor
105 
108 
111 
114 
115  // Slate inputs
119 
120  // Slate outputs
131 
137 
144 
145  // returns true if data is requested from one of the readers
146  bool isDataRequested();
147 
148  // Debugging outputs
149  bool debug_;
152 
153  // Instance of load controller
155 
156  // True if we have alerted user that we are using Simulator instead of hardware.
158 
164 
167  float rollOffset_;
168 
174 
175  // Stores the current response from the modem
176  char deviceResponse_[96];
177 
178  // Holds the communications device
180 
182 
183  // Interact with uart_
184  bool tryUartComms( const char* textToSend, const char* errorPrefix,
185  Syslog::Severity severity = Syslog::ERROR );
186 
187  // scan configuraiton settings
188  void readConfig();
189 
190  // Returns magnetic heading or nan if not available/error
191  float getCompassHdg();
192 
193  // Returns true heading or nan if not available/error
194  float getTrueHdg();
195 
196  // Returns pitch/roll or nan if not available/error
197  void getPitchRoll( float &pitch , float &roll );
198 
199  // Sends a $xxXDR command and interprets the $HCXDR response
200  bool readTransducers( float &compassHeading,
201  float &pitch , float &roll,
202  float &temperature );
203 
204  // Just sends a $xxXDR command
205  void requestTransducers();
206 
207  // Configures for a vertical mounting scheme
208  void setMountVertical();
209 
210  // Just interprets the $HCXDR response
211  bool receiveTransducers( float &compassHeading,
212  float &pitch , float &roll, float &temperature );
213 
214  // Parses a $HCXDR response
215  static bool ParseHCXDR( const char* response, float &compassHeading,
216  float &pitch , float &roll, float &temperature );
217 
218  //Only Send: 3 Byte (0xA4, 0x09, 0xA0)
219  void requestHeadingMagBin();
220 
221  //Only Read & Parse Response: 5 Bytes (0xA4, 0x09, Heading as a 16-bit signed integer, 0xA0)
222  bool receiveHeadingMagBin( float &compassHeading );
223 
224  //Send: 3 Byte (0xA4, 0x09, 0xA0)
225  //Response: 5 Bytes (0xA4, 0x09, Heading as a 16-bit signed integer, 0xA0)
226  bool readHeadingMagBin( float &compassHeading );
227 
228  //Only Send: 3 Byte (0xA4, 0x06, 0xA0)
229  void requestPitchRollBin();
230 
231  //Only Read & Parse Response: 7 Bytes (0xA4, 0x06, Pitch, Roll as 16-bit signed integers, 0xA0)
232  bool receivePitchRollBin( float &pitch, float &roll );
233 
234  //Send: 3 Byte (0xA4, 0x06, 0xA0)
235  //Response: 7 Bytes (0xA4, 0x06, Pitch, Roll as 16-bit signed integers, 0xA0)
236  bool readPitchRollBin( float &pitch, float &roll );
237 
238  // Sends a $PSPA,M command and interprets the response
239  bool readMagnetics( float &mX, float &mY , float &mZ, float &mT );
240 
241  // Parses the response to the $PSPA,M command
242  static bool ParsePSPAM( const char* response, float &mX, float &mY , float &mZ, float &mT );
243 
244  // Send: 3 Byte (0xA4, 0x01, 0xA0)
245  // Response: 9 Bytes (0xA4, 0x01, Mx, My, Mz as 16-bit integers, 0xA0)
246  bool readMagneticsBin( float &mX, float &mY , float &mZ );
247 
248  // Sends a $PSPA,A command and interprets the response
249  bool readAccelVec( float &aX, float &aY , float &aZ, float &aT );
250 
251  // Parses the response to the $PSPA,A command
252  static bool ParsePSPAA( const char* response, float &aX, float &aY , float &aZ, float &aT );
253 
254  //Send: 3 Byte (0xA4, 0x07, 0xA0)
255  //Response: 11 Bytes (0xA4, 0x07, Ax, Ay, Az, Atotal as 16-bit integers, 0xA0)
256  bool readAccelVecBin( float &aX, float &aY , float &aZ, float &aT );
257 
258  // Parses the quality of the adaptive magnetic calibration process.
259  static bool ParseMagErr( const char* response, int& magErr );
260 
261  // Calculates a NMEA checksum
262  static int CalcNMEAChecksum( const char* response );
263 
265  void setWritersInvalid( bool invalid );
266 
269  bool setCalMode( CalibrateSpartonMode calMode );
270 
271  // Flips endian and converts 2 bytes to short
272  short extractShort( char * convertFloat );
273 
274 };
275 
276 #endif /*SP3003D_H*/
virtual RunState resume()
Resume from PAUSE.
Definition: AHRS_sp3003D.cpp:988
UniversalDataReader * latitudeReader_
Definition: AHRS_sp3003D.h:116
Contains a 3x3 array of double precision floating point numbers, along with methods for performing co...
Definition: Matrix3x3.h:27
bool calibrationFailure_
If true, bail out of calibration mode and restart.
Definition: AHRS_sp3003D.h:113
Contains the SyncComponent class definition.
UniversalDataReader * depthReader_
Definition: AHRS_sp3003D.h:118
int readAccelerationsCfg_
Definition: AHRS_sp3003D.h:171
Contains the LoadControl class declaration.
A DataAccessor that reads values from the Slate Contains a default dataValue that must not be NULL...
Definition: UniversalDataReader.h:26
static int CalcNMEAChecksum(const char *response)
Definition: AHRS_sp3003D.cpp:739
bool readTransducers(float &compassHeading, float &pitch, float &roll, float &temperature)
Definition: AHRS_sp3003D.cpp:442
void readConfig()
Definition: AHRS_sp3003D.cpp:108
DataWriter * mtWriter_
Definition: AHRS_sp3003D.h:126
virtual RunState paused()
Should eventually follow a PAUSE request: should set continueTime.
Definition: AHRS_sp3003D.cpp:977
CalibrateSpartonMode calMode_
The current mode the behavior is in.
Definition: AHRS_sp3003D.h:110
virtual ConfigURI getConfigURI(ConfigOption configOption) const
Should return [myNamespace]::SIMULATE_HARDWARE, or [myNamespace]::POWER, etc.
Definition: AHRS_sp3003D.cpp:1289
Abstract Base class for components that collect data for use later in the computation cycle...
Definition: SyncComponent.h:172
DataWriter * mzWriter_
Definition: AHRS_sp3003D.h:125
static bool ParseMagErr(const char *response, int &magErr)
Definition: AHRS_sp3003D.cpp:725
bool readHeadingMagBin(float &compassHeading)
Definition: AHRS_sp3003D.cpp:504
DataWriter * compassTemperatureWriter_
Definition: AHRS_sp3003D.h:122
static bool ParseHCXDR(const char *response, float &compassHeading, float &pitch, float &roll, float &temperature)
Definition: AHRS_sp3003D.cpp:678
float rollOffset_
Definition: AHRS_sp3003D.h:167
void setMountVertical()
Definition: AHRS_sp3003D.cpp:1304
bool usingSimWarned_
Definition: AHRS_sp3003D.h:157
ConfigReader * readAccelerationsCfgReader_
Definition: AHRS_sp3003D.h:138
A DataAccessor that writes values to the Slate via its associated DataElement.
Definition: UniversalDataWriter.h:24
virtual RunState runnable()
Should eventually follow a START request or RESETTING.
Definition: AHRS_sp3003D.cpp:1025
RunState
Definition: Component.h:115
Definition: AHRS_sp3003D.h:86
virtual ~AHRS_sp3003D()
Definition: AHRS_sp3003D.cpp:99
Contains the UartStream class declaration.
void requestTransducers()
Definition: AHRS_sp3003D.cpp:412
virtual RunState resetting()
Might occur in case of Error.
Definition: AHRS_sp3003D.h:69
DataWriter * axWriter_
Definition: AHRS_sp3003D.h:127
Timespan class, represents a delta of time.
Definition: Timestamp.h:248
virtual RunState stopped()
Initial state – can be later followed by START.
Definition: AHRS_sp3003D.cpp:1250
bool readMagnetics(float &mX, float &mY, float &mZ, float &mT)
Definition: AHRS_sp3003D.cpp:566
DataWriter * mxWriter_
Definition: AHRS_sp3003D.h:123
void requestHeadingMagBin()
Definition: AHRS_sp3003D.cpp:458
Implements both InStream and OutStream for the LPC3XXX Standard UART.
Definition: UartStream.h:26
DataWriter * compassHeadingWriter_
Definition: AHRS_sp3003D.h:121
bool receiveTransducers(float &compassHeading, float &pitch, float &roll, float &temperature)
Definition: AHRS_sp3003D.cpp:421
bool readAccelVecBin(float &aX, float &aY, float &aZ, float &aT)
Definition: AHRS_sp3003D.cpp:641
char deviceResponse_[96]
Definition: AHRS_sp3003D.h:176
A DataAccessor that writes values to the Slate via its associated DataElement.
Definition: DataWriter.h:27
UniversalDataWriter * magneticHeadingWriter_
Definition: AHRS_sp3003D.h:132
Definition: ElementURI.h:166
UniversalDataWriter * pitchWriter_
Definition: AHRS_sp3003D.h:134
float magVariation_
Definition: AHRS_sp3003D.h:163
Definition: AHRS_sp3003D.h:87
float pitchOffset_
Offset for mounting. In degrees.
Definition: AHRS_sp3003D.h:166
bool isDataRequested()
Definition: AHRS_sp3003D.cpp:1274
Definition: Syslog.h:31
DataWriter * atWriter_
Definition: AHRS_sp3003D.h:130
bool readAccelVec(float &aX, float &aY, float &aZ, float &aT)
Definition: AHRS_sp3003D.cpp:624
bool setCalMode(CalibrateSpartonMode calMode)
Sets the state and commands the Sparton Retuns true if successful.
Definition: AHRS_sp3003D.cpp:766
static bool SetCalMode(CalibrateSpartonMode calMode)
Sets the state and commands the Sparton Retuns true if successful.
Definition: AHRS_sp3003D.cpp:133
void getPitchRoll(float &pitch, float &roll)
Definition: AHRS_sp3003D.cpp:330
UniversalDataReader * longitudeReader_
Definition: AHRS_sp3003D.h:117
Timestamp startTime_
Definition: AHRS_sp3003D.h:170
Definition: AHRS_sp3003D.h:88
Module is the abstract base class for a collection of Component objects that can be contained in a lo...
Definition: Module.h:45
bool readPitchRollBin(float &pitch, float &roll)
Definition: AHRS_sp3003D.cpp:560
ConfigReader * magDeviationCfgReader_
Definition: AHRS_sp3003D.h:141
float getCompassHdg()
Definition: AHRS_sp3003D.cpp:165
virtual RunState pause()
Pause for a short period (indicated by pauseTime)
Definition: AHRS_sp3003D.cpp:959
bool configSet_
Definition: AHRS_sp3003D.h:150
This class allows one to control loads on a load controller channel.
Definition: LoadControl.h:24
CalibrateSpartonMode
Definition: AHRS_sp3003D.h:84
void setWritersInvalid(bool invalid)
Sets the fail state of the slate writers during calibration.
Definition: AHRS_sp3003D.cpp:757
virtual void uninitialize()
Provide a space for uninitialization.
Definition: AHRS_sp3003D.cpp:118
float magDeviation_
Deviation of this compass in the vehicle.
Definition: AHRS_sp3003D.h:162
virtual RunState start()
Do what needs to be done to run Similar to initialize, in old init/run/uninit sequence.
Definition: AHRS_sp3003D.cpp:858
DataWriter * ayWriter_
Definition: AHRS_sp3003D.h:128
DataWriter * azWriter_
Definition: AHRS_sp3003D.h:129
Definition: UniversalDataWriter.h:55
Definition: ConfigReader.h:13
ConfigReader * readMountingCfgReader_
Definition: AHRS_sp3003D.h:140
static AHRS_sp3003D * Instance_
Pointer to the singleton-like instance of this component.
Definition: AHRS_sp3003D.h:107
Contains the Logger class definition.
Contains the Matrix3x3 class definition.
ConfigReader * rollOffsetCfgReader_
Definition: AHRS_sp3003D.h:143
Definition: AHRS_sp3003D.h:89
bool tryUartComms(const char *textToSend, const char *errorPrefix, Syslog::Severity severity=Syslog::ERROR)
Definition: AHRS_sp3003D.cpp:142
static bool ParsePSPAA(const char *response, float &aX, float &aY, float &aZ, float &aT)
Definition: AHRS_sp3003D.cpp:712
virtual void run()
The actual "payload" of the component.
Definition: AHRS_sp3003D.cpp:104
Provides software interface to the Sparton SP3003D AHRS.
Definition: AHRS_sp3003D.h:36
Severity
An attempt to define different levels of syslog severity.
Definition: Syslog.h:28
short extractShort(char *convertFloat)
Definition: AHRS_sp3003D.cpp:1311
AHRS_sp3003D(const Module *module)
Definition: AHRS_sp3003D.cpp:35
UniversalDataWriter * rollWriter_
Definition: AHRS_sp3003D.h:135
int readMagneticsCfg_
Definition: AHRS_sp3003D.h:172
int readMountingCfg_
Definition: AHRS_sp3003D.h:173
bool receiveHeadingMagBin(float &compassHeading)
Definition: AHRS_sp3003D.cpp:470
void requestPitchRollBin()
Definition: AHRS_sp3003D.cpp:510
ConfigReader * readMagneticsCfgReader_
Definition: AHRS_sp3003D.h:139
int verbosity_
Definition: AHRS_sp3003D.h:151
bool debug_
Definition: AHRS_sp3003D.h:149
ConfigOption
Definition: Component.h:456
virtual RunState stop()
Initial state – can be later followed by START.
Definition: AHRS_sp3003D.cpp:1220
ConfigReader * pitchOffsetCfgReader_
Definition: AHRS_sp3003D.h:142
bool readMagneticsBin(float &mX, float &mY, float &mZ)
Definition: AHRS_sp3003D.cpp:580
virtual RunState stopping()
Might follow a STOP request.
Definition: AHRS_sp3003D.cpp:1229
Timestamp dataTimestamp_
Definition: AHRS_sp3003D.h:170
Definition: AHRS_sp3003D.h:90
Timespan poTimeout_
Definition: AHRS_sp3003D.h:169
bool receivePitchRollBin(float &pitch, float &roll)
Definition: AHRS_sp3003D.cpp:521
UartStream uart_
Definition: AHRS_sp3003D.h:179
DataWriter * myWriter_
Definition: AHRS_sp3003D.h:124
virtual RunState resuming()
Might follow a PAUSE...RESUME sequence.
Definition: AHRS_sp3003D.cpp:1013
LoadControl loadControl_
Definition: AHRS_sp3003D.h:154
static bool ParsePSPAM(const char *response, float &mX, float &mY, float &mZ, float &mT)
Definition: AHRS_sp3003D.cpp:698
virtual RunState starting()
Might follow a STOP...START sequence.
Definition: AHRS_sp3003D.cpp:893
UniversalDataWriter * trueHeadingWriter_
Definition: AHRS_sp3003D.h:133
float getTrueHdg()
Definition: AHRS_sp3003D.cpp:248
Represents absolute times.
Definition: Timestamp.h:31
UniversalBlobWriter * rotationMatrixWriter_
Definition: AHRS_sp3003D.h:136
Matrix3x3 rotationFromVehicleToNavigationFrame_
Definition: AHRS_sp3003D.h:181