6#define _USE_MATH_DEFINES
27#define DEG2RAD M_PI/180.0
36 maxsize = bufferSize + 1;
39 elems = (
byte *)
calloc(maxsize,
sizeof(
byte));
51 info =
"Fake Laser device for test/debugging";
61 bool br = config.
check(
"GENERAL");
93 for (
size_t s = 1; s <
s_maxs; s++)
116 if (fov >360) {
yCError(
RPLIDAR) <<
"max_angle - min_angle <= 360";
return false; }
130 yCError(
RPLIDAR,
"Cannot find configuration file for serial port communication!");
139 prop.
put(
"device",
"serialport");
143 yCError(
RPLIDAR,
"Unable to read from serial port configuration file");
157 yCError(
RPLIDAR,
"Error opening serial driver. Device not available");
182 yCInfo(
RPLIDAR,
"Sensor recovered from a previous error status");
268 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
291 return ReturnValue::return_code::return_value_error_method_failed;
294 for (
size_t i = 0;
i < size;
i++)
324bool RpLidar::HW_getInfo(std::string&
s_info)
334 unsigned char s[255];
342 if ((
unsigned char)s[0] != 0xA5 || (
unsigned char)s[1] != 0x5A || (
unsigned char)s[2] != 0x14 || (
unsigned char)s[6] != 0x04)
355 sprintf(
info,
"model %d fw_major %d fw_minor %d hardware %d serial number %c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c",
356 s[0], s[1], s[2], s[3],
357 s[4], s[5], s[6], s[7], s[8],
358 s[9], s[10], s[11], s[12], s[13],
359 s[14], s[15], s[16], s[17], s[18], s[19]);
364bool RpLidar::HW_getHealth()
376 unsigned char s[255];
385 if ((
unsigned char)s[0] != 0xA5 || (
unsigned char)s[1] != 0x5A || (
unsigned char)s[2] != 3 || (
unsigned char)s[6] != 0x06)
400 int code = s[1] << 8 | s[2];
405 else if (status == 1)
410 else if (status == 2)
419bool RpLidar::HW_reset()
432bool RpLidar::HW_start()
449 unsigned char s[255];
458 if ((
unsigned char)s[0] != 0xA5 || (
unsigned char)s[1] != 0x5A || (
unsigned char)s[2] != 0x05 ||
459 (
unsigned char)s[5] != 0x40 || (
unsigned char)s[6] != 0x81)
468bool RpLidar::HW_stop()
481#define DEBUG_LOCKING 1
488 const int packet = 100;
491 unsigned char buff[packet*3];
495 static unsigned int total_r = 0;
496 unsigned int count = 0;
500#ifdef DEBUG_BYTES_READ_1
506#ifdef DEBUG_BYTES_READ_2
513 while (
buffer->size() < (packet * 2) || r < packet);
523 int lock = (
minibuff[0] >> 1) & 0x01;
542 buffer->throw_away_elem();
553 buffer->throw_away_elem();
564 buffer->throw_away_elem();
575 buffer->throw_away_elem();
586 buffer->throw_away_elem();
597 buffer->throw_away_elem();
608 buffer->throw_away_elem();
644 distance = std::numeric_limits<double>::infinity();
672 distance = std::numeric_limits<double>::infinity();
699 buffer->throw_away_elems(5);
void run() override
Loop function.
yarp::sig::Vector laser_data
yarp::dev::ReturnValue getScanLimits(double &min, double &max) override
get the scan angular range.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue setScanLimits(double min, double max) override
set the scan angular range.
bool do_not_clip_infinity_enable
yarp::dev::ReturnValue getDeviceStatus(Device_status &status) override
get the device status
std::vector< Range_t > range_skip_vector
bool threadInit() override
Initialization method.
yarp::dev::ReturnValue getDistanceRange(double &min, double &max) override
get the device detection range
Device_status device_status
void threadRelease() override
Release method.
yarp::dev::ReturnValue getHorizontalResolution(double &step) override
get the angular step between two measurements.
yarp::dev::ReturnValue setHorizontalResolution(double step) override
get the angular step between two measurements (if available)
yarp::dev::ReturnValue setScanRate(double rate) override
set the scan rate (scans per seconds)
yarp::dev::ReturnValue setDistanceRange(double min, double max) override
set the device detection range.
yarp::dev::ReturnValue getDeviceInfo(std::string &device_info) override
get the device hardware characteristics
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue getScanRate(double &rate) override
get the scan rate (scans per seconds)
yarp::dev::ReturnValue getRawData(yarp::sig::Vector &data, double *timestamp) override
Get the device measurements.
yarp::dev::ReturnValue getLaserMeasurement(std::vector< yarp::sig::LaserMeasurementData > &data, double *timestamp) override
Get the device measurements.
bool view(T *&x)
Get an interface to the device driver.
virtual int flush()=0
Flushes the internal buffer.
virtual bool send(const yarp::os::Bottle &msg)=0
Sends a string of chars to the serial communications channel.
virtual int receiveBytes(unsigned char *bytes, const int size)=0
Gets an array of bytes (unsigned char) with size <= 'size' parameter.
bool close() override
Close the DeviceDriver.
bool isValid() const
Check if device is valid.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A simple collection of objects that can be described and transmitted in a portable way.
A mini-server for performing network communication in the background.
bool isRunning() const
Returns true when the thread is started, false otherwise.
bool start()
Call this to start the thread.
void step()
Call this to "step" the thread rather than starting it.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
A class for storing options and configuration information.
bool fromConfigFile(const std::string &fname, bool wipe=true)
Interprets a file as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Helper class for finding config files and other external resources.
std::string findFileByName(const std::string &name)
Find the full path to a file.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
static void delaySystem(double seconds)
void resize(size_t size) override
Resize the vector.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
double now()
Return the current time in seconds, relative to an arbitrary starting point.
The main, catch-all namespace for YARP.
const yarp::os::LogComponent & RPLIDAR()
const yarp::os::LogComponent & RPLIDAR()