INTRODUCTION
Overview
Download and Install
Documentation
Publications

REPOSITORY
Libraries

DEVELOPER
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

sensor.h

00001 /*
00002  * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
00003  *               http://gearbox.sf.net/
00004  * Copyright (c) 2008-2010 Geoffrey Biggs
00005  *
00006  * hokuyo_aist Hokuyo laser scanner driver.
00007  *
00008  * This distribution is licensed to you under the terms described in the
00009  * LICENSE file included in this distribution.
00010  *
00011  * This work is a product of the National Institute of Advanced Industrial
00012  * Science and Technology, Japan. Registration number: H22PRO-1086.
00013  *
00014  * This file is part of hokuyo_aist.
00015  *
00016  * This software is licensed under the Eclipse Public License -v 1.0 (EPL). See
00017  * http://www.opensource.org/licenses/eclipse-1.0.txt
00018  */
00019 
00020 #ifndef SENSOR_H__
00021 #define SENSOR_H__
00022 
00023 #include <string>
00024 
00025 #if defined(WIN32)
00026     typedef unsigned char           uint8_t;
00027     typedef unsigned int            uint32_t;
00028     #if defined(HOKUYO_AIST_STATIC)
00029         #define HOKUYO_AIST_EXPORT
00030     #elif defined(HOKUYO_AIST_EXPORTS)
00031         #define HOKUYO_AIST_EXPORT       __declspec(dllexport)
00032     #else
00033         #define HOKUYO_AIST_EXPORT       __declspec(dllimport)
00034     #endif
00035 #else
00036     #include <stdint.h>
00037     #define HOKUYO_AIST_EXPORT
00038 #endif
00039 
00040 namespace flexiport
00041 {
00042     class Port;
00043 }
00044 
00049 namespace hokuyo_aist
00050 {
00051 
00064 enum MultiechoMode
00065 {
00066     ME_OFF,
00067     ME_FRONT,
00068     ME_MIDDLE,
00069     ME_REAR,
00070     ME_AVERAGE
00071 };
00072 
00073 
00074 HOKUYO_AIST_EXPORT inline char const* multiecho_mode_to_string(MultiechoMode mode)
00075 {
00076     switch(mode)
00077     {
00078         case ME_OFF:
00079             return "Off";
00080         case ME_FRONT:
00081             return "Front";
00082         case ME_MIDDLE:
00083             return "Middle";
00084         case ME_REAR:
00085             return "Rear";
00086         case ME_AVERAGE:
00087             return "Average";
00088         default:
00089             return "Unknown";
00090     }
00091 }
00092 
00093 
00095 typedef struct IPAddr
00096 {
00098     unsigned int first;
00100     unsigned int second;
00102     unsigned int third;
00104     unsigned int fourth;
00105 } IPAddr;
00106 
00107 
00121 class HOKUYO_AIST_EXPORT Sensor
00122 {
00123     public:
00124         Sensor();
00125         Sensor(std::ostream& err_output);
00126         ~Sensor();
00127 
00129         void open(std::string port_options);
00130 
00141         unsigned int open_with_probing(std::string port_options);
00142 
00144         void close();
00145 
00147         bool is_open() const;
00148 
00150         void set_power(bool on);
00151 
00156         void set_baud(unsigned int baud);
00157 
00164         void set_ip(IPAddr const& addr, IPAddr const& subnet,
00165                 IPAddr const& gateway);
00166 
00170         void reset();
00171 
00175         void semi_reset();
00176 
00187         void set_motor_speed(unsigned int speed);
00188 
00191         void set_high_sensitivity(bool on);
00192 
00196         void get_sensor_info(SensorInfo& info);
00197 
00201         unsigned int get_time();
00202 
00206         unsigned int get_raw_time();
00207 
00236         long long calibrate_time(unsigned int skew_sleep_time=0,
00237                 unsigned int samples=10);
00238 
00240         long long time_offset() const { return time_offset_; }
00241 
00243         void set_time_offset(long long time_offset)
00244             { time_offset_ = time_offset; }
00246         float drift_rate() const { return time_drift_rate_; }
00262         void set_drift_rate(float drift_rate)
00263             { time_drift_rate_ = drift_rate; }
00264 
00266         float skew_alpha() const { return time_skew_alpha_; }
00279         void set_skew_alpha(float alpha) { time_skew_alpha_ = alpha; }
00280 
00303         unsigned int get_ranges(ScanData& data, int start_step = -1,
00304                 int end_step = -1, unsigned int cluster_count = 1);
00305 
00320         unsigned int get_ranges_by_angle(ScanData& data, double start_angle,
00321                 double end_angle, unsigned int cluster_count = 1);
00322 
00345         unsigned int get_ranges_intensities(ScanData& data,
00346                 int start_step = -1, int end_step = -1,
00347                 unsigned int cluster_count = 1);
00348 
00363         unsigned int get_ranges_intensities_by_angle(ScanData& data,
00364                 double start_angle, double end_angle,
00365                 unsigned int cluster_count = 1);
00366 
00395         unsigned int get_new_ranges(ScanData& data, int start_step = -1,
00396                 int end_step = -1, unsigned int cluster_count = 1);
00397 
00414         unsigned int get_new_ranges_by_angle(ScanData& data,
00415                 double start_angle, double end_angle,
00416                 unsigned int cluster_count = 1);
00417 
00445         unsigned int get_new_ranges_intensities(ScanData& data,
00446                 int start_step = -1, int end_step = -1,
00447                 unsigned int cluster_count = 1);
00448 
00465         unsigned int get_new_ranges_intensities_by_angle(ScanData& data,
00466                 double start_angle, double end_angle,
00467                 unsigned int cluster_count = 1);
00468 
00470         uint8_t scip_version() const            { return scip_version_; }
00471 
00474         void set_verbose(bool verbose)          { verbose_ = verbose; }
00475 
00478         void ignore_unknowns(bool ignore)       { ignore_unknowns_ = ignore; }
00479 
00481         void set_multiecho_mode(MultiechoMode mode) { multiecho_mode_ = mode; }
00482 
00484         double step_to_angle(unsigned int step);
00487         unsigned int angle_to_step(double angle);
00488 
00489     private:
00490         flexiport::Port* port_;
00491         std::ostream& err_output_;
00492 
00493         uint8_t scip_version_;
00494         LaserModel model_;
00495         bool verbose_, enable_checksum_workaround_,
00496              ignore_unknowns_;
00497         MultiechoMode multiecho_mode_;
00498         double min_angle_, max_angle_, resolution_;
00499         int first_step_, last_step_, front_step_;
00500         unsigned int max_range_;
00502         unsigned int time_resolution_;
00505         long long time_offset_;
00508         unsigned int last_timestamp_;
00510         unsigned int wrap_count_;
00512         float time_drift_rate_;
00514         float time_skew_alpha_;
00515 
00516         void clear_read_buffer();
00517         int read_line(char* buffer, int expected_length=-1);
00518         int read_line_with_check(char* buffer, int expected_length=-1,
00519                 bool has_semicolon=false);
00520         bool read_data_block(char* buffer, int& block_size);
00521         void skip_lines(int count);
00522         int send_command(char const* cmd, char const* param, int param_length,
00523                 char const* extra_ok);
00524 
00525         void enter_timing_mode();
00526         void leave_timing_mode();
00528         unsigned int get_timing_mode_time(unsigned long long* reception_time=0);
00530         unsigned long long get_computer_time();
00532         unsigned int wrap_timestamp(unsigned int timestamp);
00535         unsigned long long offset_timestamp(unsigned int timestamp);
00538         unsigned int step_to_time_offset(int start_step);
00539 
00540         void find_model(char const* buffer);
00541         void get_and_set_scip_version();
00542         void get_defaults();
00543         void process_vv_line(char const* buffer, SensorInfo& info);
00544         void process_pp_line(char const* buffer, SensorInfo& info);
00545         void process_ii_line(char const* buffer, SensorInfo& info);
00546 
00547         uint32_t process_echo_buffer(int const* buffer, int num_echos);
00548         void read_2_byte_range_data(ScanData& data, unsigned int num_steps);
00549         void read_3_byte_range_data(ScanData& data, unsigned int num_steps);
00550         void read_3_byte_range_and_intensity_data(ScanData& data,
00551                 unsigned int num_steps);
00552 
00553         int confirm_checksum(char const* buffer, int length,
00554                 int expected_sum);
00555 }; // class Sensor
00556 
00557 } // namespace hokuyo_aist
00558 
00561 #endif // SENSOR_H__
00562 
 

Generated for GearBox by  doxygen 1.4.5