HokuyoAIST  3.0.2
sensor.h
Go to the documentation of this file.
1 /* HokuyoAIST
2  *
3  * Header file for the sensor object.
4  *
5  * Copyright 2008-2011 Geoffrey Biggs geoffrey.biggs@aist.go.jp
6  * RT-Synthesis Research Group
7  * Intelligent Systems Research Institute,
8  * National Institute of Advanced Industrial Science and Technology (AIST),
9  * Japan
10  * All rights reserved.
11  *
12  * This file is part of HokuyoAIST.
13  *
14  * HokuyoAIST is free software; you can redistribute it and/or modify it
15  * under the terms of the GNU Lesser General Public License as published
16  * by the Free Software Foundation; either version 2.1 of the License,
17  * or (at your option) any later version.
18  *
19  * HokuyoAIST is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with HokuyoAIST. If not, see
26  * <http://www.gnu.org/licenses/>.
27  */
28 
29 #ifndef SENSOR_H__
30 #define SENSOR_H__
31 
32 #include <string>
33 
34 #if defined(WIN32)
35  typedef unsigned char uint8_t;
36  typedef unsigned int uint32_t;
37  #if defined(HOKUYOAIST_STATIC)
38  #define HOKUYOAIST_EXPORT
39  #elif defined(hokuyoaist_EXPORTS)
40  #define HOKUYOAIST_EXPORT __declspec(dllexport)
41  #else
42  #define HOKUYOAIST_EXPORT __declspec(dllimport)
43  #endif
44 #else
45  #include <stdint.h>
46  #define HOKUYOAIST_EXPORT
47 #endif
48 
49 namespace flexiport
50 {
51  class Port;
52 }
53 
58 namespace hokuyoaist
59 {
60 
74 {
80 };
81 
82 
84 {
85  switch(mode)
86  {
87  case ME_OFF:
88  return "Off";
89  case ME_FRONT:
90  return "Front";
91  case ME_MIDDLE:
92  return "Middle";
93  case ME_REAR:
94  return "Rear";
95  case ME_AVERAGE:
96  return "Average";
97  default:
98  return "Unknown";
99  }
100 }
101 
102 
104 typedef struct IPAddr
105 {
107  unsigned int first;
109  unsigned int second;
111  unsigned int third;
113  unsigned int fourth;
115 
116 
131 {
132  public:
134  Sensor(std::ostream& err_output);
136 
138  void open(std::string port_options);
139 
141  void close();
142 
144  bool is_open() const;
145 
147  void set_power(bool on);
148 
155  void set_ip(IPAddr const& addr, IPAddr const& subnet,
156  IPAddr const& gateway);
157 
159  void reset();
160 
164  void semi_reset();
165 
175  void set_motor_speed(unsigned int speed);
176 
179  void set_high_sensitivity(bool on);
180 
183 
185  unsigned long long get_time();
186 
188  unsigned int get_raw_time();
189 
218  long long calibrate_time(unsigned int skew_sleep_time=0,
219  unsigned int samples=10);
220 
222  long long time_offset() const { return time_offset_; }
223 
225  void set_time_offset(long long time_offset)
226  { time_offset_ = time_offset; }
228  float drift_rate() const { return time_drift_rate_; }
244  void set_drift_rate(float drift_rate)
245  { time_drift_rate_ = drift_rate; }
246 
248  float skew_alpha() const { return time_skew_alpha_; }
261  void set_skew_alpha(float alpha) { time_skew_alpha_ = alpha; }
262 
285  unsigned int get_ranges(ScanData& data, int start_step = -1,
286  int end_step = -1, unsigned int cluster_count = 1);
287 
302  unsigned int get_ranges_by_angle(ScanData& data, double start_angle,
303  double end_angle, unsigned int cluster_count = 1);
304 
327  unsigned int get_ranges_intensities(ScanData& data,
328  int start_step = -1, int end_step = -1,
329  unsigned int cluster_count = 1);
330 
346  double start_angle, double end_angle,
347  unsigned int cluster_count = 1);
348 
375  unsigned int get_new_ranges(ScanData& data, int start_step = -1,
376  int end_step = -1, unsigned int cluster_count = 1);
377 
392  unsigned int get_new_ranges_by_angle(ScanData& data,
393  double start_angle, double end_angle,
394  unsigned int cluster_count = 1);
395 
422  int start_step = -1, int end_step = -1,
423  unsigned int cluster_count = 1);
424 
440  double start_angle, double end_angle,
441  unsigned int cluster_count = 1);
442 
444  uint8_t scip_version() const { return scip_version_; }
445 
448  void set_verbose(bool verbose) { verbose_ = verbose; }
449 
452  void ignore_unknowns(bool ignore) { ignore_unknowns_ = ignore; }
453 
455  void set_multiecho_mode(MultiechoMode mode) { multiecho_mode_ = mode; }
456 
458  double step_to_angle(unsigned int step);
461  unsigned int angle_to_step(double angle);
462 
463  private:
464  flexiport::Port* port_;
465  std::ostream& err_output_;
466 
467  uint8_t scip_version_;
468  LaserModel model_;
469  bool verbose_, enable_checksum_workaround_,
470  ignore_unknowns_;
471  MultiechoMode multiecho_mode_;
472  double min_angle_, max_angle_, resolution_;
473  int first_step_, last_step_, front_step_;
474  unsigned int max_range_;
476  unsigned int time_resolution_;
479  long long time_offset_;
482  unsigned int last_timestamp_;
484  unsigned int wrap_count_;
486  float time_drift_rate_;
488  float time_skew_alpha_;
489 
490  void clear_read_buffer();
491  int read_line(char* buffer, int expected_length=-1);
492  int read_line_with_check(char* buffer, int expected_length=-1,
493  bool has_semicolon=false);
494  bool read_data_block(char* buffer, int& block_size);
495  void skip_lines(int count);
496  int send_command(char const* cmd, char const* param, int param_length,
497  char const* extra_ok);
498 
499  void enter_timing_mode();
500  void leave_timing_mode();
502  unsigned int get_timing_mode_time(unsigned long long* reception_time=0);
504  unsigned long long get_computer_time();
506  unsigned int wrap_timestamp(unsigned int timestamp);
509  unsigned long long offset_timestamp(unsigned int timestamp);
512  unsigned int step_to_time_offset(int start_step);
513 
514  void find_model(char const* buffer);
515  void get_and_set_scip_version();
516  void get_defaults();
517  void process_vv_line(char const* buffer, SensorInfo& info);
518  void process_pp_line(char const* buffer, SensorInfo& info);
519  void process_ii_line(char const* buffer, SensorInfo& info);
520 
521  uint32_t process_echo_buffer(int const* buffer, int num_echos);
522  void read_2_byte_range_data(ScanData& data, unsigned int num_steps);
523  void read_3_byte_range_data(ScanData& data, unsigned int num_steps);
524  void read_3_byte_range_and_intensity_data(ScanData& data,
525  unsigned int num_steps);
526 
527  int confirm_checksum(char const* buffer, int length,
528  int expected_sum);
529 }; // class Sensor
530 
531 } // namespace hokuyoaist
532 
535 #endif // SENSOR_H__
536 
hokuyoaist::Sensor::calibrate_time
long long calibrate_time(unsigned int skew_sleep_time=0, unsigned int samples=10)
Calibrate the time offset between the laser and computer.
hokuyoaist::Sensor::open
void open(std::string port_options)
Open the laser scanner and begin scanning.
hokuyoaist::Sensor::get_new_ranges_intensities_by_angle
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.
hokuyoaist::Sensor::set_motor_speed
void set_motor_speed(unsigned int speed)
Set the speed at which the scanner's sensor spins.
hokuyoaist::IPAddr
Structure to store an IP address.
Definition: sensor.h:105
hokuyoaist::Sensor::~Sensor
~Sensor()
hokuyoaist::Sensor::get_ranges_intensities_by_angle
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.
hokuyoaist::Sensor::set_verbose
void set_verbose(bool verbose)
Turns on and off printing of verbose operating information to stderr.
Definition: sensor.h:448
hokuyoaist::Sensor::get_new_ranges_by_angle
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.
hokuyoaist::ME_FRONT
@ ME_FRONT
Definition: sensor.h:76
hokuyoaist::Sensor::get_raw_time
unsigned int get_raw_time()
Get the raw value of the scanner's clock in milliseconds.
flexiport
Definition: sensor.h:50
hokuyoaist::IPAddr::first
unsigned int first
First byte.
Definition: sensor.h:107
hokuyoaist::Sensor::angle_to_step
unsigned int angle_to_step(double angle)
A convenience function to convert an angle to a step (rounded towards the front).
hokuyoaist::Sensor::close
void close()
Close the connection to the laser scanner.
hokuyoaist::Sensor::drift_rate
float drift_rate() const
Retrieve the current clock drift rate (0 if not set).
Definition: sensor.h:228
hokuyoaist::Sensor::scip_version
uint8_t scip_version() const
Return the major version of the SCIP protocol in use.
Definition: sensor.h:444
hokuyoaist::Sensor::set_skew_alpha
void set_skew_alpha(float alpha)
Set a skew line slope value.
Definition: sensor.h:261
hokuyoaist::Sensor
Hokuyo laser scanner class.
Definition: sensor.h:131
hokuyoaist::Sensor::get_ranges_by_angle
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.
hokuyoaist::MultiechoMode
MultiechoMode
Possible values of the multiecho mode setting.
Definition: sensor.h:74
hokuyoaist::Sensor::set_multiecho_mode
void set_multiecho_mode(MultiechoMode mode)
Set the multi-echo mode to use.
Definition: sensor.h:455
hokuyoaist::ME_MIDDLE
@ ME_MIDDLE
Definition: sensor.h:77
hokuyoaist::Sensor::is_open
bool is_open() const
Checks if the connection to the laser scanner is open.
hokuyoaist::Sensor::reset
void reset()
Reset the laser scanner to its default settings.
hokuyoaist::ME_OFF
@ ME_OFF
Definition: sensor.h:75
hokuyoaist::ME_REAR
@ ME_REAR
Definition: sensor.h:78
hokuyoaist::ME_AVERAGE
@ ME_AVERAGE
Definition: sensor.h:79
hokuyoaist
Definition: hokuyo_errors.h:54
hokuyoaist::Sensor::time_offset
long long time_offset() const
Retrieve the calculated time offset (0 if not calibrated).
Definition: sensor.h:222
hokuyoaist::Sensor::get_new_ranges
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.
hokuyoaist::Sensor::set_ip
void set_ip(IPAddr const &addr, IPAddr const &subnet, IPAddr const &gateway)
Change the IP address information.
hokuyoaist::Sensor::Sensor
Sensor(std::ostream &err_output)
hokuyoaist::Sensor::set_power
void set_power(bool on)
Switch the laser scanner on or off.
hokuyoaist::IPAddr::third
unsigned int third
Third byte.
Definition: sensor.h:111
hokuyoaist::Sensor::set_high_sensitivity
void set_high_sensitivity(bool on)
Switch the scanner between normal and high sensitivity modes.
hokuyoaist::Sensor::set_drift_rate
void set_drift_rate(float drift_rate)
Set the current clock drift rate.
Definition: sensor.h:244
hokuyoaist::Sensor::get_sensor_info
void get_sensor_info(SensorInfo &info)
Get various information about the scanner.
hokuyoaist::Sensor::step_to_angle
double step_to_angle(unsigned int step)
A convenience function to convert a step index to an angle.
hokuyoaist::LaserModel
LaserModel
Laser models.
Definition: sensor_info.h:59
hokuyoaist::Sensor::set_time_offset
void set_time_offset(long long time_offset)
Set the time offset (if the calculated value is bad).
Definition: sensor.h:225
hokuyoaist::Sensor::Sensor
Sensor()
hokuyoaist::Sensor::get_new_ranges_intensities
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.
hokuyoaist::Sensor::get_time
unsigned long long get_time()
Get the value of the scanner's clock in milliseconds.
hokuyoaist::Sensor::semi_reset
void semi_reset()
Reset everything except motor and serial speed.
hokuyoaist::IPAddr::fourth
unsigned int fourth
Fourth byte.
Definition: sensor.h:113
hokuyoaist::IPAddr
struct hokuyoaist::IPAddr IPAddr
Structure to store an IP address.
hokuyoaist::multiecho_mode_to_string
HOKUYOAIST_EXPORT char const * multiecho_mode_to_string(MultiechoMode mode)
Definition: sensor.h:83
hokuyoaist::Sensor::skew_alpha
float skew_alpha() const
Get the calculated skew line slope (default: 0).
Definition: sensor.h:248
HOKUYOAIST_EXPORT
#define HOKUYOAIST_EXPORT
Definition: sensor.h:46
hokuyoaist::Sensor::get_ranges
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.
hokuyoaist::ScanData
Structure to store data returned from the laser scanner.
Definition: scan_data.h:62
hokuyoaist::Sensor::ignore_unknowns
void ignore_unknowns(bool ignore)
Enables/disables ignoring unknown lines in sensor info messages.
Definition: sensor.h:452
hokuyoaist::SensorInfo
Sensor information.
Definition: sensor_info.h:138
hokuyoaist::IPAddr::second
unsigned int second
Second byte.
Definition: sensor.h:109
hokuyoaist::Sensor::get_ranges_intensities
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.