HokuyoAIST
3.0.2
|
Hokuyo laser scanner class. More...
#include <hokuyoaist/sensor.h>
Public Member Functions | |
Sensor () | |
Sensor (std::ostream &err_output) | |
~Sensor () | |
void | open (std::string port_options) |
Open the laser scanner and begin scanning. More... | |
void | close () |
Close the connection to the laser scanner. More... | |
bool | is_open () const |
Checks if the connection to the laser scanner is open. More... | |
void | set_power (bool on) |
Switch the laser scanner on or off. More... | |
void | set_ip (IPAddr const &addr, IPAddr const &subnet, IPAddr const &gateway) |
Change the IP address information. More... | |
void | reset () |
Reset the laser scanner to its default settings. More... | |
void | semi_reset () |
Reset everything except motor and serial speed. More... | |
void | set_motor_speed (unsigned int speed) |
Set the speed at which the scanner's sensor spins. More... | |
void | set_high_sensitivity (bool on) |
Switch the scanner between normal and high sensitivity modes. More... | |
void | get_sensor_info (SensorInfo &info) |
Get various information about the scanner. More... | |
unsigned long long | get_time () |
Get the value of the scanner's clock in milliseconds. More... | |
unsigned int | get_raw_time () |
Get the raw value of the scanner's clock in milliseconds. More... | |
long long | calibrate_time (unsigned int skew_sleep_time=0, unsigned int samples=10) |
Calibrate the time offset between the laser and computer. More... | |
long long | time_offset () const |
Retrieve the calculated time offset (0 if not calibrated). More... | |
void | set_time_offset (long long time_offset) |
Set the time offset (if the calculated value is bad). More... | |
float | drift_rate () const |
Retrieve the current clock drift rate (0 if not set). More... | |
void | set_drift_rate (float drift_rate) |
Set the current clock drift rate. More... | |
float | skew_alpha () const |
Get the calculated skew line slope (default: 0). More... | |
void | set_skew_alpha (float alpha) |
Set a skew line slope value. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
uint8_t | scip_version () const |
Return the major version of the SCIP protocol in use. More... | |
void | set_verbose (bool verbose) |
Turns on and off printing of verbose operating information to stderr. More... | |
void | ignore_unknowns (bool ignore) |
Enables/disables ignoring unknown lines in sensor info messages. More... | |
void | set_multiecho_mode (MultiechoMode mode) |
Set the multi-echo mode to use. More... | |
double | step_to_angle (unsigned int step) |
A convenience function to convert a step index to an angle. More... | |
unsigned int | angle_to_step (double angle) |
A convenience function to convert an angle to a step (rounded towards the front). More... | |
Hokuyo laser scanner class.
Provides an interface for interacting with a Hokuyo laser scanner using SCIP protocol version 2. The FlexiPort library is used to implement the data communications with the scanner. See its documentation for details on controlling the connection.
To use a serial connection, ensure that you do not also have a USB cable connected, as this will force the scanner into USB mode, preventing the serial connection from functioning correctly.
All functions may throw instances of BaseError or its children. Exceptions from FlexiPort may also occur.
hokuyoaist::Sensor::Sensor | ( | ) |
|
explicit |
hokuyoaist::Sensor::~Sensor | ( | ) |
unsigned int hokuyoaist::Sensor::angle_to_step | ( | double | angle | ) |
A convenience function to convert an angle to a step (rounded towards the front).
long long hokuyoaist::Sensor::calibrate_time | ( | unsigned int | skew_sleep_time = 0 , |
unsigned int | samples = 10 |
||
) |
Calibrate the time offset between the laser and computer.
This function performs several checks of the communications between the laser and the computer. Its goal is to calculate the communications lag between the two devices, and so determine as accurately as possible what the offset is from the computer's clock to the laser's clock. This offset is necessary to calculate the time stamp of scans in terms of the computer's clock.
Because this function sends a lot of data to and from the laser, it may take some time to complete. It will never be called automatically; until it is called, the offset defaults to zero.
Note that the laser's clock is a 24-bit millisecond timer. It wraps approximately every 9.5 hours. This class will detect wrapped time stamps and adjust them accordingly.
skew_sleep_time | Whether to approximate the laser clock skew. This requires sleeping for the specified time, then calibrating again. The results of the two calibrations are used to approximate the clock skew as a straight line between the two points. This is very approximate; in order to overcome noise in the signal you will need to calibrate over a period of up to several minutes. Set this to 0 to not approximate the skew. |
samples | The number of samples to use in calculating latencies. |
void hokuyoaist::Sensor::close | ( | ) |
Close the connection to the laser scanner.
|
inline |
unsigned int hokuyoaist::Sensor::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.
Unlike get_ranges, which returns the most recent scan the scanner took, this function will request a new scan. This means it will wait while the scanner performs the scan, which means the rate at which scans can be retrieved using this function is less than with get_ranges. Otherwise behaves identicallty to get_ranges.
data | Pointer to a ScanData object to store the range readings in. |
cluster_count | The number of readings to cluster together into a single reading. The minimum value from a cluster is returned as the range for that cluster. |
start_step | The first step to get ranges from. Set to -1 for the first scannable step. |
end_step | The last step to get ranges from. Set to -1 for the last scannable step. |
unsigned int hokuyoaist::Sensor::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.
data | Pointer to a ScanData object to store the range readings in. |
start_angle | The angle to get range readings from. Exclusive; if this falls between two steps the step inside the angle will be returned, but the step outside won't. |
end_angle | The angle to get range readings to. Exclusive; if this falls between two steps the step inside the angle will be returned, but the step outside won't. |
cluster_count | The number of readings to cluster together into a single reading. The minimum value from a cluster is returned as the range for that cluster. |
unsigned int hokuyoaist::Sensor::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.
Unlike get_ranges, which returns the most recent scan the scanner took, this function will request a new scan. This means it will wait while the scanner performs the scan. Otherwise behaves identicallty to get_ranges.
data | Pointer to a ScanData object to store the range readings in. |
cluster_count | The number of readings to cluster together into a single reading. The minimum value from a cluster is returned as the range for that cluster. |
start_step | The first step to get ranges from. Set to -1 for the first scannable step. |
end_step | The last step to get ranges from. Set to -1 for the last scannable step. |
unsigned int hokuyoaist::Sensor::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.
data | Pointer to a ScanData object to store the range readings in. |
start_angle | The angle to get range readings from. Exclusive; if this falls between two steps the step inside the angle will be returned, but the step outside won't. |
end_angle | The angle to get range readings to. Exclusive; if this falls between two steps the step inside the angle will be returned, but the step outside won't. |
cluster_count | The number of readings to cluster together into a single reading. The minimum value from a cluster is returned as the range for that cluster. |
unsigned int hokuyoaist::Sensor::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.
This function requires a pointer to a ScanData object. It will allocate space in this object as necessary for storing range data. If the passed-in ScanData object already has the correct quantity of space to store the range data, it will not be re-allocated. If it does not have any space, it will be allocated. If it has space, but it is the wrong size, it will be re-allocated. This means you can repeatedly send the same ScanData object without having to worry about allocating its data, whether it will change or not, while also avoiding excessive allocations.
data | Pointer to a ScanData object to store the range readings in. |
cluster_count | The number of readings to cluster together into a single reading. The minimum value from a cluster is returned as the range for that cluster. |
start_step | The first step to get ranges from. Set to -1 for the first scannable step. |
end_step | The last step to get ranges from. Set to -1 for the last scannable step. |
unsigned int hokuyoaist::Sensor::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.
data | Pointer to a ScanData object to store the range readings in. |
start_angle | The angle to get range readings from. Exclusive; if this falls between two steps the step inside the angle will be returned, but the step outside won't. |
end_angle | The angle to get range readings to. Exclusive; if this falls between two steps the step inside the angle will be returned, but the step outside won't. |
cluster_count | The number of readings to cluster together into a single reading. The minimum value from a cluster is returned as the range for that cluster. |
unsigned int hokuyoaist::Sensor::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.
This function requires a pointer to a ScanData object. It will allocate space in this object as necessary for storing range data. If the passed-in ScanData object already has the correct quantity of space to store the range data, it will not be re-allocated. If it does not have any space, it will be allocated. If it has space, but it is the wrong size, it will be re-allocated. This means you can repeatedly send the same ScanData object without having to worry about allocating its data, whether it will change or not, while also avoiding excessive allocations.
data | Pointer to a ScanData object to store the range readings in. |
cluster_count | The number of readings to cluster together into a single reading. The minimum value from a cluster is returned as the range for that cluster. |
start_step | The first step to get ranges from. Set to -1 for the first scannable step. |
end_step | The last step to get ranges from. Set to -1 for the last scannable step. |
unsigned int hokuyoaist::Sensor::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.
data | Pointer to a ScanData object to store the range readings in. |
start_angle | The angle to get range readings from. Exclusive; if this falls between two steps the step inside the angle will be returned, but the step outside won't. |
end_angle | The angle to get range readings to. Exclusive; if this falls between two steps the step inside the angle will be returned, but the step outside won't. |
cluster_count | The number of readings to cluster together into a single reading. The minimum value from a cluster is returned as the range for that cluster. |
unsigned int hokuyoaist::Sensor::get_raw_time | ( | ) |
Get the raw value of the scanner's clock in milliseconds.
void hokuyoaist::Sensor::get_sensor_info | ( | SensorInfo & | info | ) |
Get various information about the scanner.
unsigned long long hokuyoaist::Sensor::get_time | ( | ) |
Get the value of the scanner's clock in milliseconds.
|
inline |
bool hokuyoaist::Sensor::is_open | ( | ) | const |
Checks if the connection to the laser scanner is open.
void hokuyoaist::Sensor::open | ( | std::string | port_options | ) |
Open the laser scanner and begin scanning.
void hokuyoaist::Sensor::reset | ( | ) |
Reset the laser scanner to its default settings.
|
inline |
void hokuyoaist::Sensor::semi_reset | ( | ) |
Reset everything except motor and serial speed.
Requires SCIP v2.1 or higher.
|
inline |
Set the current clock drift rate.
The drift rate is used when correcting laser time stamps to computer time. It is factored into the equation as: Tc = ((1 - drift)Tl + offset + beta) / (1 - alpha) where Tc is the computer time and Tl is the laser time. See set_skew_alpha for the values of alpha and beta.
If the drift rate is zero, it means the laser's clock does not drift. This is extremely unlikely, but the laser's drift may not matter for your application.
Drift should usually be provided by the manufacturer. If it is not, you can calculate it by calibrating the laser many times over a long period and looking at the change in the calculated offset.
void hokuyoaist::Sensor::set_high_sensitivity | ( | bool | on | ) |
Switch the scanner between normal and high sensitivity modes.
void hokuyoaist::Sensor::set_ip | ( | IPAddr const & | addr, |
IPAddr const & | subnet, | ||
IPAddr const & | gateway | ||
) |
Change the IP address information.
This function only works on devices providing an ethernet connection.
Once this function has successfully completed, the laser must be restarted for it to take effect.
void hokuyoaist::Sensor::set_motor_speed | ( | unsigned int | speed | ) |
Set the speed at which the scanner's sensor spins.
Set the speed to 0 to have it reset to the default value, and 99 to reset it to the initial (startup) value. Values between 1 and 10 specify a ratio of the default speed. The speeds in revolutions per minute that these correspond to will depend on the scanner model. For example, for a URG-04LX, they are (from 1 to 10) 594, 588, 576, 570, 564, 558, 552, 546, and 540 rpm.
|
inline |
void hokuyoaist::Sensor::set_power | ( | bool | on | ) |
Switch the laser scanner on or off.
|
inline |
Set a skew line slope value.
The skew is used when correcting laser time stamps to computer time. It is factored into the equation as: Tc = ((1 - drift)Tl + offset + beta) / (1 - alpha) where Tc is the computer time and Tl is the laser time. See drift_rate for the value of the drift. Beta, the line's y crossing, is assumed to be 0 since we always use a two-point line fit instead of something like least squares.
The effect of this is to cancel out the skew caused by the different frequencies of the computer clock and the laser clock.
|
inline |
|
inline |
|
inline |
double hokuyoaist::Sensor::step_to_angle | ( | unsigned int | step | ) |
A convenience function to convert a step index to an angle.
|
inline |