INTRODUCTION Overview Download and Install Documentation Publications REPOSITORY Libraries DEVELOPER Dev Guide Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
hokuyo_aist.h 00001 /* 00002 * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics 00003 * http://gearbox.sf.net/ 00004 * Copyright (c) 2008 Geoffrey Biggs 00005 * 00006 * hokuyo_aist Hokuyo laser scanner driver. 00007 * 00008 * This distribution is licensed to you under the terms described in the LICENSE file included in 00009 * this distribution. 00010 * 00011 * This work is a product of the National Institute of Advanced Industrial Science and Technology, 00012 * Japan. Registration number: H20PRO-880 00013 * 00014 * This file is part of hokuyo_aist. 00015 * 00016 * hokuyo_aist is free software: you can redistribute it and/or modify it under the terms of the GNU 00017 * Lesser General Public License as published by the Free Software Foundation, either version 3 of 00018 * the License, or (at your option) any later version. 00019 * 00020 * hokuyo_aist is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 00021 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00022 * Lesser General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU Lesser General Public License along with hokuyo_aist. 00025 * If not, see <http://www.gnu.org/licenses/>. 00026 */ 00027 00028 #ifndef __HOKUYO_AIST_H 00029 #define __HOKUYO_AIST_H 00030 00031 #include <flexiport/port.h> 00032 #include <string> 00033 00034 #if defined (WIN32) 00035 typedef unsigned char uint8_t; 00036 typedef unsigned int uint32_t; 00037 #if defined (HOKUYO_AIST_STATIC) 00038 #define HOKUYO_AIST_EXPORT 00039 #elif defined (HOKUYO_AIST_EXPORTS) 00040 #define HOKUYO_AIST_EXPORT __declspec (dllexport) 00041 #else 00042 #define HOKUYO_AIST_EXPORT __declspec (dllimport) 00043 #endif 00044 #else 00045 #include <stdint.h> 00046 #define HOKUYO_AIST_EXPORT 00047 #endif 00048 00053 namespace hokuyo_aist 00054 { 00055 00057 class HOKUYO_AIST_EXPORT HokuyoError : public std::exception 00058 { 00059 public: 00064 HokuyoError (unsigned int code, std::string desc) 00065 : _errorCode (code), _errorDesc (desc) 00066 {} 00067 virtual ~HokuyoError () throw () {}; 00068 00069 virtual unsigned int Code () const throw () 00070 { 00071 return _errorCode; 00072 } 00073 00074 virtual const char* what () const throw () 00075 { 00076 return _errorDesc.c_str (); 00077 } 00078 00079 virtual std::string AsString () const throw(); 00080 00081 private: 00083 unsigned int _errorCode; 00085 std::string _errorDesc; 00086 }; 00087 #if defined (WIN32) 00088 // Exporting data members on Windows is a bloody pain (they have to be initialised somewhere else), 00089 // so we'll use #define's on Win32 and lose the type safety. 00091 #define HOKUYO_ERR_READ 1 00092 00093 #define HOKUYO_ERR_WRITE 2 00094 00095 #define HOKUYO_ERR_PROTOCOL 3 00096 00097 #define HOKUYO_ERR_CHANGEBAUD 4 00098 00099 #define HOKUYO_ERR_CONNECT_FAILED 5 00100 00101 #define HOKUYO_ERR_CLOSE_FAILED 6 00102 00103 #define HOKUYO_ERR_NODESTINATION 7 00104 00105 #define HOKUYO_ERR_BADFIRMWARE 8 00106 00107 #define HOKUYO_ERR_SCIPVERSION 9 00108 00109 #define HOKUYO_ERR_MEMORY 10 00110 00111 #define HOKUYO_ERR_UNSUPPORTED 11 00112 00113 #define HOKUYO_ERR_BADARG 12 00114 00115 #define HOKUYO_ERR_NODATA 13 00116 00117 #define HOKUYO_ERR_NOTSERIAL 14 00118 #else 00119 00120 const unsigned int HOKUYO_ERR_READ = 1; 00122 const unsigned int HOKUYO_ERR_WRITE = 2; 00124 const unsigned int HOKUYO_ERR_PROTOCOL = 3; 00126 const unsigned int HOKUYO_ERR_CHANGEBAUD = 4; 00128 const unsigned int HOKUYO_ERR_CONNECT_FAILED = 5; 00130 const unsigned int HOKUYO_ERR_CLOSE_FAILED = 6; 00132 const unsigned int HOKUYO_ERR_NODESTINATION = 7; 00134 const unsigned int HOKUYO_ERR_BADFIRMWARE = 8; 00136 const unsigned int HOKUYO_ERR_SCIPVERSION = 9; 00138 const unsigned int HOKUYO_ERR_MEMORY = 10; 00140 const unsigned int HOKUYO_ERR_UNSUPPORTED = 11; 00142 const unsigned int HOKUYO_ERR_BADARG = 12; 00144 const unsigned int HOKUYO_ERR_NODATA = 13; 00146 const unsigned int HOKUYO_ERR_NOTSERIAL = 14; 00147 #endif // defined (WIN32) 00148 00153 class HOKUYO_AIST_EXPORT HokuyoSensorInfo 00154 { 00155 public: 00156 friend class HokuyoLaser; 00157 00158 HokuyoSensorInfo (); 00159 HokuyoSensorInfo (const HokuyoSensorInfo &rhs); 00160 00162 HokuyoSensorInfo& operator= (const HokuyoSensorInfo &rhs); 00163 00165 std::string AsString (); 00166 00167 // Version details. 00169 std::string vendor; 00171 std::string product; 00173 std::string firmware; 00175 std::string protocol; 00177 std::string serial; 00178 00179 // Specification details. 00181 std::string model; 00183 unsigned int minRange; 00185 unsigned int maxRange; 00187 unsigned int steps; 00189 unsigned int firstStep; 00191 unsigned int lastStep; 00193 unsigned int frontStep; 00195 unsigned int standardSpeed; 00196 00197 // Status details. 00199 bool power; 00201 unsigned int speed; 00203 unsigned short speedLevel; 00205 std::string measureState; 00207 unsigned int baud; 00209 unsigned int time; 00211 std::string sensorDiagnostic; 00212 00213 // Calculated details 00216 double minAngle; 00219 double maxAngle; 00221 double resolution; 00223 unsigned int scanableSteps; 00224 00225 private: 00226 void SetDefaults (); 00227 void CalculateValues (); 00228 }; 00229 00231 class HOKUYO_AIST_EXPORT HokuyoData 00232 { 00233 public: 00234 friend class HokuyoLaser; 00235 00237 HokuyoData (); 00239 HokuyoData (uint32_t *ranges, unsigned int length, bool error, unsigned int time); 00241 HokuyoData (uint32_t *ranges, uint32_t *intensities, unsigned int length, 00242 bool error, unsigned int time); 00244 HokuyoData (const HokuyoData &rhs); 00245 ~HokuyoData (); 00246 00251 const uint32_t* Ranges () const { return _ranges; } 00253 const uint32_t* Intensities () const { return _intensities; } 00255 unsigned int Length () const { return _length; } 00260 bool GetErrorStatus () const { return _error; } 00262 std::string ErrorCodeToString (uint32_t errorCode); 00265 unsigned int TimeStamp () const { return _time; } 00266 00268 HokuyoData& operator= (const HokuyoData &rhs); 00270 uint32_t operator[] (unsigned int index); 00271 00273 std::string AsString (); 00274 00276 void CleanUp (); 00277 00278 protected: 00279 uint32_t *_ranges; 00280 uint32_t *_intensities; 00281 unsigned int _length; 00282 bool _error; 00283 unsigned int _time; 00284 bool _sensorIsUTM30LX; 00285 00286 void AllocateData (unsigned int length, bool includeIntensities = false); 00287 }; 00288 00300 class HOKUYO_AIST_EXPORT HokuyoLaser 00301 { 00302 public: 00303 HokuyoLaser (); 00304 ~HokuyoLaser (); 00305 00307 void Open (std::string portOptions); 00308 00317 unsigned int OpenWithProbing (std::string portOptions); 00318 00320 void Close (); 00321 00323 bool IsOpen () const; 00324 00326 void SetPower (bool on); 00327 00332 void SetBaud (unsigned int baud); 00333 00337 void Reset (); 00338 00348 void SetMotorSpeed (unsigned int speed); 00349 00351 void SetHighSensitivity (bool on); 00352 00356 void GetSensorInfo (HokuyoSensorInfo *info); 00357 00361 unsigned int GetTime (); 00362 00379 unsigned int GetRanges (HokuyoData *data, int startStep = -1, int endStep = -1, 00380 unsigned int clusterCount = 1); 00381 00392 unsigned int GetRangesByAngle (HokuyoData *data, double startAngle, double endAngle, 00393 unsigned int clusterCount = 1); 00394 00416 unsigned int GetNewRanges (HokuyoData *data, int startStep = -1, int endStep = -1, 00417 unsigned int clusterCount = 1); 00418 00431 unsigned int GetNewRangesByAngle (HokuyoData *data, double startAngle, double endAngle, 00432 unsigned int clusterCount = 1); 00433 00454 unsigned int GetNewRangesAndIntensities (HokuyoData *data, int startStep = -1, 00455 int endStep = -1, unsigned int clusterCount = 1); 00456 00469 unsigned int GetNewRangesAndIntensitiesByAngle (HokuyoData *data, double startAngle, 00470 double endAngle, unsigned int clusterCount = 1); 00471 00473 uint8_t SCIPVersion () const { return _scipVersion; } 00474 00477 void SetVerbose (bool verbose) { _verbose = verbose; } 00478 00481 void IgnoreUnknowns (bool ignore) { _ignoreUnknowns = ignore; } 00482 00484 double StepToAngle (unsigned int step); 00486 unsigned int AngleToStep (double angle); 00487 00488 private: 00489 flexiport::Port *_port; 00490 00491 uint8_t _scipVersion; 00492 bool _verbose, _sensorIsUTM30LX, _enableCheckSumWorkaround, _ignoreUnknowns; 00493 double _minAngle, _maxAngle, _resolution; 00494 int _firstStep, _lastStep, _frontStep; 00495 unsigned int _maxRange; 00496 00497 void ClearReadBuffer (); 00498 int ReadLine (char *buffer, int expectedLength = -1); 00499 int ReadLineWithCheck (char *buffer, int expectedLength = -1, bool hasSemicolon = false); 00500 void SkipLines (int count); 00501 int SendCommand (const char *cmd, const char *param, int paramLength, const char *extraOK); 00502 00503 void GetAndSetSCIPVersion (); 00504 void GetDefaults (); 00505 void ProcessVVLine (const char *buffer, HokuyoSensorInfo *info); 00506 void ProcessPPLine (const char *buffer, HokuyoSensorInfo *info); 00507 void ProcessIILine (const char *buffer, HokuyoSensorInfo *info); 00508 void Read2ByteRangeData (HokuyoData *data, unsigned int numSteps); 00509 void Read3ByteRangeData (HokuyoData *data, unsigned int numSteps); 00510 void Read3ByteRangeAndIntensityData (HokuyoData *data, unsigned int numSteps); 00511 00512 int ConfirmCheckSum (const char *buffer, int length, int expectedSum); 00513 }; 00514 00515 } // namespace hokuyo_aist 00516 00519 #endif // __HOKUYO_AIST_H |