Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 #ifndef HOKUYO_HH
00026 #define HOKUYO_HH
00027 
00028 #include <stdexcept>
00029 #include <termios.h>
00030 #include <string>
00031 #include <vector>
00032 #include <stdint.h>
00033 
00035 namespace hokuyo
00036 {
00038   const uint32_t MAX_READINGS = 1128;
00039 
00041   const int MAX_CMD_LEN = 100;
00042 
00044   const int MAX_SKIPPED = 1000000;
00045   
00047 #define DEF_EXCEPTION(name, parent) \
00048   class name  : public parent { \
00049   public: \
00050     name(const char* msg) : parent(msg) {} \
00051   }
00052   
00054   DEF_EXCEPTION(Exception, std::runtime_error);
00055 
00057   DEF_EXCEPTION(TimeoutException, Exception);
00058 
00060   DEF_EXCEPTION(CorruptedDataException, Exception);
00061 
00063   DEF_EXCEPTION(RepeatedTimeException, Exception);
00064 
00065 #undef DEF_EXCEPTION
00066 
00068   struct LaserConfig
00069   {
00071     float min_angle;
00073     float max_angle;
00075     float ang_increment;
00077     float time_increment;
00079     float scan_time;
00081     float min_range;
00083     float max_range;
00085     float range_res;
00086   };
00087 
00088 
00090   struct LaserScan
00091   {
00093     std::vector<float> ranges;
00095     std::vector<float> intensities;
00097     uint64_t self_time_stamp;
00099     uint64_t system_time_stamp;
00101     LaserConfig config;
00102   };
00103 
00104 
00106 
00122   class Laser
00123   {
00124   public:
00126     Laser();
00127 
00129     ~Laser();
00130   
00132 
00139     void open(const char * port_name);
00140 
00142 
00145     void close();
00146 
00148 
00153     void reset();
00154   
00156     bool portOpen() {  return laser_fd_ != -1; }
00157 
00159         
00160     void setToSCIP2();
00161 
00173     int sendCmd(const char* cmd, int timeout = -1);
00174 
00176 
00185     void getConfig(LaserConfig& config);
00186 
00187 
00189 
00198     int pollScan(LaserScan& scan, double min_ang, double max_ang, int clustering = 0, int timeout = -1);
00199 
00201 
00217     int requestScans(bool intensity, double min_ang, double max_ang, int clustering = 0, int skip = 0, int num = 0, int timeout = -1);
00218 
00220 
00226     int serviceScan(LaserScan& scan, int timeout = -1);
00227 
00229 
00232     int laserOff();
00233 
00235 
00238     int laserOn();
00239 
00241 
00244     int stopScanning();
00245 
00247 
00250     std::string getID();
00251 
00253 
00256     std::string getStatus();
00257 
00259 
00282     long long calcLatency(bool intensity, double min_ang, double max_ang, int clustering = 0, int skip = 0, int num = 0, int timeout = -1);
00283 
00285     void clearLatency()
00286     {
00287       offset_ = 0;
00288     }
00289 
00292     long long getLatency()
00293     {
00294       return offset_;
00295     }
00296 
00298 
00301     std::string getFirmwareVersion();
00302 
00304 
00307     std::string getVendorName();
00308 
00310 
00313     std::string getProductName();
00314 
00316 
00319     std::string getProtocolVersion();
00320 
00322 
00327     bool isIntensitySupported();
00328 
00331     void queryVersionInformation();
00332   
00334     int laserWrite(const char* msg);
00335 
00337     int laserReadline(char *buf, int len, int timeout = -1);
00338 
00340     int laserFlush();
00341 
00343     uint64_t readTime(int timeout = -1);
00344 
00345   private:
00347     
00348     long long int getHokuyoClockOffset(int reps, int timeout = -1);
00349 
00351     
00352     long long int getHokuyoScanStampToSystemStampOffset(bool intensity, double min_ang, double max_ang, int clustering, int skip, int reps, int timeout = -1);
00353      
00355     void querySensorConfig();
00356 
00358     char* laserReadlineAfter(char *buf, int len, const char *str, int timeout = -1);
00359 
00361     bool checkSum(const char* buf, int buf_len);
00362 
00364     void readData(LaserScan& scan, bool has_intensity, int timout = -1);
00365 
00366     int dmin_;
00367     int dmax_;
00368     int ares_;
00369     int amin_;
00370     int amax_;
00371     int afrt_;
00372     int rate_;
00373 
00374     int wrapped_;
00375 
00376     unsigned int last_time_;
00377 
00378     unsigned int time_repeat_count_;
00379 
00380     long long offset_;
00381 
00382     int laser_fd_;
00383 
00384     std::string vendor_name_;
00385     std::string product_name_;
00386     std::string serial_number_;
00387     std::string protocol_version_;
00388     std::string firmware_version_;
00389 
00390     char read_buf[256];
00391     int read_buf_start;
00392     int read_buf_end;
00393   };
00394 
00395 }
00396 
00397 #endif