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
1 /*
2  * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
3  * http://gearbox.sf.net/
4  * Copyright (c) 2008-2010 Geoffrey Biggs
5  *
6  * hokuyo_aist Hokuyo laser scanner driver.
7  *
8  * This distribution is licensed to you under the terms described in the
9  * LICENSE file included in this distribution.
10  *
11  * This work is a product of the National Institute of Advanced Industrial
12  * Science and Technology, Japan. Registration number: H22PRO-1086.
13  *
14  * This file is part of hokuyo_aist.
15  *
16  * This software is licensed under the Eclipse Public License -v 1.0 (EPL). See
17  * http://www.opensource.org/licenses/eclipse-1.0.txt
18  */
19 
20 #ifndef SENSOR_H__
21 #define SENSOR_H__
22 
23 #include <string>
24 
25 #if defined(WIN32)
26  typedef unsigned char uint8_t;
27  typedef unsigned int uint32_t;
28  #if defined(HOKUYO_AIST_STATIC)
29  #define HOKUYO_AIST_EXPORT
30  #elif defined(HOKUYO_AIST_EXPORTS)
31  #define HOKUYO_AIST_EXPORT __declspec(dllexport)
32  #else
33  #define HOKUYO_AIST_EXPORT __declspec(dllimport)
34  #endif
35 #else
36  #include <stdint.h>
37  #define HOKUYO_AIST_EXPORT
38 #endif
39 
40 namespace flexiport
41 {
42  class Port;
43 }
44 
49 namespace hokuyo_aist
50 {
51 
65 {
66  ME_OFF,
67  ME_FRONT,
68  ME_MIDDLE,
69  ME_REAR,
70  ME_AVERAGE
71 };
72 
73 
74 HOKUYO_AIST_EXPORT inline char const* multiecho_mode_to_string(MultiechoMode mode)
75 {
76  switch(mode)
77  {
78  case ME_OFF:
79  return "Off";
80  case ME_FRONT:
81  return "Front";
82  case ME_MIDDLE:
83  return "Middle";
84  case ME_REAR:
85  return "Rear";
86  case ME_AVERAGE:
87  return "Average";
88  default:
89  return "Unknown";
90  }
91 }
92 
93 
95 typedef struct IPAddr
96 {
98  unsigned int first;
100  unsigned int second;
102  unsigned int third;
104  unsigned int fourth;
105 } IPAddr;
106 
107 
121 class HOKUYO_AIST_EXPORT Sensor
122 {
123  public:
124  Sensor();
125  Sensor(std::ostream& err_output);
126  ~Sensor();
127 
129  void open(std::string port_options);
130 
141  unsigned int open_with_probing(std::string port_options);
142 
144  void close();
145 
147  bool is_open() const;
148 
150  void set_power(bool on);
151 
156  void set_baud(unsigned int baud);
157 
164  void set_ip(IPAddr const& addr, IPAddr const& subnet,
165  IPAddr const& gateway);
166 
170  void reset();
171 
175  void semi_reset();
176 
187  void set_motor_speed(unsigned int speed);
188 
191  void set_high_sensitivity(bool on);
192 
196  void get_sensor_info(SensorInfo& info);
197 
201  unsigned int get_time();
202 
206  unsigned int get_raw_time();
207 
236  long long calibrate_time(unsigned int skew_sleep_time=0,
237  unsigned int samples=10);
238 
240  long long time_offset() const { return time_offset_; }
241 
243  void set_time_offset(long long time_offset)
244  { time_offset_ = time_offset; }
246  float drift_rate() const { return time_drift_rate_; }
262  void set_drift_rate(float drift_rate)
263  { time_drift_rate_ = drift_rate; }
264 
266  float skew_alpha() const { return time_skew_alpha_; }
279  void set_skew_alpha(float alpha) { time_skew_alpha_ = alpha; }
280 
303  unsigned int get_ranges(ScanData& data, int start_step = -1,
304  int end_step = -1, unsigned int cluster_count = 1);
305 
320  unsigned int get_ranges_by_angle(ScanData& data, double start_angle,
321  double end_angle, unsigned int cluster_count = 1);
322 
345  unsigned int get_ranges_intensities(ScanData& data,
346  int start_step = -1, int end_step = -1,
347  unsigned int cluster_count = 1);
348 
363  unsigned int get_ranges_intensities_by_angle(ScanData& data,
364  double start_angle, double end_angle,
365  unsigned int cluster_count = 1);
366 
395  unsigned int get_new_ranges(ScanData& data, int start_step = -1,
396  int end_step = -1, unsigned int cluster_count = 1);
397 
414  unsigned int get_new_ranges_by_angle(ScanData& data,
415  double start_angle, double end_angle,
416  unsigned int cluster_count = 1);
417 
445  unsigned int get_new_ranges_intensities(ScanData& data,
446  int start_step = -1, int end_step = -1,
447  unsigned int cluster_count = 1);
448 
465  unsigned int get_new_ranges_intensities_by_angle(ScanData& data,
466  double start_angle, double end_angle,
467  unsigned int cluster_count = 1);
468 
470  uint8_t scip_version() const { return scip_version_; }
471 
474  void set_verbose(bool verbose) { verbose_ = verbose; }
475 
478  void ignore_unknowns(bool ignore) { ignore_unknowns_ = ignore; }
479 
481  void set_multiecho_mode(MultiechoMode mode) { multiecho_mode_ = mode; }
482 
484  double step_to_angle(unsigned int step);
487  unsigned int angle_to_step(double angle);
488 
489  private:
490  flexiport::Port* port_;
491  std::ostream& err_output_;
492 
493  uint8_t scip_version_;
494  LaserModel model_;
495  bool verbose_, enable_checksum_workaround_,
496  ignore_unknowns_;
497  MultiechoMode multiecho_mode_;
498  double min_angle_, max_angle_, resolution_;
499  int first_step_, last_step_, front_step_;
500  unsigned int max_range_;
502  unsigned int time_resolution_;
505  long long time_offset_;
508  unsigned int last_timestamp_;
510  unsigned int wrap_count_;
512  float time_drift_rate_;
514  float time_skew_alpha_;
515 
516  void clear_read_buffer();
517  int read_line(char* buffer, int expected_length=-1);
518  int read_line_with_check(char* buffer, int expected_length=-1,
519  bool has_semicolon=false);
520  bool read_data_block(char* buffer, int& block_size);
521  void skip_lines(int count);
522  int send_command(char const* cmd, char const* param, int param_length,
523  char const* extra_ok);
524 
525  void enter_timing_mode();
526  void leave_timing_mode();
528  unsigned int get_timing_mode_time(unsigned long long* reception_time=0);
530  unsigned long long get_computer_time();
532  unsigned int wrap_timestamp(unsigned int timestamp);
535  unsigned long long offset_timestamp(unsigned int timestamp);
538  unsigned int step_to_time_offset(int start_step);
539 
540  void find_model(char const* buffer);
541  void get_and_set_scip_version();
542  void get_defaults();
543  void process_vv_line(char const* buffer, SensorInfo& info);
544  void process_pp_line(char const* buffer, SensorInfo& info);
545  void process_ii_line(char const* buffer, SensorInfo& info);
546 
547  uint32_t process_echo_buffer(int const* buffer, int num_echos);
548  void read_2_byte_range_data(ScanData& data, unsigned int num_steps);
549  void read_3_byte_range_data(ScanData& data, unsigned int num_steps);
550  void read_3_byte_range_and_intensity_data(ScanData& data,
551  unsigned int num_steps);
552 
553  int confirm_checksum(char const* buffer, int length,
554  int expected_sum);
555 }; // class Sensor
556 
557 } // namespace hokuyo_aist
558 
561 #endif // SENSOR_H__
562 
double max_angle
Definition: sensor_info.h:196
void set_motor_speed(unsigned int speed)
Set the speed at which the scanner's sensor spins.
Definition: sensor.cpp:591
SCIP version error class.
Definition: hokuyo_errors.h:201
void set_baud(unsigned int baud)
Change the baud rate when using a serial connection.
Definition: sensor.cpp:489
Baudrate error class.
Definition: hokuyo_errors.h:146
std::string sensor_diagnostic
Diagnostic status string.
Definition: sensor_info.h:188
virtual void Flush()=0
Flush the port's input and output buffers, discarding all data.
struct hokuyo_aist::IPAddr IPAddr
Structure to store an IP address.
No data error class.
Definition: hokuyo_errors.h:251
void set_power(bool on)
Switch the laser scanner on or off.
Definition: sensor.cpp:444
unsigned int first
First byte.
Definition: sensor.h:98
void open(std::string port_options)
Open the laser scanner and begin scanning.
Definition: sensor.cpp:307
std::string as_string()
Format the entire object into a string.
Definition: sensor_info.cpp:131
virtual ssize_t ReadLine(char *const buffer, size_t count)
Read a new-line terminated string of data.
Definition: port.cpp:201
float skew_alpha() const
Get the calculated skew line slope (default: 0).
Definition: sensor.h:266
virtual ssize_t SkipUntil(uint8_t terminator, unsigned int count)
Read and dump data until the specified termination character has been seen count times.
Definition: port.cpp:245
void set_high_sensitivity(bool on)
Switch the scanner between normal and high sensitivity modes.
Definition: sensor.cpp:640
virtual bool IsOpen() const =0
Check if the port is open.
std::string GetPortType() const
Get the port type.
Definition: port.h:266
unsigned int get_time()
Get the value of the scanner's clock in milliseconds.
Definition: sensor.cpp:829
void set_ip(IPAddr const &addr, IPAddr const &subnet, IPAddr const &gateway)
Change the IP address information.
Definition: sensor.cpp:525
void close()
Close the connection to the laser scanner.
Definition: sensor.cpp:425
FlexiPort data communications library.
Set IP error class.
Definition: hokuyo_errors.h:281
unsigned int get_new_ranges_intensities_by_angle(ScanData &data, double start_angle, double end_angle, unsigned int cluster_count=1)
Get a new scan from the scanner with intensity data.
Definition: sensor.cpp:1319
std::string serial
Serial number of this device.
Definition: sensor_info.h:151
Bad start step error class.
Definition: hokuyo_errors.h:301
bool is_open() const
Checks if the connection to the laser scanner is open.
Definition: sensor.cpp:436
unsigned int first_step
First scanable step of a full scan.
Definition: sensor_info.h:163
unsigned int get_new_ranges(ScanData &data, int start_step=-1, int end_step=-1, unsigned int cluster_count=1)
Get a new scan from the scanner.
Definition: sensor.cpp:1117
Bad firmware error class.
Definition: hokuyo_errors.h:191
std::string firmware
Firmware version.
Definition: sensor_info.h:147
unsigned int open_with_probing(std::string port_options)
Open the laser scanner and begin scanning, probing the baud rate.
Definition: sensor.cpp:334
virtual void Open()=0
Open the port.
Missing firmware specification error.
Definition: hokuyo_errors.h:439
MultiechoMode
Possible values of the multiecho mode setting.
Definition: sensor.h:64
unsigned int angle_to_step(double angle)
A convenience function to convert an angle to a step (rounded towards the front).
Definition: sensor.cpp:1356
unsigned int speed
Current motor speed (rpm).
Definition: sensor_info.h:178
Command echo error.
Definition: hokuyo_errors.h:525
double step_to_angle(unsigned int step)
A convenience function to convert a step index to an angle.
Definition: sensor.cpp:1349
long long time_offset() const
Retrieve the calculated time offset (0 if not calibrated).
Definition: sensor.h:240
std::string measure_state
Measurement state.
Definition: sensor_info.h:182
unsigned int min_range
Minimum detectable range (mm).
Definition: sensor_info.h:157
unsigned int last_step
Last scanable step of a full scan.
Definition: sensor_info.h:165
void set_multiecho_mode(MultiechoMode mode)
Set the multi-echo mode to use. Default is ME_OFF.
Definition: sensor.h:481
void set_skew_alpha(float alpha)
Definition: sensor.h:279
unsigned int time
Current sensor time (s).
Definition: sensor_info.h:186
unsigned int get_ranges(ScanData &data, int start_step=-1, int end_step=-1, unsigned int cluster_count=1)
Get the latest scan data from the scanner.
Definition: sensor.cpp:954
virtual ssize_t BytesAvailableWait()=0
Get the number of bytes waiting after blocking for the timeout.
unsigned int baud
Baud rate.
Definition: sensor_info.h:184
General error class.
Definition: hokuyo_errors.h:56
unsigned int standard_speed
Standard motor speed (rpm).
Definition: sensor_info.h:170
Read error class.
Definition: hokuyo_errors.h:120
double time_resolution
Time between two scan points (milliseconds).
Definition: sensor_info.h:200
unsigned short speed_level
Speed level (0 for default)
Definition: sensor_info.h:180
Structure to store data returned from the laser scanner.
Definition: scan_data.h:52
unsigned int steps
Number of steps in a 360-degree scan.
Definition: sensor_info.h:161
Serial implementation of the Port class.
Definition: serialport.h:72
unsigned int front_step
Definition: sensor_info.h:168
long long calibrate_time(unsigned int skew_sleep_time=0, unsigned int samples=10)
Calibrate the time offset between the laser and computer.
Definition: sensor.cpp:860
unsigned int scanable_steps
Total number of steps in a full scan (lastStep - firstStep).
Definition: sensor_info.h:202
Parameter echo error.
Definition: hokuyo_errors.h:566
unsigned int get_ranges_intensities_by_angle(ScanData &data, double start_angle, double end_angle, unsigned int cluster_count=1)
Get the latest scan data from the scanner with intensities.
Definition: sensor.cpp:1091
void set_verbose(bool verbose)
Turns on and off printing of verbose operating information to stderr. Default is off.
Definition: sensor.h:474
unsigned int get_new_ranges_by_angle(ScanData &data, double start_angle, double end_angle, unsigned int cluster_count=1)
Get a new scan from the scanner.
Definition: sensor.cpp:1203
LaserModel
Laser models.
Definition: sensor_info.h:49
Incorrect number of data sets read error.
Definition: hokuyo_errors.h:371
Unknown SCIP version error class.
Definition: hokuyo_errors.h:211
unsigned int fourth
Fourth byte.
Definition: sensor.h:104
LaserModel detected_model
Detected model of the laser.
Definition: sensor_info.h:206
Bad response error - may be sent in response to any command.
Definition: hokuyo_errors.h:449
Misplaced line feed error.
Definition: hokuyo_errors.h:381
Invalid motor speed error class.
Definition: hokuyo_errors.h:291
Structure to store an IP address.
Definition: sensor.h:95
unsigned int third
Third byte.
Definition: sensor.h:102
float drift_rate() const
Retrieve the current clock drift rate (0 if not set).
Definition: sensor.h:246
Incorrect line length error.
Definition: hokuyo_errors.h:630
Hokuyo laser scanner class.
Definition: sensor.h:121
std::string model
Sensor model number.
Definition: sensor_info.h:155
void semi_reset()
Reset everything except motor and serial speed.
Definition: sensor.cpp:574
double min_angle
Definition: sensor_info.h:193
std::string protocol
Protocol version in use.
Definition: sensor_info.h:149
Sensor information.
Definition: sensor_info.h:127
Parse error.
Definition: hokuyo_errors.h:412
Bad response error (SCIP1 version)
Definition: hokuyo_errors.h:490
void set_drift_rate(float drift_rate)
Definition: sensor.h:262
void set_time_offset(long long time_offset)
Set the time offset (if the calculated value is bad).
Definition: sensor.h:243
unsigned int get_new_ranges_intensities(ScanData &data, int start_step=-1, int end_step=-1, unsigned int cluster_count=1)
Get a new scan from the scanner with intensity data.
Definition: sensor.cpp:1232
void get_sensor_info(SensorInfo &info)
Get various information about the scanner.
Definition: sensor.cpp:669
unsigned int get_ranges_intensities(ScanData &data, int start_step=-1, int end_step=-1, unsigned int cluster_count=1)
Get the latest scan data from the scanner with intensities.
Definition: sensor.cpp:1041
Base protocol error.
Definition: hokuyo_errors.h:321
Write error class.
Definition: hokuyo_errors.h:133
double resolution
Angle between two scan points (radians).
Definition: sensor_info.h:198
void ignore_unknowns(bool ignore)
Enables/disables ignoring unknown lines in sensor info messages. Default is off.
Definition: sensor.h:478
Insufficient bytes to calculate checksum error.
Definition: hokuyo_errors.h:597
unsigned int max_range
Maximum detectable range (mm).
Definition: sensor_info.h:159
std::string product
Product name.
Definition: sensor_info.h:145
virtual ssize_t Read(void *const buffer, size_t count)=0
Read from the port.
unsigned int get_ranges_by_angle(ScanData &data, double start_angle, double end_angle, unsigned int cluster_count=1)
Get the latest scan data from the scanner.
Definition: sensor.cpp:1015
uint8_t scip_version() const
Return the major version of the SCIP protocol in use.
Definition: sensor.h:470
UnknownLine error.
Definition: hokuyo_errors.h:391
bool power
Operational status - illuminated or not.
Definition: sensor_info.h:176
Bad checksum error.
Definition: hokuyo_errors.h:338
unsigned int second
Second byte.
Definition: sensor.h:100
T median(std::vector< T > &v)
Find the median value of a std::vector.
Definition: utils.h:74
Bad end step error class.
Definition: hokuyo_errors.h:311
Not a serial connection error class.
Definition: hokuyo_errors.h:261
Unsupported feature error class.
Definition: hokuyo_errors.h:221
virtual ssize_t Write(const void *const buffer, size_t count)=0
Write data to the port.
std::string vendor
Vendor name.
Definition: sensor_info.h:143
unsigned int get_raw_time()
Get the raw value of the scanner's clock in milliseconds.
Definition: sensor.cpp:835
void reset()
Reset the laser scanner to its default settings.
Definition: sensor.cpp:555
Base Port class.
Definition: port.h:79
virtual std::string GetStatus() const
Get the status of the port (type, device, etc).
Definition: port.cpp:352
Close error class.
Definition: hokuyo_errors.h:171
Hokuyo laser scanner driver name space.
 

Generated for GearBox by  doxygen 1.4.5