hokuyo
/build/rock-master-18.09-drivers-hokuyo-0.20160711/hokuyo.hh
Go to the documentation of this file.
1 #ifndef URG_H
2 #define URG_H
3 
4 #include <map>
5 #include <string>
6 #include <iosfwd>
7 #include <sys/types.h>
8 #include <base/samples/LaserScan.hpp>
9 #include <iodrivers_base/Driver.hpp>
10 
19 class URG : public iodrivers_base::Driver {
20 public:
21  struct StatusCode;
22  struct SimpleCommand;
23 
25  static const int MDMS_COMMAND_LENGTH = 15;
29  static const int MDMS_DATA_OFFSET = MDMS_TIMESTAMP_OFFSET + 6;
30 
34  struct DeviceInfo {
36  : version(UNKNOWN), dMin(0), dMax(0), resolution(0), stepMin(0), stepMax(0), stepFront(0), motorSpeed(0) { }
37 
38  enum VERSIONS {
43  };
44  std::map<std::string, std::string> values;
46  int dMin;
47  int dMax;
48  int resolution;
49  int stepMin;
50  int stepMax;
51  int stepFront;
52  float motorSpeed;
53  };
54 
56  enum ERROR_CODES {
57  OK = 0,
58 
68 
69  BAD_REPLY = 100,
72  BAD_STATE = 123,
73  READ_FAILED = 124,
74  BAD_RATE = 125,
75  WRITE_FAILED = 126,
76  READ_TIMEOUT = 127,
81 
82  DUPLICATE = 132,
83 
84  UNKNOWN = 200,
87 
88  END = 500
89  };
90 
91 private:
92  static const unsigned int MAX_PACKET_SIZE = 8192;
93 
95  int baudrate;
96  char m_last_status[3];
98  ERROR_CODES m_error;
100  DeviceInfo m_info;
101 
103  int last_device_timestamp;
104  base::Time device_time_offset;
105 
107  base::Time last_sample_time;
108 
110  static const int MAX_RANGE_READING = 60000;
111  std::vector<float> remission_lookup;
112  float normaliseRemission( int raw, int range );
113  void initRemissionLookup();
114 
116  int sample_count;
117 
119  int readAnswer(char* buffer, size_t buffer_size, char const* expected_cmd, int timeout = 1000);
120 
125  int readAnswer(char* buffer, size_t buffer_size, char const** expected_cmds, int timeout = 1000);
126 
127  bool readInfo();
128  bool simpleCommand(SimpleCommand const& cmd, int timeout = 1000);
135  bool write(char const* string, int timeout = 1000);
136 
137  bool error(ERROR_CODES code);
138  bool parseErrorCode(char const* code, StatusCode const* specific_codes);
139  bool infoCommand(std::map<std::string, std::string>& result, char const* cmd, bool scip1 = false);
140  bool timeCommand(int &device_timestamp, int timeout);
141 
142 protected:
143  int extractPacket(uint8_t const* buffer, size_t buffer_size) const;
144 
145 public:
146  URG();
147  ~URG();
148 
151  void openURI(std::string const& filename);
154  bool open(std::string const& filename);
157  bool fullSerialReset();
159  bool initCommunication(int timeout = 1000);
161  bool measureCommunicationLatency(int timeout = 1000);
163  void close();
166  DeviceInfo getInfo() const { return m_info; };
167 
181  bool startAcquisition(int nScans, int startStep = -1, int endStep = -1, int scanInterval = 0, int clusterCount = 1, bool includeRemission = false );
183  bool stopAcquisition();
187  bool readRanges(base::samples::LaserScan& range, int timeout = -1);
194  bool setBaudrate(int brate);
195 
204  int getPacketCounter();
205 
207  ERROR_CODES error() const { return m_error; }
209  static char const* errorString(int error_code);
211  char const* errorString() const { return errorString(m_error); }
212 };
213 
214 std::ostream& operator << (std::ostream& io, URG::DeviceInfo info);
215 
216 #endif
Definition: hokuyo.hh:72
float motorSpeed
the step number in front of the device
Definition: hokuyo.hh:52
Definition: hokuyo.hh:39
Definition: hokuyo.hh:82
Definition: hokuyo.hh:41
static const int MDMS_TIMESTAMP_OFFSET
Definition: hokuyo.hh:27
int stepFront
the last measurable step
Definition: hokuyo.hh:51
Definition: hokuyo.hh:75
Definition: hokuyo.hh:78
Definition: hokuyo.hh:84
Definition: hokuyo.hh:65
Definition: hokuyo.hh:80
void openURI(std::string const &filename)
Definition: hokuyo.cc:801
bool measureCommunicationLatency(int timeout=1000)
Definition: hokuyo.cc:531
Definition: hokuyo.hh:67
bool initCommunication(int timeout=1000)
Definition: hokuyo.cc:468
Definition: hokuyo.hh:66
Definition: hokuyo.hh:71
Definition: hokuyo.hh:61
bool stopAcquisition()
Definition: hokuyo.cc:790
Definition: hokuyo.hh:70
Definition: hokuyo.hh:34
bool open(std::string const &filename)
Definition: hokuyo.cc:813
~URG()
Definition: hokuyo.cc:154
Definition: hokuyo.hh:42
ERROR_CODES error() const
Definition: hokuyo.hh:207
Definition: hokuyo.hh:76
Definition: hokuyo.hh:57
DeviceInfo getInfo() const
Definition: hokuyo.hh:166
Definition: hokuyo.cc:118
bool readRanges(base::samples::LaserScan &range, int timeout=-1)
Definition: hokuyo.cc:633
Definition: hokuyo.hh:79
Definition: hokuyo.hh:63
DeviceInfo()
Definition: hokuyo.hh:35
Definition: hokuyo.hh:60
static const int MDMS_DATA_OFFSET
Definition: hokuyo.hh:29
int stepMax
the first measurable range
Definition: hokuyo.hh:50
Definition: hokuyo.hh:62
Definition: hokuyo.hh:73
VERSIONS version
Definition: hokuyo.hh:45
Definition: hokuyo.hh:19
Definition: hokuyo.hh:69
Definition: hokuyo.hh:59
Definition: hokuyo.hh:85
int dMax
the minimal measurable distance
Definition: hokuyo.hh:47
bool fullSerialReset()
Definition: hokuyo.cc:508
int resolution
the biggest measurable distance
Definition: hokuyo.hh:48
int getPacketCounter()
Definition: hokuyo.cc:785
ERROR_CODES
Definition: hokuyo.hh:56
std::map< std::string, std::string > values
Definition: hokuyo.hh:44
int stepMin
how much steps in one full turn
Definition: hokuyo.hh:49
int dMin
Definition: hokuyo.hh:46
static const int MDMS_COMMAND_LENGTH
Definition: hokuyo.hh:25
VERSIONS
Definition: hokuyo.hh:38
Definition: hokuyo.hh:88
Definition: hokuyo.cc:25
bool startAcquisition(int nScans, int startStep=-1, int endStep=-1, int scanInterval=0, int clusterCount=1, bool includeRemission=false)
Definition: hokuyo.cc:587
char const * errorString() const
Definition: hokuyo.hh:211
Definition: hokuyo.hh:64
void close()
Definition: hokuyo.cc:794
std::ostream & operator<<(std::ostream &io, URG::DeviceInfo info)
Definition: hokuyo.hh:77
Definition: hokuyo.hh:86
Definition: hokuyo.hh:74
bool setBaudrate(int brate)
Definition: hokuyo.cc:552
Definition: hokuyo.hh:40
int extractPacket(uint8_t const *buffer, size_t buffer_size) const
Definition: hokuyo.cc:347
URG()
Definition: hokuyo.cc:143