IGSTK
igstkAscensionCommandInterpreter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Image Guided Surgery Software Toolkit
4  Module: $RCSfile: igstkAscensionCommandInterpreter.h,v $
5  Language: C++
6  Date: $Date: 2009-01-30 19:33:49 $
7  Version: $Revision: 1.1 $
8 
9  Copyright (c) ISC Insight Software Consortium. All rights reserved.
10  See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================
17 
18 Copyright (c) 2000-2005 Atamai, Inc.
19 
20 Use, modification and redistribution of the software, in source or
21 binary forms, are permitted provided that the following terms and
22 conditions are met:
23 
24 1) Redistribution of the source code, in verbatim or modified
25  form, must retain the above copyright notice, this license,
26  the following disclaimer, and any notices that refer to this
27  license and/or the following disclaimer.
28 
29 2) Redistribution in binary form must include the above copyright
30  notice, a copy of this license and the following disclaimer
31  in the documentation or with other materials provided with the
32  distribution.
33 
34 3) Modified copies of the source code must be clearly marked as such,
35  and must not be misrepresented as verbatim copies of the source code.
36 
37 THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS"
38 WITHOUT EXPRESSED OR IMPLIED WARRANTY INCLUDING, BUT NOT LIMITED TO,
39 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 PURPOSE. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR OTHER PARTY WHO MAY
41 MODIFY AND/OR REDISTRIBUTE THE SOFTWARE UNDER THE TERMS OF THIS LICENSE
42 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES
43 (INCLUDING, BUT NOT LIMITED TO, LOSS OF DATA OR DATA BECOMING INACCURATE
44 OR LOSS OF PROFIT OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF
45 THE USE OR INABILITY TO USE THE SOFTWARE, EVEN IF ADVISED OF THE
46 POSSIBILITY OF SUCH DAMAGES.
47 
48 =======================================================================*/
49 
50 #ifndef __igstkAscensionCommandInterpreter_h
51 #define __igstkAscensionCommandInterpreter_h
52 
53 #include "igstkObject.h"
55 
56 #include <string>
57 
58 namespace igstk
59 {
60 
70 {
71  FB_POINT = 'B',
72  FB_STREAM = '@',
77 
79  FB_C_ANGLES = 'W',
80  FB_C_MATRIX = 'X',
85 
88 
93 
94  FB_FBB_RESET = '/',
97  FB_RUN = 'F',
98  FB_SLEEP = 'G',
99  FB_SYNC = 'A',
100  FB_XOFF = '\x13',
101  FB_XON = '\x11',
102 
103  FB_RS232_TO_FBB = '\xF0',
106 
109 };
110 
119 {
120  FB_POSITION = 'V',
121  FB_ANGLES = 'W',
122  FB_MATRIX = 'X',
127 };
128 
136 {
140  FB_STATUS_XOFF = 0x0040,
147  FB_STATUS_ERROR = 0x2000,
150 };
151 
161 {
170 };
171 
177 {
188 };
189 
198 {
202 };
203 
211 {
212  FB_FORWARD = 0x0000,
213  FB_AFT = 0x0100,
214  FB_UPPER = 0x010C,
215  FB_LOWER = 0x000C,
216  FB_LEFT = 0x0106,
217  FB_RIGHT = 0x0006,
218 };
219 
229 {
232 };
233 
242 {
243  FB_STATUS = 0,
245  FB_SPEED = 2,
248  FB_FILTER = 4,
251  FB_RATE = 7,
258  FB_VM = 12,
284 };
285 
291 {
292  FB_2400 = 0,
293  FB_4800 = 1,
294  FB_9600 = 2,
295  FB_19200 = 3,
296  FB_38400 = 4,
297  FB_57600 = 5,
299 };
300 
302 {
303 public:
304 
307 
308 public:
309 
311  typedef SerialCommunication CommunicationType;
312 
314  void SetCommunication(CommunicationType* communication);
315 
317  CommunicationType* GetCommunication();
318 
320  void Open();
321 
323  void Stop();
324  void Run();
325 
327  void Close();
328 
330  void Reset();
331 
333  void SetHemisphere(AscensionHemisphere hemisphere);
334 
336  void SetFormat(AscensionDataFormat format);
337 
339  void SetButtonMode(bool mode);
340 
342  void Point();
343 
345  void Stream();
346 
348  void EndStream();
349 
352  void EndStreamIfStreaming();
353 
359  void Update();
360 
366  unsigned int GetBird();
367 
373  void GetPosition(float xyz[3]);
374 
379  void GetAngles(float zyx[3]);
380 
387  void GetMatrix(float a[9]);
388 
395  void GetQuaternion(float q[4]);
396 
402  int GetButton();
403 
405  void MatrixFromAngles(float a[9], const float zyx[3]);
406 
408  void AnglesFromMatrix(float zyx[3], const float a[9]);
409 
411  void FBBReset();
412 
414  void FBBAutoConfig(unsigned int num);
415 
417  void RS232ToFBB(unsigned int bird);
418 
420  void SendCommand(AscensionCommand command);
421 
423  void SendCommandWords(AscensionCommand command, const short *data);
424 
426  void SendCommandBytes(AscensionCommand command, const char *data);
427 
430 
432  int ExamineValueWords(AscensionParameter parm, short *data);
433 
435  int ExamineValueBytes(AscensionParameter parm, char *data);
436 
438  void ChangeValue(AscensionParameter parm, int data);
439 
441  void ChangeValueWords(AscensionParameter parm, const short *data);
442 
444  void ChangeValueBytes(AscensionParameter parm, const char *data);
445 
453 
455  const char *GetErrorMessage();
456 
462  void ButtonRead(int *val);
463 
465  int GetShort(const char *cp);
466 
468  void PutShort(char *cp, int val);
469 
470 protected:
471 
474 
477 
479  virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const;
480 
481 private:
482 
484  void ReceiveRaw(char *reply, unsigned int len);
485 
487  void SendRaw(const char *text, unsigned int len);
488 
490  int Unpack(char **cp);
491 
493  void SetErrorAndMessage(AscensionErrorCode errorcode, const char *text);
494 
495  /* stores last error */
496  AscensionErrorCode m_Error;
497 
498  /* stores text for last error */
499  std::string m_ErrorText;
500 
501  /* revision number (quite important) */
502  int m_Revision;
503 
504  /* max examine/change parameter number for this rev */
505  AscensionParameter m_MaxParameter;
506 
507  /* FBB addressing mode */
508  AscensionAddressMode m_AddressMode;
509 
510  /* birds are in group mode */
511  bool m_GroupMode;
512 
513  /* number of running birds */
514  unsigned int m_NumberOfBirds;
515 
516  /* true if currently stream */
517  bool m_StreamData;
518 
519  /* true if currently point */
520  bool m_PointData;
521 
522  /* stores bird address after RS232_TO_FBB */
523  unsigned int m_FBBAddress;
524 
525  /* the bird which this data set is for */
526  unsigned int m_CurrentBird;
527 
528  /* position scale mode for each bird */
529  AscensionPositionScale m_PositionScale[128];
530 
531  /* button mode for each bird */
532  bool m_ButtonMode[128];
533 
534  /* FB_POSITION, FB_ANGLES, etc for each bird */
535  AscensionDataFormat m_DataFormat[128];
536 
537  /* place where data is stored after being read */
538  char m_DataBuffer[256];
539 
540  /* leftover chars after a phase error */
541  unsigned int m_PhaseErrorLeftoverBytes;
542 
544  CommunicationType::Pointer m_Communication;
545 };
546 
547 } /* end namespace igstk */
548 
549 #endif /* __igstkAscensionCommandInterpreter_h */
communications timeout error
Sudden output change elimination.
Bird outputs an error code.
FBB Auto-Configuration, 1 xmtr/N snsrs.
Change / Examine Hemisphere.
void AnglesFromMatrix(float zyx[3], const float a[9])
Convenience method to convert a matrix into angles.
void GetMatrix(float a[9])
Get the rotation matrix from the most recent data record, if present.
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const
Print object information.
Base class for all the IGSTK classes.
Definition: igstkObject.h:40
void Stop()
Stop and restart the system.
void Open()
Open communication with the flock.
DC filter constant table ALPHA_MAX.
void FBBAutoConfig(unsigned int num)
Configure the flock to work with a certain number of birds.
virtual ~AscensionCommandInterpreter()
Destructor.
void SetFormat(AscensionDataFormat format)
Set the data format.
void RS232ToFBB(unsigned int bird)
Direct the next command to a specific bird on the Flock Of Birds Bus.
int ExamineValue(AscensionParameter parm)
Examine a parameter value and return the result.
int ExamineValueWords(AscensionParameter parm, short *data)
Examine a parameter value and store the result in the supplied array.
DC Filter constant table ALPHA_MIN.
error setting COM port parameters
#define igstkStandardClassTraitsMacro(classname, superclassname)
Convenience macro for traits of a non-templated class.
Definition: igstkMacros.h:275
Disable/Enable data ready output.
int ExamineValueBytes(AscensionParameter parm, char *data)
Examine a parameter value and store the result in the supplied array.
void EndStreamIfStreaming()
Request that the flock stops streaming data records, but only if it is currently streaming.
void Close()
Close communication with the flock.
AscensionDataFormat
The Flock of Birds supports several different data formats, which can be set with the SetFormat() met...
void SetButtonMode(bool mode)
Set button state reporting on or off.
AscensionStatusBits
The bird status parameter FB_STATUS can be examined using the ExamineValue() function.
Software revision number.
action is illegal in this state
int GetButton()
Get the button state for a transducer that has a button attached.
void Point()
Request a single data record.
Changes data ready character.
void SetHemisphere(AscensionHemisphere hemisphere)
Set the operational hemisphere of the flock.
const char * GetErrorMessage()
Get a textual description of the last error from the flock.
int GetShort(const char *cp)
Utilitity function to unpack two chars from the flock into a short.
void SendCommand(AscensionCommand command)
Send a command to the Flock of Birds.
On error: stop or don't stop Bird.
Bird measurement rate.
AscensionAddressMode
The FB_FBB_ADDRESS_MODE parameter can be examined with ExamineValue().
AscensionCommandInterpreter()
Constructor.
void GetAngles(float zyx[3])
Get the angles from the most recent data record, if present.
void FBBReset()
Pass a reset to the Flock of Birds Bus to reset all the birds.
AscensionCommand
Every bird command consists of a single byte.
void Update()
Get the next data record from the flock.
AscensionHemisphere
The FB_P_HEMISPHERE parameter can be examined with ExamineValue() and changed with fbChangeValue()...
AscensionErrorCode
The following error codes are returned by GetError():
DC filter constant table Vm.
void GetQuaternion(float q[4])
Get the quaternion from the most recent data record, if present.
unsigned int GetBird()
Get the bird that the most recent data record is for.
void PutShort(char *cp, int val)
Utility function to convert a short into two chars for the flock.
void GetPosition(float xyz[3])
Get the position from the most recent data record, if present.
void Stream()
Request that the flock starts streaming data records.
Bird measurement rate count.
void ChangeValueWords(AscensionParameter parm, const short *data)
Change a parameter to values in the supplied array.
This class implements communication over a serial port via RS-232.
void ChangeValue(AscensionParameter parm, int data)
Change a parameter to the specified value.
void ChangeValueBytes(AscensionParameter parm, const char *data)
Change a parameter to values in the supplied array.
phase error: comm port is dropping bytes
void Reset()
Do a hardware reset of the flock.
bad examine/change parameter
void MatrixFromAngles(float a[9], const float zyx[3])
Convenience method to convert angles to a matrix.
void EndStream()
Request that the flock stops streaming data records.
void SendCommandWords(AscensionCommand command, const short *data)
Send a command to the Flock of Birds along with some 16-bit data.
Bird computer crystal speed.
Change / Examine Reference Frame2.
AscensionBusStatusBits
The FB_FBB_STATUS parameter can be examined using ExamineValueBytes(), which will provide one status ...
Change / Examine Angle Align2.
void SendCommandBytes(AscensionCommand command, const char *data)
Send a command to the Flock of Birds along with some 8-bit data.
AscensionPositionScale
The FB_POSITION_SCALING parameter is specified here in millimeters rather than inches.
AscensionErrorCode GetError()
Get an integer error code for the flock, zero if no error.
void ButtonRead(int *val)
Read the button state.
CommunicationType * GetCommunication()
Get the communication object.