YARP
Yet Another Robot Platform
rpLidar3.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6#ifndef RPLIDAR3_H
7#define RPLIDAR3_H
8
9
11#include <yarp/os/Semaphore.h>
14#include <yarp/dev/PolyDriver.h>
15#include <yarp/sig/Vector.h>
18
19#include <mutex>
20#include <string>
21#include <vector>
22
23#include <rplidar.h>
24
25using namespace yarp::os;
26using namespace yarp::dev;
27
28typedef unsigned char byte;
29
30//---------------------------------------------------------------------------------------------------------------
50{
51 typedef rp::standalone::rplidar::RPlidarDriver rplidardrv;
52
53 void handleError(u_result error);
54
55protected:
57 bool m_inExpressMode = false;
58 bool m_force_scan = false;
59 std::string m_scan_mode ="Boost";
60 int m_pwm_val = 600;
61 std::string m_serialPort;
62 rplidardrv* m_drv = nullptr;
63 const size_t m_nodes_num = 8192;
64 rplidar_response_measurement_node_hq_t* m_nodes = nullptr;
65
66public:
67 RpLidar3(double period = 0) : PeriodicThread(period) //period=0 allows to run the thread as fast as possible, but it is not a busy loop since yield() is called internally
68 {
69 m_nodes = new rplidar_response_measurement_node_hq_t[m_nodes_num];
70 }
71
73 {
74 delete [] m_nodes;
75 }
76
77 bool open(yarp::os::Searchable& config) override;
78 bool close() override;
79 bool threadInit() override;
80 void threadRelease() override;
81 void run() override;
82
83private:
84 bool startMotor();
85 bool startScan();
86 bool deviceinfo();
87
88public:
89 //IRangefinder2D interface
90 bool setDistanceRange (double min, double max) override;
91 bool setScanLimits (double min, double max) override;
92 bool setHorizontalResolution (double step) override;
93 bool setScanRate (double rate) override;
94
95public:
96 //Lidar2DDeviceBase
97 bool acquireDataFromHW() override final;
98};
99
100#endif
define control board standard interfaces
contains the definition of a Vector type
rpLidar2: The device driver for the RP2 lidar
Definition: rpLidar3.h:50
const size_t m_nodes_num
Definition: rpLidar3.h:63
rplidar_response_measurement_node_hq_t * m_nodes
Definition: rpLidar3.h:64
std::string m_serialPort
Definition: rpLidar3.h:61
bool acquireDataFromHW() override final
This method should be implemented by the user, and contain the logic to grab data from the hardware.
Definition: rpLidar3.cpp:275
void run() override
Loop function.
Definition: rpLidar3.cpp:261
bool m_force_scan
Definition: rpLidar3.h:58
int m_pwm_val
Definition: rpLidar3.h:60
std::string m_scan_mode
Definition: rpLidar3.h:59
void threadRelease() override
Release method.
Definition: rpLidar3.cpp:349
bool setDistanceRange(double min, double max) override
set the device detection range.
Definition: rpLidar3.cpp:221
bool m_inExpressMode
Definition: rpLidar3.h:57
bool threadInit() override
Initialization method.
Definition: rpLidar3.cpp:251
bool setScanRate(double rate) override
set the scan rate (scans per seconds)
Definition: rpLidar3.cpp:244
bool close() override
Close the DeviceDriver.
Definition: rpLidar3.cpp:209
~RpLidar3()
Definition: rpLidar3.h:72
int m_buffer_life
Definition: rpLidar3.h:56
RpLidar3(double period=0)
Definition: rpLidar3.h:67
bool setScanLimits(double min, double max) override
set the scan angular range.
Definition: rpLidar3.cpp:229
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: rpLidar3.cpp:121
bool setHorizontalResolution(double step) override
get the angular step between two measurements (if available)
Definition: rpLidar3.cpp:237
rplidardrv * m_drv
Definition: rpLidar3.h:62
Interface implemented by all device drivers.
Definition: DeviceDriver.h:30
The Lidar2DDeviceBase class.
An abstraction for a periodic thread.
void step()
Call this to "step" the thread rather than starting it.
A base class for nested structures that can be searched.
Definition: Searchable.h:63
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
unsigned char byte
Definition: rpLidar3.h:28