INTRODUCTION Overview Download and Install Documentation Publications REPOSITORY Libraries DEVELOPER Dev Guide Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
messages.h00001 /* 00002 * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics 00003 * http://gearbox.sf.net/ 00004 * Copyright (c) 2004-2010 Alex Brooks 00005 * 00006 * This distribution is licensed to you under the terms described in 00007 * the LICENSE file included in this distribution. 00008 * 00009 */ 00010 00011 #ifndef SICK_ACFR_DRIVER_MESSAGES_H 00012 #define SICK_ACFR_DRIVER_MESSAGES_H 00013 00014 #include <string> 00015 #include <vector> 00016 #include <gbxsickacfr/sickdefines.h> 00017 #include <gbxsickacfr/gbxserialdeviceacfr/gbxserialdeviceacfr.h> 00018 00019 namespace gbxsickacfr { 00020 00021 std::string toHexString( const uChar *buf, int bufLen ); 00022 inline std::string toHexString( const std::vector<uChar> &buf ) 00023 {return toHexString( &(buf[0]), buf.size() );} 00024 00026 // Generic LMS RxMsg classes: 00027 // 00028 // - The SICK replies to commands with rxMsgs. 00029 // - RxMsgs are of a standard format, but some rxMsgs contain 00030 // extra rxMsg-type-specific data. 00031 // - This is handled with the abstract class 'LmsRxMsgData': 00032 // - The LmsRxMsg has a pointer to LmsRxMsgData, which should 00033 // be cast to the appropriate type depending on the rxMsg type. 00034 // 00035 // (Note that in continuous mode, the measurements continuously 00036 // sent out by the SICK are 'rxMsgs', even though there's no command). 00037 // 00039 00040 // Abstract class for representing rxMsg-type-specific data. 00041 class LmsRxMsgData : public IceUtil::Shared { 00042 public: 00043 virtual ~LmsRxMsgData() {} 00044 00045 // human-readable string 00046 virtual std::string toString() const=0; 00047 00048 virtual bool isError() const { return false; } 00049 virtual bool isWarn() const { return false; } 00050 00051 // Returns a freshly allocated object of the same type 00052 //virtual LmsRxMsgData *clone() const=0; 00053 }; 00054 typedef IceUtil::Handle<LmsRxMsgData> LmsRxMsgDataPtr; 00055 00056 // This class represents rxMsgs which the SICK uses to reply to commands. 00057 // All rxMsg types have the information in this class. 00058 // Some rxMsgs also have extra data, which is stored in the 'data' member. 00059 class LmsRxMsg : public gbxserialdeviceacfr::RxMsg { 00060 public: 00061 LmsRxMsg() 00062 : status(0), 00063 data(NULL) 00064 {} 00065 // ~LmsRxMsg() 00066 // { if (data) delete data; } 00067 00068 // private: 00069 // LmsRxMsg( const LmsRxMsg &other ); 00070 // LmsRxMsg &operator=( const LmsRxMsg &other ); 00071 // public: 00072 00073 uChar type; 00074 uChar status; 00075 LmsRxMsgDataPtr data; 00076 00077 bool isError() const; 00078 bool isWarn() const; 00079 00080 std::string toString() const; 00081 }; 00082 std::string toString( const LmsRxMsg &r ); 00083 typedef IceUtil::Handle<LmsRxMsg> LmsRxMsgPtr; 00084 inline std::string toString( const LmsRxMsgPtr &r ) 00085 { return toString(*r); } 00086 00088 // RxMsg-specific data classes 00089 // 00090 // - The set of classes below all inherit from the abstract 00091 // 'LmsRxMsgData' class. They represent the data contained 00092 // in specific rxMsg types. 00093 // - See 'parseRxMsg' in the .cpp file for details of which 00094 // classes go with which rxMsg codes. 00095 // 00097 00098 class LmsInitRxMsgData : public LmsRxMsgData { 00099 public: 00100 std::string description; 00101 00102 std::string toString() const { return description; } 00103 LmsRxMsgData *clone() const { return new LmsInitRxMsgData(*this); } 00104 }; 00105 00106 class LmsStatusRxMsgData : public LmsRxMsgData { 00107 public: 00108 std::string version; 00109 uChar operatingMode; 00110 uChar status; 00111 std::string manufacturer; 00112 uChar variantType; 00113 uint16_t pollution[POLLUTION_LENGTH]; 00114 uint16_t refPollution[REF_POLLUTION_LENGTH]; 00115 uint16_t calibPollution[CALIB_POLLUTION_LENGTH]; 00116 uint16_t calibRefPollution[CALIB_REF_POLLUTION_LENGTH]; 00117 uint16_t numMotorRevolutions; 00118 uint16_t refScale1Dark100Pct; 00119 uint16_t refScale2Dark100Pct; 00120 uint16_t refScale1Dark66Pct; 00121 uint16_t refScale2Dark66Pct; 00122 uint16_t signalAmplitudePct; 00123 uint16_t currentAngle; 00124 uint16_t peakThreshold; 00125 uint16_t angleOfMeasurement; 00126 uint16_t calibSignalAmplitude; 00127 uint16_t targetStopThreshold; 00128 uint16_t targetPeakThreshold; 00129 uint16_t actualStopThreshold; 00130 uint16_t actualPeakThreshold; 00131 uChar measuringMode; 00132 uint16_t refSingleMeasuredValues; 00133 uint16_t refMeanMeasuredValues; 00134 uint16_t scanningAngle; 00135 uint16_t angularResolution; 00136 uChar restartMode; 00137 uChar restartTime; 00138 uint16_t baudRate; 00139 uChar evaluationNumber; 00140 uChar permanentBaudRate; 00141 uChar lmsAddress; 00142 uChar fieldSetNumber; 00143 uChar currentMeasuredValueUnit; 00144 uChar laserSwitchOff; 00145 std::string softwareVersion; 00146 00147 std::string toString() const; 00148 LmsRxMsgData *clone() const { return new LmsStatusRxMsgData(*this); } 00149 }; 00150 00151 class LmsSwitchOperatingModeRxMsgData : public LmsRxMsgData { 00152 public: 00153 uChar success; 00154 00155 bool isError() const { return success != OPERATING_MODE_RESPONSE_SUCCESS; } 00156 std::string toString() const { return modeSwitchSuccessToString(success); } 00157 LmsRxMsgData *clone() const { return new LmsSwitchOperatingModeRxMsgData(*this); } 00158 }; 00159 00160 class LmsConfigurationData : public LmsRxMsgData { 00161 public: 00162 00163 // Default values for all these fuckers 00164 LmsConfigurationData(); 00165 bool operator==( const LmsConfigurationData &o ) const; 00166 bool operator!=( const LmsConfigurationData &o ) const 00167 { return !(operator==(o)); } 00168 00169 uint16_t blanking; 00170 uChar sensitivity; 00171 uChar availability; 00172 uChar measuringMode; 00173 uChar measuredValueUnit; 00174 uChar transientFieldSet; 00175 uChar subtractiveFields; // 14 00176 uChar multipleEvaluation; 00177 uChar restart; 00178 uChar restartTime; 00179 uChar multipleEvaluationForSuppressed; 00180 uChar contourARef; 00181 uChar contourAPosToleranceBand; // 20 00182 uChar contourANegToleranceBand; 00183 uChar contourAStartAngle; 00184 uChar contourAStopAngle; 00185 uChar contourBRef; 00186 uChar contourBPosToleranceBand; 00187 uChar contourBNegToleranceBand; 00188 uChar contourBStartAngle; 00189 uChar contourBStopAngle; 00190 uChar contourARef2; 00191 uChar contourAPosToleranceBand2; // 30 00192 uChar contourCNegToleranceBand; 00193 uChar contourCStartAngle; 00194 uChar contourCStopAngle; 00195 uChar pixelOrientedEvaluation; 00196 uChar singleMeasuredValueEvaluation; 00197 uint16_t restartTimeFields; 00198 uint16_t multipleEvaluationForDazzle; 00199 00200 std::string toString() const; 00201 LmsRxMsgData *clone() const { return new LmsConfigurationData(*this); } 00202 }; 00203 00204 class LmsConfigurationRxMsgData : public LmsRxMsgData { 00205 public: 00206 LmsConfigurationData config; 00207 uChar configSuccess; 00208 00209 std::string toString() const; 00210 LmsRxMsgData *clone() const { return new LmsConfigurationRxMsgData(*this); } 00211 bool isError() const { return configSuccess != CONFIGURATION_SUCCESS; } 00212 }; 00213 00214 class LmsSwitchVariantRxMsgData : public LmsRxMsgData { 00215 public: 00216 uChar success; 00217 uint16_t scanningAngle; 00218 uint16_t angularResolution; 00219 00220 std::string toString() const; 00221 LmsRxMsgData *clone() const { return new LmsSwitchVariantRxMsgData(*this); } 00222 bool isError() const { return success != SWITCH_VARIANT_SUCCESS; } 00223 }; 00224 00225 class LmsMeasurementData : public LmsRxMsgData { 00226 public: 00227 00228 // ranges in metres 00229 std::vector<float> ranges; 00230 std::vector<uChar> intensities; 00231 00232 std::string toString() const; 00233 LmsRxMsgData *clone() const { return new LmsMeasurementData(*this); } 00234 }; 00235 00236 class LmsErrorRxMsgData : public LmsRxMsgData { 00237 public: 00238 00239 std::vector<uChar> errorTypes; 00240 std::vector<uChar> errorCodes; 00241 00242 std::string toString() const; 00243 LmsRxMsgData *clone() const { return new LmsErrorRxMsgData(*this); } 00244 bool isError() const; 00245 bool isWarn() const; 00246 }; 00247 00248 class LmsOperatingDataCounterData : public LmsRxMsgData { 00249 public: 00250 00251 int hoursOfOperation; 00252 int numSwitchOns; 00253 00254 std::string toString() const; 00255 LmsRxMsgData *clone() const { return new LmsOperatingDataCounterData(*this); } 00256 }; 00257 00259 00260 // If a complete telegram was found, returns it 00261 // (also sets bytesParsed regardless of whether a complete message was found) 00262 LmsRxMsgPtr parseBufferForRxMsgs( const uChar *buffer, 00263 int bufferLength, 00264 int &bytesParsed ); 00265 00266 void constructTelegram( std::vector<uChar> &buffer, 00267 const std::vector<uChar> &commandAndData ); 00268 00269 // SICK parameters can be changed in installation mode. 00270 void constructRequestInstallationMode( std::vector<uChar> &commandAndData ); 00271 00272 void constructRequestContinuousMode( std::vector<uChar> &commandAndData ); 00273 void constructRequestMeasuredOnRequestMode( std::vector<uChar> &commandAndData ); 00274 00275 void constructInitAndReset( std::vector<uChar> &commandAndData ); 00276 00277 void constructStatusRequest( std::vector<uChar> &commandAndData ); 00278 00279 void constructConfigurationRequest( std::vector<uChar> &commandAndData ); 00280 00281 void constructConfigurationCommand( const LmsConfigurationData &c, 00282 std::vector<uChar> &commandAndData ); 00283 00284 void constructRequestErrorMessage( std::vector<uChar> &commandAndData ); 00285 00286 void constructSwitchVariant( uint16_t scanningAngle, 00287 uint16_t angularResolution, 00288 std::vector<uChar> &commandAndData ); 00289 00290 void constructRequestOperatingDataCounter( std::vector<uChar> &commandAndData ); 00291 00292 void constructRequestBaudRate( std::vector<uChar> &commandAndData, int baudRate ); 00293 } 00294 00295 #endif |