19#ifndef _USE_MATH_DEFINES
20#define _USE_MATH_DEFINES
25#define DEG2RAD M_PI/180.0
31using namespace rp::standalone::rplidar;
44 m_device_status = DEVICE_OK_STANDBY;
50 if (this->parseConfiguration(config) ==
false)
56 bool br = config.check(
"GENERAL");
62 if (
general_config.check(
"sample_buffer_life") ==
false) {
yCError(
RP2_LIDAR) <<
"Missing sample_buffer_life param in GENERAL group";
return false; }
66 m_buffer_life =
general_config.find(
"sample_buffer_life").asInt32();
83 m_drv = RPlidarDriver::CreateDriver(rp::standalone::rplidar::DRIVER_TYPE_SERIALPORT);
90 if (
IS_FAIL(m_drv->connect(m_serialPort.c_str(), (
_u32)baudrate)))
92 yCError(
RP2_LIDAR) <<
"Error, cannot bind to the specified serial port:", m_serialPort.c_str();
93 RPlidarDriver::DisposeDriver(m_drv);
97 m_info = deviceinfo();
98 yCInfo(
RP2_LIDAR,
"max_dist %f, min_dist %f", m_max_distance, m_min_distance);
100 bool m_inExpressMode=
false;
101 result = m_drv->checkExpressScanSupported(m_inExpressMode);
102 if (result ==
RESULT_OK && m_inExpressMode==
true)
111 result = m_drv->startMotor();
121 if (m_pwm_val>0 && m_pwm_val<1023)
123 result = m_drv->setMotorPWM(m_pwm_val);
133 yCError(
RP2_LIDAR) <<
"Invalid motor pwm request " << m_pwm_val <<
". It should be a value between 0 and 1023.";
143 result = m_drv->startScan(
forceScan,m_inExpressMode);
153 yCInfo(
RP2_LIDAR,
"max_angle %f, min_angle %f", m_max_angle, m_min_angle);
165 RPlidarDriver::DisposeDriver(
m_drv);
197 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
207#define _countof(_Array) (int)(sizeof(_Array) / sizeof (_Array[0]))
240 m_drv->ascendScanData(nodes, count);
262 for (
size_t i = 0;
i < count; ++
i)
265 double distance = nodes[
i].distance_q2 / 4.0f / 1000.0;
283 distance = std::numeric_limits<double>::infinity();
345std::string RpLidar2::deviceinfo()
365 return "Firmware Version: " + std::to_string(
info.firmware_version) +
366 "\nHardware Version: " + std::to_string(
info.hardware_version) +
367 "\nModel: " + std::to_string(
info.model) +
rpLidar2: The device driver for the RP2 lidar
yarp::dev::ReturnValue setDistanceRange(double min, double max) override
set the device detection range.
bool close() override
Close the DeviceDriver.
bool threadInit() override
Initialization method.
bool acquireDataFromHW() override final
This method should be implemented by the user, and contain the logic to grab data from the hardware.
void threadRelease() override
Release method.
void run() override
Loop function.
yarp::dev::ReturnValue setScanLimits(double min, double max) override
set the scan angular range.
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)
virtual bool updateLidarData()
This utility method calls in sequence: grabDataFromHW(), updateTimestamp and applyLimitsOnLaserData()...
yarp::sig::Vector m_laser_data
A mini-server for performing network communication in the background.
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 base class for nested structures that can be searched.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
The main, catch-all namespace for YARP.
const yarp::os::LogComponent & RP2_LIDAR()