nav200.h

00001 
00009 #ifndef _NAV200_H
00010 #define _NAV200_H
00011 
00012 #include <sys/types.h>
00013 #include <sys/stat.h>
00014 #include <sys/time.h>
00015 #include <fcntl.h>
00016 #include <termios.h>
00017 #include <stdio.h>
00018 #include <strings.h>
00019 #include <unistd.h>
00020 #include <stdlib.h>
00021 #include <errno.h>
00022 #include <string.h>
00023 #include <pthread.h>
00024 #include <math.h>
00025 #include <libplayercore/playercore.h>
00026 //#include <stdint.h>
00027 
00028 #define DEFAULT_PORT "/dev/ttyS0"
00029 #define DEFAULT_RATE B19200
00030 
00031 
00032 #define STX     0x02
00033 #define MAXLEN  255
00034 #define BUFFER_SIZE 256
00035 #define HEADER_SIZE 4
00036 #define FOOTER_SIZE 1
00037 
00038 typedef struct Nav200Command
00039 {
00040         uint8_t header;
00041         uint8_t length;
00042         uint8_t mode;
00043         uint8_t function;
00044         uint8_t data [MAXLEN-HEADER_SIZE-FOOTER_SIZE+1];
00045         int dataLength;
00046         uint8_t BCC;
00047 }Nav200Command;
00048 
00049 // typedef struct ReflectorInfo
00050 // {
00051 //   uint8_t layer;
00052 //   uint8_t number;
00053 // }ReflectorInfo;
00054 
00055 typedef struct PositionXY
00056 {//position is in mm
00057   int x;
00058   int y;
00059 }PositionXY;
00060 
00061 
00062 typedef struct ReflectorData
00063 {
00064   uint8_t layer;
00065   uint8_t number; // reflector number
00066   PositionXY pos;
00067 }ReflectorData;
00068 
00069 
00070 typedef struct LaserPos
00071 {
00072   PositionXY pos; // position of the laser scanner
00073   short orientation;
00074   uint8_t quality;
00075   uint8_t number; // number of reflectors used
00076 }LaserPos;
00077 
00078 typedef struct ErrorBytes
00079 {
00080   uint8_t F0; // function byte of the last command
00081   uint8_t F1; // error class
00082   uint8_t F2; // error group
00083   uint8_t F3; // error specification
00084 }ErrorBytes;
00085 
00086 
00087 
00088 
00089 class Nav200
00090 {
00091 public:
00092 
00093   Nav200();
00094   ~Nav200();
00095 
00096   int Initialise(const char * port = DEFAULT_PORT, int rate = DEFAULT_RATE);
00097   int Terminate();
00098 
00099   int ProcessData();
00100 
00101   // standby mode
00102   bool EnterStandby();
00103   int GetVersionNumber();
00104   char* GetVersionString(); //String pointer return is only valid till the next request to Nav200
00105   short GetDeviceSerial();
00106   bool rotateDirection(uint8_t direction);
00107   bool GetReflectorPosition(uint8_t layer, uint8_t number, PositionXY & reflector);
00108   bool ChangeReflectorPosition(uint8_t layer, uint8_t number, int newX, int newY);
00109   bool InsertReflectorPosition(uint8_t layer, uint8_t number, int X, int Y);
00110   bool DeleteReflectorPosition(uint8_t layer, uint8_t number, PositionXY & reflector);
00111 
00112   // read and set reflector radii
00113   int GetReflectorRadius(uint8_t layer);
00114   bool SetReflectorRadius(uint8_t layer, uint8_t radius);
00115 
00116   // mapping mode
00117   bool EnterMapping();
00118   int StartMapping(uint8_t layer, int X, int Y, short orientation, uint8_t radius);
00119   int StartMappingMeasurement(uint8_t layer, uint8_t scans, int X, int Y, short orientation, uint8_t radius);
00120   int StartNegativeMappingMeasurement(uint8_t layer, uint8_t scans, int X, int Y, short orientation, uint8_t radius);
00121   bool MappingPosition(uint8_t layer, uint8_t number, PositionXY & reflector);
00122 
00123   // positioning mode
00124   bool EnterPositioning();
00125   bool EnterPositioningInput(uint8_t NumberOfMeasurements);
00126   bool GetPositionAuto(LaserPos & laserPosition);
00127   bool GetPositionSpeed(short speedX, short speedY, LaserPos & laserPosition);
00128   bool GetPositionSpeedVelocity(short speedX, short speedY, short velocity, LaserPos & laserPosition);
00129   bool GetPositionSpeedVelocityAbsolute(short speedX, short speedY, short velocity, LaserPos & laserPosition);
00130   bool ChangeLayer(uint8_t layer);
00131   bool ChangeLayerDefPosition(uint8_t layer, int X, int Y, short orientation);
00132   bool SetActionRadii(int min, int max);
00133   bool SelectNearest(uint8_t N_nearest);
00134 
00135   // upload mode
00136   bool EnterUpload();
00137   bool GetUploadTrans(uint8_t layer, ReflectorData & reflector);
00138   // download mode
00139   bool EnterDownload();
00140   bool DownloadReflector(uint8_t layer, uint8_t number, int X, int Y);
00141 
00142 
00143 protected:
00144   // serial port descriptor
00145   int fd;
00146   struct termios oldtio;
00147 
00148   uint8_t receivedBuffer[BUFFER_SIZE];
00149   int bytesReceived;
00150   Nav200Command packet;
00151   ErrorBytes error;
00152 
00153   void PrintErrorMsg(void);
00154 
00155   int ReadFromNav200(int timeout_usec=5000000);
00156   int WriteCommand(char mode, char function, int dataLength, uint8_t * data);
00157   uint8_t CreateCRC(uint8_t* data, ssize_t len);
00158 };
00159 
00160 
00161 
00162 #endif

Last updated 12 September 2005 21:38:45