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
49namespace flexiport
50{
51 class Port;
52}
53
58namespace hokuyoaist
59{
60
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
104typedef 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
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
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
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
Structure to store data returned from the laser scanner.
Definition scan_data.h:62
Hokuyo laser scanner class.
Definition sensor.h:131
void set_verbose(bool verbose)
Turns on and off printing of verbose operating information to stderr.
Definition sensor.h:448
void set_time_offset(long long time_offset)
Set the time offset (if the calculated value is bad).
Definition sensor.h:225
void open(std::string port_options)
Open the laser scanner and begin scanning.
void set_high_sensitivity(bool on)
Switch the scanner between normal and high sensitivity modes.
void close()
Close the connection to the laser scanner.
void set_motor_speed(unsigned int speed)
Set the speed at which the scanner's sensor spins.
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.
long long calibrate_time(unsigned int skew_sleep_time=0, unsigned int samples=10)
Calibrate the time offset between the laser and computer.
void set_ip(IPAddr const &addr, IPAddr const &subnet, IPAddr const &gateway)
Change the IP address information.
void reset()
Reset the laser scanner to its default settings.
void set_multiecho_mode(MultiechoMode mode)
Set the multi-echo mode to use.
Definition sensor.h:455
void set_skew_alpha(float alpha)
Set a skew line slope value.
Definition sensor.h:261
void set_power(bool on)
Switch the laser scanner on or off.
void get_sensor_info(SensorInfo &info)
Get various information about the scanner.
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.
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.
void set_drift_rate(float drift_rate)
Set the current clock drift rate.
Definition sensor.h:244
unsigned int get_raw_time()
Get the raw value of the scanner's clock in milliseconds.
unsigned long long get_time()
Get the value of the scanner's clock in milliseconds.
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.
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.
float skew_alpha() const
Get the calculated skew line slope (default: 0).
Definition sensor.h:248
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.
void ignore_unknowns(bool ignore)
Enables/disables ignoring unknown lines in sensor info messages.
Definition sensor.h:452
bool is_open() const
Checks if the connection to the laser scanner is open.
long long time_offset() const
Retrieve the calculated time offset (0 if not calibrated).
Definition sensor.h:222
float drift_rate() const
Retrieve the current clock drift rate (0 if not set).
Definition sensor.h:228
void semi_reset()
Reset everything except motor and serial speed.
double step_to_angle(unsigned int step)
A convenience function to convert a step index to an 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.
unsigned int angle_to_step(double angle)
A convenience function to convert an angle to a step (rounded towards the front).
Sensor(std::ostream &err_output)
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.
uint8_t scip_version() const
Return the major version of the SCIP protocol in use.
Definition sensor.h:444
Sensor information.
#define HOKUYOAIST_EXPORT
MultiechoMode
Possible values of the multiecho mode setting.
Definition sensor.h:74
@ ME_FRONT
Definition sensor.h:76
@ ME_REAR
Definition sensor.h:78
@ ME_MIDDLE
Definition sensor.h:77
@ ME_AVERAGE
Definition sensor.h:79
LaserModel
Laser models.
Definition sensor_info.h:59
struct hokuyoaist::IPAddr IPAddr
Structure to store an IP address.
HOKUYOAIST_EXPORT char const * multiecho_mode_to_string(MultiechoMode mode)
Definition sensor.h:83
Structure to store an IP address.
Definition sensor.h:105
unsigned int fourth
Fourth byte.
Definition sensor.h:113
unsigned int third
Third byte.
Definition sensor.h:111
unsigned int second
Second byte.
Definition sensor.h:109
unsigned int first
First byte.
Definition sensor.h:107