SickPLS.hh
Go to the documentation of this file.
00001 
00015 #ifndef SICK_PLS_HH
00016 #define SICK_PLS_HH
00017 
00018 /* Implementation dependencies */
00019 #include <string>
00020 #include <iostream>
00021 #include <termios.h>
00022 
00023 #include "SickLIDAR.hh"
00024 #include "SickException.hh"
00025 
00026 #include "SickPLSBufferMonitor.hh"
00027 #include "SickPLSMessage.hh"
00028 
00029 /* Macro definitions */
00030 #define DEFAULT_SICK_PLS_SICK_BAUD                                       (B500000)  ///< Initial baud rate of the PLS (whatever is set in flash)
00031 #define DEFAULT_SICK_PLS_HOST_ADDRESS                                     (0x80)  ///< Client/host default serial address
00032 #define DEFAULT_SICK_PLS_SICK_ADDRESS                                     (0x00)  ///< Sick PLS default serial address
00033 #define DEFAULT_SICK_PLS_SICK_PASSWORD                                "SICK_PLS"  ///< Password for entering installation mode
00034 #define DEFAULT_SICK_PLS_SICK_MESSAGE_TIMEOUT                (unsigned int)(20e6)  ///< The max time to wait for a message reply (usecs)
00035 #define DEFAULT_SICK_PLS_SICK_SWITCH_MODE_TIMEOUT            (unsigned int)(20e6)  ///< Can take the Sick LD up to 3 seconds to reply (usecs)
00036 #define DEFAULT_SICK_PLS_SICK_CONFIG_MESSAGE_TIMEOUT        (unsigned int)(20e6)  ///< The sick can take some time to respond to config commands (usecs)
00037 #define DEFAULT_SICK_PLS_BYTE_INTERVAL                                      (55)  ///< Minimum time in microseconds between transmitted bytes
00038 //#define DEFAULT_SICK_PLS_BYTE_INTERVAL                                      (0)  ///< Minimum time in microseconds between transmitted bytes
00039 #define DEFAULT_SICK_PLS_NUM_TRIES                                           (1)  ///< The max number of tries before giving up on a request
00040 
00041 /* Associate the namespace */
00042 namespace SickToolbox {
00043 
00050   class SickPLS : public SickLIDAR< SickPLSBufferMonitor, SickPLSMessage >
00051   {
00052 
00053   public:
00054 
00056         /* TODO: I think this should be 180 * 2 */
00057     static const uint16_t SICK_MAX_NUM_MEASUREMENTS = 721;                     
00058 
00059 
00064     enum sick_pls_scan_angle_t {
00066       SICK_SCAN_ANGLE_180 = 180,                                               
00067       SICK_SCAN_ANGLE_UNKNOWN = 0xFF                                           
00068     };
00069 
00074     enum sick_pls_scan_resolution_t {
00076       SICK_SCAN_RESOLUTION_50 = 50,                                            
00077       SICK_SCAN_RESOLUTION_UNKNOWN = 0xFF                                      
00078     };
00079 
00084     enum sick_pls_measuring_units_t {
00085 
00086       /* Only in cm */
00087       SICK_MEASURING_UNITS_CM = 0x00,                                          
00088       SICK_MEASURING_UNITS_UNKNOWN = 0xFF                                      
00089     };
00090 
00095     enum sick_pls_status_t {
00096       SICK_STATUS_OK = 0x00,                                                   
00097       SICK_STATUS_ERROR = 0x01,                                                
00098       SICK_STATUS_UNKNOWN = 0xFF                                               
00099     };
00100 
00106     enum sick_pls_operating_mode_t {
00107 
00110       SICK_OP_MODE_INSTALLATION = 0x00,                                        
00111       SICK_OP_MODE_DIAGNOSTIC = 0x10,                                          
00112       SICK_OP_MODE_MONITOR_STREAM_MIN_VALUE_FOR_EACH_SEGMENT = 0x20,           
00113       SICK_OP_MODE_MONITOR_TRIGGER_MIN_VALUE_ON_OBJECT = 0x21,                 
00114       SICK_OP_MODE_MONITOR_STREAM_MIN_VERT_DIST_TO_OBJECT = 0x22,              
00115       SICK_OP_MODE_MONITOR_TRIGGER_MIN_VERT_DIST_TO_OBJECT = 0x23,             
00116       SICK_OP_MODE_MONITOR_STREAM_VALUES = 0x24,                               
00117       SICK_OP_MODE_MONITOR_REQUEST_VALUES = 0x25,                              
00118       SICK_OP_MODE_MONITOR_STREAM_MEAN_VALUES = 0x26,                          
00119       SICK_OP_MODE_MONITOR_STREAM_VALUES_SUBRANGE = 0x27,                      
00120       SICK_OP_MODE_MONITOR_STREAM_MEAN_VALUES_SUBRANGE = 0x28,                 
00121       SICK_OP_MODE_MONITOR_STREAM_VALUES_WITH_FIELDS = 0x29,                   
00122       SICK_OP_MODE_MONITOR_STREAM_VALUES_FROM_PARTIAL_SCAN = 0x2A,             
00123       SICK_OP_MODE_MONITOR_STREAM_RANGE_AND_REFLECT_FROM_PARTIAL_SCAN = 0x2B,  
00124       SICK_OP_MODE_MONITOR_STREAM_MIN_VALUES_FOR_EACH_SEGMENT_SUBRANGE = 0x2C, 
00125       SICK_OP_MODE_MONITOR_NAVIGATION = 0x2E,                                  
00126       SICK_OP_MODE_MONITOR_STREAM_RANGE_AND_REFLECT = 0x50,                    
00127       SICK_OP_MODE_UNKNOWN = 0xFF                                              
00128     };
00129 
00134     enum sick_pls_baud_t {
00135       SICK_BAUD_9600 = 0x42,                                                   
00136       SICK_BAUD_19200 = 0x41,                                                  
00137       SICK_BAUD_38400 = 0x40,                                                  
00138       SICK_BAUD_500K = 0x48,                                                   
00139       SICK_BAUD_UNKNOWN = 0xFF                                                 
00140     };
00141 
00142 
00153     typedef struct sick_pls_operating_status_tag {
00154       uint16_t sick_scan_angle;                                                
00155       uint16_t sick_scan_resolution;                                           
00156       uint16_t sick_num_motor_revs;                                            
00157       uint8_t sick_operating_mode;                                             
00158       uint8_t sick_laser_mode;                                                 
00159       uint8_t sick_measuring_units;                                            
00160       uint8_t sick_address;                                                    
00161     } sick_pls_operating_status_t;
00162 
00163 
00164 
00174     typedef struct sick_pls_baud_status_tag {
00175       uint16_t sick_baud_rate;                                                 
00176       uint8_t sick_permanent_baud_rate;                                        
00177     } sick_pls_baud_status_t;
00178 
00179 
00190     typedef struct sick_pls_scan_profile_b0_tag {
00191       uint16_t sick_num_measurements;                                          
00192       uint16_t sick_measurements[SICK_MAX_NUM_MEASUREMENTS];                   
00193       uint8_t sick_telegram_index;                                             
00194       uint8_t sick_real_time_scan_index;                                       
00195       uint8_t sick_partial_scan_index;                                         
00196     } sick_pls_scan_profile_b0_t;
00197 
00198 
00200     SickPLS( const std::string sick_device_path );
00201 
00203     ~SickPLS( );
00204 
00206     bool Initialize( const sick_pls_baud_t desired_baud_rate )
00207       throw( SickConfigException, SickTimeoutException, SickIOException, SickThreadException);
00208 
00210     void Uninitialize( ) throw( SickConfigException, SickTimeoutException, SickIOException, SickThreadException );
00211 
00213     std::string GetSickDevicePath( ) const;
00214 
00216     double GetSickScanAngle( ) const throw( SickConfigException );
00217 
00219     double GetSickScanResolution( ) const throw( SickConfigException );
00220 
00222     SickPLS::sick_pls_measuring_units_t GetSickMeasuringUnits( ) const throw( SickConfigException );
00223 
00225     sick_pls_operating_mode_t GetSickOperatingMode( ) const throw( SickConfigException );
00226 
00228     void GetSickScan( unsigned int * const measurement_values,
00229                       unsigned int & num_measurement_values) throw( SickConfigException, SickTimeoutException, SickIOException, SickThreadException);
00230 
00232     sick_pls_status_t GetSickStatus( ) throw( SickConfigException, SickTimeoutException, SickIOException, SickThreadException );
00233 
00235     void ResetSick( ) throw( SickConfigException, SickTimeoutException, SickIOException, SickThreadException );
00236 
00238     std::string GetSickStatusAsString( ) const;
00239 
00240 
00241 
00242 
00243     /*
00244      * NOTE: The following methods are given to make working with our
00245      *       predefined types a bit more manageable.
00246      */
00247 
00248 
00250     static sick_pls_scan_angle_t IntToSickScanAngle( const int scan_angle_int );
00251 
00253     static sick_pls_scan_resolution_t IntToSickScanResolution( const int scan_resolution_int );
00254 
00256     static sick_pls_scan_resolution_t DoubleToSickScanResolution( const double scan_resolution_double );
00257 
00259     static std::string SickBaudToString( const sick_pls_baud_t baud_rate );
00260 
00262     static sick_pls_baud_t IntToSickBaud( const int baud_int );
00263 
00265     static sick_pls_baud_t StringToSickBaud( const std::string baud_str );
00266 
00268     static std::string SickStatusToString( const sick_pls_status_t sick_status );
00269 
00271     static std::string SickOperatingModeToString( const sick_pls_operating_mode_t sick_operating_mode );
00272 
00274     static std::string SickMeasuringUnitsToString( const sick_pls_measuring_units_t sick_units );
00275 
00276   protected:
00277 
00279     std::string _sick_device_path;
00280 
00282     sick_pls_baud_t _curr_session_baud;
00283 
00285     sick_pls_baud_t _desired_session_baud;
00286 
00287 
00289   sick_pls_operating_status_t _sick_operating_status;
00290 
00291 
00293     sick_pls_baud_status_t _sick_baud_status;
00294 
00295 
00297     struct termios _old_term;
00298 
00300     void _setupConnection( ) throw( SickIOException, SickThreadException );
00301 
00303     void _teardownConnection( ) throw( SickIOException );
00304 
00306     void _sendMessageAndGetReply( const SickPLSMessage &sick_send_message,
00307                                   SickPLSMessage &sick_recv_message,
00308                                   const unsigned int timeout_value,
00309                                   const unsigned int num_tries ) throw( SickIOException, SickThreadException, SickTimeoutException );
00310 
00312     void _sendMessageAndGetReply( const SickPLSMessage &sick_send_message,
00313                                   SickPLSMessage &sick_recv_message,
00314                                   const uint8_t reply_code,
00315                                   const unsigned int timeout_value,
00316                                   const unsigned int num_tries ) throw( SickIOException, SickThreadException, SickTimeoutException );
00317 
00319     void _flushTerminalBuffer( ) throw ( SickThreadException );
00320 
00322     void _setSessionBaud( const sick_pls_baud_t baud_rate ) throw( SickIOException, SickThreadException, SickTimeoutException );
00323 
00325     bool _testSickBaud( const sick_pls_baud_t baud_rate ) throw( SickIOException, SickThreadException );
00326 
00328     void _setTerminalBaud( const sick_pls_baud_t sick_baud ) throw( SickIOException, SickThreadException );
00329 
00331     void _getSickErrors( unsigned int * const num_sick_errors = NULL,
00332                          uint8_t * const error_type_buffer = NULL,
00333                          uint8_t * const error_num_buffer = NULL ) throw( SickTimeoutException, SickIOException, SickThreadException );
00334 
00336     void _setSickOpModeInstallation( )
00337       throw( SickConfigException, SickTimeoutException, SickIOException, SickThreadException);
00338 
00340     void _setSickOpModeDiagnostic( )
00341       throw( SickConfigException, SickTimeoutException, SickIOException, SickThreadException);
00342 
00344     void _setSickOpModeMonitorRequestValues( )
00345       throw( SickConfigException, SickTimeoutException, SickIOException, SickThreadException);
00346 
00348     void _setSickOpModeMonitorStreamValues( )
00349       throw( SickConfigException, SickTimeoutException, SickIOException, SickThreadException);
00350 
00352     void _switchSickOperatingMode( const uint8_t sick_mode, const uint8_t * const mode_params = NULL )
00353       throw( SickConfigException, SickTimeoutException, SickIOException, SickThreadException);
00354 
00356     void _parseSickScanProfileB0( const uint8_t * const src_buffer, sick_pls_scan_profile_b0_t &sick_scan_profile ) const;
00357 
00358 
00360     void _extractSickMeasurementValues( const uint8_t * const byte_sequence, const uint16_t num_measurements, uint16_t * const measured_values) const;
00361 
00363     bool _validSickScanAngle( const sick_pls_scan_angle_t sick_scan_angle ) const;
00364 
00366     bool _validSickScanResolution( const sick_pls_scan_resolution_t sick_scan_resolution ) const;
00367 
00369     sick_pls_baud_t _baudToSickBaud( const int baud_rate ) const;
00370 
00371   };
00372 
00377   typedef SickPLS::sick_pls_scan_angle_t sick_pls_scan_angle_t;
00378 
00383   typedef SickPLS::sick_pls_scan_resolution_t sick_pls_scan_resolution_t;
00384 
00389   typedef SickPLS::sick_pls_measuring_units_t sick_pls_measuring_units_t;
00390 
00391 
00396   typedef SickPLS::sick_pls_operating_mode_t sick_pls_operating_mode_t;
00397 
00402   typedef SickPLS::sick_pls_baud_t sick_pls_baud_t;
00403 
00404 } //namespace SickToolbox
00405 
00406 #endif //SICK_PLS_HH


asr_mild_base_laserscanner
Author(s): Aumann Florian, Borella Jocelyn, Dehmani Souheil, Marek Felix, Reckling Reno
autogenerated on Thu Jun 6 2019 21:02:16