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 INCLUDE_HOKUYOAIST_SENSOR_H__
30 #define INCLUDE_HOKUYOAIST_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  class Port;
51 }
52 
57 namespace hokuyoaist {
58 
72 {
78 };
79 
80 
82 {
83  switch (mode) {
84  case ME_OFF:
85  return "Off";
86  case ME_FRONT:
87  return "Front";
88  case ME_MIDDLE:
89  return "Middle";
90  case ME_REAR:
91  return "Rear";
92  case ME_AVERAGE:
93  return "Average";
94  default:
95  return "Unknown";
96  }
97 }
98 
99 
101 typedef struct IPAddr
102 {
104  unsigned int first;
106  unsigned int second;
108  unsigned int third;
110  unsigned int fourth;
111 } IPAddr;
112 
113 
128 {
129  public:
130  Sensor();
131  explicit Sensor(std::ostream& err_output);
132  ~Sensor();
133 
135  void open(std::string port_options);
136 
138  void close();
139 
141  bool is_open() const;
142 
144  void set_power(bool on);
145 
152  void set_ip(IPAddr const& addr, IPAddr const& subnet, IPAddr const& gateway);
153 
155  void reset();
156 
160  void semi_reset();
161 
171  void set_motor_speed(unsigned int speed);
172 
175  void set_high_sensitivity(bool on);
176 
178  void get_sensor_info(SensorInfo& info);
179 
181  unsigned long long get_time();
182 
184  unsigned int get_raw_time();
185 
214  long long calibrate_time(unsigned int skew_sleep_time=0, unsigned int samples=10);
215 
217  long long time_offset() const
218  {
219  return time_offset_;
220  }
221 
223  void set_time_offset(long long time_offset)
224  {
225  time_offset_ = time_offset;
226  }
228  float drift_rate() const
229  {
230  return time_drift_rate_;
231  }
247  void set_drift_rate(float drift_rate)
248  {
249  time_drift_rate_ = drift_rate;
250  }
251 
253  float skew_alpha() const
254  {
255  return time_skew_alpha_;
256  }
269  void set_skew_alpha(float alpha)
270  {
271  time_skew_alpha_ = alpha;
272  }
273 
296  unsigned int get_ranges(
297  ScanData& data,
298  int start_step = -1,
299  int end_step = -1,
300  unsigned int cluster_count = 1);
301 
316  unsigned int get_ranges_by_angle(
317  ScanData& data,
318  double start_angle,
319  double end_angle,
320  unsigned int cluster_count = 1);
321 
344  unsigned int get_ranges_intensities(
345  ScanData& data,
346  int start_step = -1,
347  int end_step = -1,
348  unsigned int cluster_count = 1);
349 
364  unsigned int get_ranges_intensities_by_angle(
365  ScanData& data,
366  double start_angle,
367  double end_angle,
368  unsigned int cluster_count = 1);
369 
396  unsigned int get_new_ranges(
397  ScanData& data,
398  int start_step = -1,
399  int end_step = -1,
400  unsigned int cluster_count = 1);
401 
416  unsigned int get_new_ranges_by_angle(
417  ScanData& data,
418  double start_angle,
419  double end_angle,
420  unsigned int cluster_count = 1);
421 
447  unsigned int get_new_ranges_intensities(
448  ScanData& data,
449  int start_step = -1,
450  int end_step = -1,
451  unsigned int cluster_count = 1);
452 
467  unsigned int get_new_ranges_intensities_by_angle(
468  ScanData& data,
469  double start_angle,
470  double end_angle,
471  unsigned int cluster_count = 1);
472 
474  uint8_t scip_version() const { return scip_version_; }
475 
478  void set_verbose(bool verbose) { verbose_ = verbose; }
479 
482  void ignore_unknowns(bool ignore) { ignore_unknowns_ = ignore; }
483 
485  void set_multiecho_mode(MultiechoMode mode) { multiecho_mode_ = mode; }
486 
488  double step_to_angle(unsigned int step);
491  unsigned int angle_to_step(double angle);
492 
493  private:
494  flexiport::Port* port_;
495  std::ostream& err_output_;
496 
497  uint8_t scip_version_;
498  LaserModel model_;
499  bool verbose_, enable_checksum_workaround_, ignore_unknowns_;
500  MultiechoMode multiecho_mode_;
501  double min_angle_, max_angle_, resolution_;
502  int first_step_, last_step_, front_step_;
503  unsigned int max_range_;
505  unsigned int time_resolution_;
508  long long time_offset_;
511  unsigned int last_timestamp_;
513  unsigned int wrap_count_;
515  float time_drift_rate_;
517  float time_skew_alpha_;
518 
519  void clear_read_buffer();
520  int read_line(char* buffer, int expected_length=-1);
521  int read_line_with_check(char* buffer, int expected_length=-1, bool has_semicolon=false);
522  bool read_data_block(char* buffer, int& block_size);
523  void skip_lines(int count);
524  int send_command(char const* cmd, char const* param, int param_length, char const* extra_ok);
525 
526  void enter_timing_mode();
527  void leave_timing_mode();
529  unsigned int get_timing_mode_time(unsigned long long* reception_time=0);
531  unsigned long long get_computer_time();
533  unsigned int wrap_timestamp(unsigned int timestamp);
536  unsigned long long offset_timestamp(unsigned int timestamp);
539  unsigned int step_to_time_offset(int start_step);
540 
541  void find_model(char const* buffer);
542  void get_and_set_scip_version();
543  void get_defaults();
544  void process_vv_line(char const* buffer, SensorInfo& info);
545  void process_pp_line(char const* buffer, SensorInfo& info);
546  void process_ii_line(char const* buffer, SensorInfo& info);
547 
548  uint32_t process_echo_buffer(int const* buffer, int num_echos);
549  void read_2_byte_range_data(ScanData& data, unsigned int num_steps);
550  void read_3_byte_range_data(ScanData& data, unsigned int num_steps);
551  void read_3_byte_range_and_intensity_data(ScanData& data, unsigned int num_steps);
552 
553  int confirm_checksum(char const* buffer, int length, int expected_sum);
554 }; // class Sensor
555 
556 } // namespace hokuyoaist
557 
560 #endif // INCLUDE_HOKUYOAIST_SENSOR_H__
void set_multiecho_mode(MultiechoMode mode)
Set the multi-echo mode to use.
Definition: sensor.h:485
Structure to store an IP address.
Definition: sensor.h:101
uint8_t scip_version() const
Return the major version of the SCIP protocol in use.
Definition: sensor.h:474
void set_skew_alpha(float alpha)
Set a skew line slope value.
Definition: sensor.h:269
unsigned int second
Second byte.
Definition: sensor.h:106
float drift_rate() const
Retrieve the current clock drift rate (0 if not set).
Definition: sensor.h:228
struct hokuyoaist::IPAddr IPAddr
Structure to store an IP address.
Structure to store data returned from the laser scanner.
Definition: scan_data.h:60
unsigned int fourth
Fourth byte.
Definition: sensor.h:110
HOKUYOAIST_EXPORT char const * multiecho_mode_to_string(MultiechoMode mode)
Definition: sensor.h:81
void set_drift_rate(float drift_rate)
Set the current clock drift rate.
Definition: sensor.h:247
void set_time_offset(long long time_offset)
Set the time offset (if the calculated value is bad).
Definition: sensor.h:223
Hokuyo laser scanner class.
Definition: sensor.h:127
Sensor information.
Definition: sensor_info.h:135
long long time_offset() const
Retrieve the calculated time offset (0 if not calibrated).
Definition: sensor.h:217
#define HOKUYOAIST_EXPORT
Definition: sensor.h:46
unsigned int third
Third byte.
Definition: sensor.h:108
void ignore_unknowns(bool ignore)
Enables/disables ignoring unknown lines in sensor info messages.
Definition: sensor.h:482
void set_verbose(bool verbose)
Turns on and off printing of verbose operating information to stderr.
Definition: sensor.h:478
float skew_alpha() const
Get the calculated skew line slope (default: 0).
Definition: sensor.h:253
LaserModel
Laser models.
Definition: sensor_info.h:57
MultiechoMode
Possible values of the multiecho mode setting.
Definition: sensor.h:71
unsigned int first
First byte.
Definition: sensor.h:104