INTRODUCTION
Overview
Download and Install
Documentation
Publications

REPOSITORY
Libraries

DEVELOPER
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
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_EXPORTS)
00038                 #define HOKUYO_AIST_EXPORT       __declspec (dllexport)
00039         #else
00040                 #define HOKUYO_AIST_EXPORT       __declspec (dllimport)
00041         #endif
00042 #else
00043         #include <stdint.h>
00044         #define HOKUYO_AIST_EXPORT
00045 #endif
00046 
00051 namespace hokuyo_aist
00052 {
00053 
00055 class HOKUYO_AIST_EXPORT HokuyoError : public std::exception
00056 {
00057         public:
00062                 HokuyoError (unsigned int code, std::string desc)
00063                         : _errorCode (code), _errorDesc (desc)
00064                 {}
00065                 virtual ~HokuyoError (void) throw () {};
00066 
00067                 virtual unsigned int Code (void) const throw ()
00068                 {
00069                         return _errorCode;
00070                 }
00071 
00072                 virtual const char* what (void) const throw ()
00073                 {
00074                         return _errorDesc.c_str ();
00075                 }
00076 
00077                 virtual std::string AsString (void) const throw();
00078 
00079         private:
00081                 unsigned int _errorCode;
00083                 std::string _errorDesc;
00084 };
00085 #if defined (WIN32)
00086 // Exporting data members on Windows is a bloody pain (they have to be initialised somewhere else),
00087 // so we'll use #define's on Win32 and lose the type safety.
00089 #define HOKUYO_ERR_READ            1
00091 #define HOKUYO_ERR_WRITE           2
00093 #define HOKUYO_ERR_PROTOCOL        3
00095 #define HOKUYO_ERR_CHANGEBAUD      4
00097 #define HOKUYO_ERR_CONNECT_FAILED  5
00099 #define HOKUYO_ERR_CLOSE_FAILED    6
00101 #define HOKUYO_ERR_NODESTINATION   7
00103 #define HOKUYO_ERR_BADFIRMWARE     8
00105 #define HOKUYO_ERR_SCIPVERSION     9
00107 #define HOKUYO_ERR_MEMORY          10
00109 #define HOKUYO_ERR_UNSUPPORTED     11
00111 #define HOKUYO_ERR_BADARG          12
00113 #define HOKUYO_ERR_NODATA          13
00115 #define HOKUYO_ERR_NOTSERIAL       14
00116 #else
00118 const unsigned int HOKUYO_ERR_READ            = 1;
00120 const unsigned int HOKUYO_ERR_WRITE           = 2;
00122 const unsigned int HOKUYO_ERR_PROTOCOL        = 3;
00124 const unsigned int HOKUYO_ERR_CHANGEBAUD      = 4;
00126 const unsigned int HOKUYO_ERR_CONNECT_FAILED  = 5;
00128 const unsigned int HOKUYO_ERR_CLOSE_FAILED    = 6;
00130 const unsigned int HOKUYO_ERR_NODESTINATION   = 7;
00132 const unsigned int HOKUYO_ERR_BADFIRMWARE     = 8;
00134 const unsigned int HOKUYO_ERR_SCIPVERSION     = 9;
00136 const unsigned int HOKUYO_ERR_MEMORY          = 10;
00138 const unsigned int HOKUYO_ERR_UNSUPPORTED     = 11;
00140 const unsigned int HOKUYO_ERR_BADARG          = 12;
00142 const unsigned int HOKUYO_ERR_NODATA          = 13;
00144 const unsigned int HOKUYO_ERR_NOTSERIAL       = 14;
00145 #endif // defined (WIN32)
00146 
00151 class HOKUYO_AIST_EXPORT HokuyoSensorInfo
00152 {
00153         public:
00154                 friend class HokuyoLaser;
00155 
00156                 HokuyoSensorInfo (void);
00157                 HokuyoSensorInfo (const HokuyoSensorInfo &rhs);
00158 
00160                 HokuyoSensorInfo& operator= (const HokuyoSensorInfo &rhs);
00161 
00163                 std::string AsString (void);
00164 
00165                 // Version details.
00167                 std::string vendor;
00169                 std::string product;
00171                 std::string firmware;
00173                 std::string protocol;
00175                 std::string serial;
00176 
00177                 // Specification details.
00179                 std::string model;
00181                 unsigned int minRange;
00183                 unsigned int maxRange;
00185                 unsigned int steps;
00187                 unsigned int firstStep;
00189                 unsigned int lastStep;
00191                 unsigned int frontStep;
00193                 unsigned int standardSpeed;
00194 
00195                 // Status details.
00197                 bool power;
00199                 unsigned int speed;
00201                 unsigned short speedLevel;
00203                 std::string measureState;
00205                 unsigned int baud;
00207                 unsigned int time;
00209                 std::string sensorDiagnostic;
00210 
00211                 // Calculated details
00214                 double minAngle;
00217                 double maxAngle;
00219                 double resolution;
00221                 unsigned int scanableSteps;
00222 
00223         private:
00224                 void SetDefaults (void);
00225                 void CalculateValues (void);
00226 };
00227 
00229 class HOKUYO_AIST_EXPORT HokuyoData
00230 {
00231         public:
00232                 friend class HokuyoLaser;
00233 
00235                 HokuyoData (void);
00237                 HokuyoData (uint32_t *ranges, unsigned int length, bool error, unsigned int time);
00239                 HokuyoData (uint32_t *ranges, uint32_t *intensities, unsigned int length,
00240                                         bool error, unsigned int time);
00242                 HokuyoData (const HokuyoData &rhs);
00243                 ~HokuyoData (void);
00244 
00249                 const uint32_t* Ranges (void) const                 { return _ranges; }
00251                 const uint32_t* Intensities (void) const            { return _intensities; }
00253                 unsigned int Length (void) const                    { return _length; }
00258                 bool GetErrorStatus (void) const                    { return _error; }
00260                 std::string ErrorCodeToString (uint32_t errorCode);
00263                 unsigned int TimeStamp (void) const                 { return _time; }
00264 
00266                 HokuyoData& operator= (const HokuyoData &rhs);
00268                 uint32_t operator[] (unsigned int index);
00269 
00271                 std::string AsString (void);
00272 
00274                 void CleanUp (void);
00275 
00276         protected:
00277                 uint32_t *_ranges;
00278                 uint32_t *_intensities;
00279                 unsigned int _length;
00280                 bool _error;
00281                 unsigned int _time;
00282                 bool _sensorIsUTM30LX;
00283 
00284                 void AllocateData (unsigned int length, bool includeIntensities = false);
00285 };
00286 
00298 class HOKUYO_AIST_EXPORT HokuyoLaser
00299 {
00300         public:
00301                 HokuyoLaser (void);
00302                 ~HokuyoLaser (void);
00303 
00305                 void Open (std::string portOptions);
00306 
00308                 void Close (void);
00309 
00311                 bool IsOpen (void) const;
00312 
00314                 void SetPower (bool on);
00315 
00320                 void SetBaud (unsigned int baud);
00321 
00325                 void Reset (void);
00326 
00336                 void SetMotorSpeed (unsigned int speed);
00337 
00339                 void SetHighSensitivity (bool on);
00340 
00344                 void GetSensorInfo (HokuyoSensorInfo *info);
00345 
00349                 unsigned int GetTime (void);
00350 
00369                 unsigned int GetRanges (HokuyoData *data, int startStep = -1, int endStep = -1,
00370                                                                 unsigned int clusterCount = 1);
00371 
00384                 unsigned int GetRangesByAngle (HokuyoData *data, double startAngle, double endAngle,
00385                                                                 unsigned int clusterCount = 1);
00386 
00408                 unsigned int GetNewRanges (HokuyoData *data, int startStep = -1, int endStep = -1,
00409                                                                 unsigned int clusterCount = 1);
00410 
00423                 unsigned int GetNewRangesByAngle (HokuyoData *data, double startAngle, double endAngle,
00424                                                                 unsigned int clusterCount = 1);
00425 
00446                 unsigned int GetNewRangesAndIntensities (HokuyoData *data, int startStep = -1,
00447                                                                                                 int endStep = -1, unsigned int clusterCount = 1);
00448 
00461                 unsigned int GetNewRangesAndIntensitiesByAngle (HokuyoData *data, double startAngle,
00462                                                                                                 double endAngle, unsigned int clusterCount = 1);
00463 
00465                 uint8_t SCIPVersion (void) const            { return _scipVersion; }
00466 
00469                 void SetVerbose (bool verbose)              { _verbose = verbose; }
00470 
00472                 double StepToAngle (unsigned int step);
00474                 unsigned int AngleToStep (double angle);
00475 
00476         private:
00477                 flexiport::Port *_port;
00478 
00479                 uint8_t _scipVersion;
00480                 bool _verbose, _sensorIsUTM30LX;
00481                 double _minAngle, _maxAngle, _resolution;
00482                 int _firstStep, _lastStep, _frontStep;
00483                 unsigned int _maxRange;
00484 
00485                 void ClearReadBuffer (void);
00486                 int ReadLine (char *buffer, int expectedLength = -1);
00487                 int ReadLineWithCheck (char *buffer, int expectedLength = -1, bool hasSemicolon = false);
00488                 void SkipLines (int count);
00489                 int SendCommand (const char *cmd, const char *param, int paramLength, const char *extraOK);
00490 
00491                 void GetAndSetSCIPVersion (void);
00492                 void GetDefaults (void);
00493                 void Read2ByteRangeData (HokuyoData *data, unsigned int numSteps);
00494                 void Read3ByteRangeData (HokuyoData *data, unsigned int numSteps);
00495                 void Read3ByteRangeAndIntensityData (HokuyoData *data, unsigned int numSteps);
00496 };
00497 
00498 } // namespace hokuyo_aist
00499 
00502 #endif // __HOKUYO_AIST_H
 

Generated for GearBox by  doxygen 1.4.5