nav200.h
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2006
4  * Kathy Fung, Toby Collett
5  *
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */
21 
30 #ifndef _NAV200_H
31 #define _NAV200_H
32 
33 #include <libplayercore/playercore.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #if !defined (WIN32)
37  #include <sys/time.h>
38  #include <termios.h>
39  #include <strings.h>
40  #include <unistd.h>
41 #endif
42 #include <fcntl.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <errno.h>
46 #include <string.h>
47 #include <pthread.h>
48 #include <math.h>
49 //#include <stdint.h>
50 
51 #if defined (WIN32)
52  typedef unsigned int ssize_t;
53 #endif
54 
55 #define STX 0x02
56 #define MAXLEN 255
57 #define BUFFER_SIZE 256
58 #define HEADER_SIZE 4
59 #define FOOTER_SIZE 1
60 
61 typedef struct Nav200Command
62 {
63  uint8_t header;
64  uint8_t length;
65  uint8_t mode;
66  uint8_t function;
67  uint8_t data [MAXLEN-HEADER_SIZE-FOOTER_SIZE+1];
68  int dataLength;
69  uint8_t BCC;
71 
72 // typedef struct ReflectorInfo
73 // {
74 // uint8_t layer;
75 // uint8_t number;
76 // }ReflectorInfo;
77 
78 typedef struct PositionXY
79 {//position is in mm
80  int x;
81  int y;
82 }PositionXY;
83 
84 
85 typedef struct ReflectorData
86 {
87  uint8_t layer;
88  uint8_t number; // reflector number
89  PositionXY pos;
91 
92 
93 typedef struct LaserPos
94 {
95  PositionXY pos; // position of the laser scanner
96  short orientation;
97  uint8_t quality;
98  uint8_t number; // number of reflectors used
99 }LaserPos;
100 
101 typedef struct ErrorBytes
102 {
103  uint8_t F0; // function byte of the last command
104  uint8_t F1; // error class
105  uint8_t F2; // error group
106  uint8_t F3; // error specification
107 }ErrorBytes;
108 
109 
110 
111 
112 class Nav200
113 {
114 public:
115 
116  friend class SickNAV200;
117  Nav200();
118  ~Nav200();
119 
120  int Initialise(Driver* device, Device* opaque, player_devaddr_t opaque_id);
121  int Terminate();
122 
123  int ProcessData();
124 
125  // standby mode
126  bool EnterStandby();
127  int GetVersionNumber();
128  char* GetVersionString(); //String pointer return is only valid till the next request to Nav200
129  short GetDeviceSerial();
130  bool rotateDirection(uint8_t direction);
131  bool GetReflectorPosition(uint8_t layer, uint8_t number, PositionXY & reflector);
132  bool ChangeReflectorPosition(uint8_t layer, uint8_t number, int newX, int newY);
133  bool InsertReflectorPosition(uint8_t layer, uint8_t number, int X, int Y);
134  bool DeleteReflectorPosition(uint8_t layer, uint8_t number, PositionXY & reflector);
135 
136  // read and set reflector radii
137  int GetReflectorRadius(uint8_t layer);
138  bool SetReflectorRadius(uint8_t layer, uint8_t radius);
139 
140  // mapping mode
141  bool EnterMapping();
142  int StartMapping(uint8_t layer, int X, int Y, short orientation, uint8_t radius);
143  int StartMappingMeasurement(uint8_t layer, uint8_t scans, int X, int Y, short orientation, uint8_t radius);
144  int StartNegativeMappingMeasurement(uint8_t layer, uint8_t scans, int X, int Y, short orientation, uint8_t radius);
145  bool MappingPosition(uint8_t layer, uint8_t number, PositionXY & reflector);
146 
147  // positioning mode
148  bool EnterPositioning();
149  bool EnterPositioningInput(uint8_t NumberOfMeasurements);
150  bool GetPositionAuto(LaserPos & laserPosition);
151  bool GetPositionSpeed(short speedX, short speedY, LaserPos & laserPosition);
152  bool GetPositionSpeedVelocity(short speedX, short speedY, short velocity, LaserPos & laserPosition);
153  bool GetPositionSpeedVelocityAbsolute(short speedX, short speedY, short velocity, LaserPos & laserPosition);
154  bool ChangeLayer(uint8_t layer);
155  bool ChangeLayerDefPosition(uint8_t layer, int X, int Y, short orientation);
156  bool SetActionRadii(int min, int max);
157  bool SelectNearest(uint8_t N_nearest);
158 
159  // upload mode
160  bool EnterUpload();
161  bool GetUploadTrans(uint8_t layer, ReflectorData & reflector);
162  // download mode
163  bool EnterDownload();
164  bool DownloadReflector(uint8_t layer, uint8_t number, int X, int Y);
165 
166 
167 protected:
168  // serial port descriptor
169  //int fd;
170  //struct termios oldtio;
171 
172  uint8_t receivedBuffer[BUFFER_SIZE];
173  int bytesReceived;
174  Nav200Command packet;
175  ErrorBytes error;
176 
177  void PrintErrorMsg(void);
178 
179  int ReadFromNav200(int timeout_usec=5000000);
180  int WriteCommand(char mode, char function, int dataLength, uint8_t * data);
181  uint8_t CreateCRC(uint8_t* data, ssize_t len);
182 
183  // SickNav200 Driver info
184  Driver *sn200;
185 
186  // Opaque info - for setting filter
187  Device *opaque;
188  player_devaddr_t opaque_id;
189 
190 };
191 
192 
193 
194 #endif
Definition: nav200.h:112
A device address.
Definition: player.h:141
Definition: nav200.h:85
Definition: nav200.h:93
Definition: nav200.h:61
Encapsulates a device (i.e., a driver bound to an interface)
Definition: device.h:74
Definition: nav200.h:78
Base class for all drivers.
Definition: driver.h:108
T max(T a, T b)
Return the maximum of a, b.
Definition: utility.h:104
T min(T a, T b)
Return the minimum of a, b.
Definition: utility.h:91
Definition: nav200.h:101

Last updated 12 September 2005 21:38:45