19 #if MRPT_HAS_ROBOPEAK_LIDAR 22 # define RPLIDAR_DRV static_cast<RPlidarDriver*>(m_rplidar_drv) 36 CRoboPeakLidar::CRoboPeakLidar() :
38 m_com_port_baudrate(115200),
55 #if MRPT_HAS_ROBOPEAK_LIDAR 56 RPlidarDriver::DisposeDriver(RPLIDAR_DRV);
65 bool &outThereIsObservation,
69 #if MRPT_HAS_ROBOPEAK_LIDAR 70 outThereIsObservation =
false;
71 hardwareError =
false;
80 rplidar_response_measurement_node_t nodes[360*2];
81 size_t count =
sizeof(nodes)/
sizeof(nodes[0]);
92 op_result = RPLIDAR_DRV->ascendScanData(nodes,
count);
95 const size_t angle_compensate_nodes_count = 360;
96 const size_t angle_compensate_multiple = 1;
97 int angle_compensate_offset = 0;
98 rplidar_response_measurement_node_t angle_compensate_nodes[angle_compensate_nodes_count];
99 memset(angle_compensate_nodes, 0, angle_compensate_nodes_count*
sizeof(rplidar_response_measurement_node_t));
103 for(
size_t i=0 ; i <
count; i++ )
108 int angle_value = (int)(angle * angle_compensate_multiple);
109 if ((angle_value - angle_compensate_offset) < 0) angle_compensate_offset = angle_value;
110 for (
size_t j = 0; j < angle_compensate_multiple; j++)
112 angle_compensate_nodes[angle_value-angle_compensate_offset+j] = nodes[i];
117 for(
size_t i=0 ; i < angle_compensate_nodes_count; i++ )
119 const float read_value = (float) angle_compensate_nodes[i].
distance_q2/4.0f/1000;
131 outObservation.
timestamp = tim_scan_start;
145 outThereIsObservation =
true;
168 configSource.
read_float(iniSection,
"pose_x",0),
169 configSource.
read_float(iniSection,
"pose_y",0),
170 configSource.
read_float(iniSection,
"pose_z",0),
176 #ifdef MRPT_OS_WINDOWS 191 #if MRPT_HAS_ROBOPEAK_LIDAR 193 if (ret && RPLIDAR_DRV)
194 RPLIDAR_DRV->startMotor();
206 #if MRPT_HAS_ROBOPEAK_LIDAR 209 RPLIDAR_DRV->stopMotor();
220 #if MRPT_HAS_ROBOPEAK_LIDAR 221 if (!RPLIDAR_DRV)
return false;
223 rplidar_response_device_health_t healthinfo;
225 u_result op_result = RPLIDAR_DRV->getHealth(healthinfo);
226 if (
IS_OK(op_result))
228 printf(
"[CRoboPeakLidar] RPLidar health status : %d\n", healthinfo.status);
231 fprintf(stderr,
"[CRoboPeakLidar] Error, rplidar internal error detected. Please reboot the device to retry.\n");
237 fprintf(stderr,
"[CRoboPeakLidar] Error, cannot retrieve rplidar health code: %x\n", op_result);
255 #if MRPT_HAS_ROBOPEAK_LIDAR 260 m_rplidar_drv = RPlidarDriver::CreateDriver(RPlidarDriver::DRIVER_TYPE_SERIALPORT);
277 fprintf(stderr,
"[CRoboPeakLidar] Error, cannot bind to the specified serial port %s\n",
m_com_port.c_str() );
281 rplidar_response_device_info_t devinfo;
282 if (
IS_FAIL(RPLIDAR_DRV->getDeviceInfo(devinfo) ))
289 printf(
"[CRoboPeakLidar] Connection established:\n" 290 "Firmware version: %u\n" 291 "Hardware version: %u\n" 294 (
unsigned int)devinfo.firmware_version,
295 (
unsigned int)devinfo.hardware_version,
296 (
unsigned int)devinfo.model);
298 for (
int i=0;i<16;i++)
299 printf(
"%02X",devinfo.serialnum[i]);
311 fprintf(stderr,
"[CRoboPeakLidar] Error starting scanning mode: %x\n",
res);
328 throw std::runtime_error(
"[CRoboPeakLidar::initialize] Error initializing RPLIDAR scanner.");
330 throw std::runtime_error(
"[CRoboPeakLidar::initialize] Error initializing RPLIDAR scanner.");
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
GLuint GLuint GLsizei count
virtual void initialize()
Attempts to connect and turns the laser on. Raises an exception on error.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
void setSerialPort(const std::string &port_name)
If set to non-empty, the serial port will be attempted to be opened automatically when this class is ...
#define RPLIDAR_RESP_MEASUREMENT_ANGLE_SHIFT
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
void setScanRange(const size_t i, const float val)
std::string m_sensorLabel
See CGenericSensor.
void disconnect()
Closes the comms with the laser. Shouldn't have to be directly needed by the user.
#define THROW_EXCEPTION(msg)
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Contains classes for various device interfaces.
virtual void doProcessSimple(bool &outThereIsObservation, mrpt::obs::CObservation2DRangeScan &outObservation, bool &hardwareError)
Specific laser scanner "software drivers" must process here new data from the I/O stream...
bool getDeviceHealth() const
Returns true if the device is connected & operative.
int BASE_IMPEXP fprintf(FILE *fil, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(2
An OS-independent version of fprintf.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
void filterByExclusionAreas(mrpt::obs::CObservation2DRangeScan &obs) const
Mark as invalid those points which (x,y) coordinates fall within the exclusion polygons.
float stdError
The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid...
void filterByExclusionAngles(mrpt::obs::CObservation2DRangeScan &obs) const
Mark as invalid those ranges in a set of forbiden angle ranges.
This class allows loading and storing values and vectors of different types from a configuration text...
float maxRange
The maximum range allowed by the device, in meters (e.g. 80m, 50m,...)
void loadConfig_sensorSpecific(const mrpt::utils::CConfigFileBase &configSource, const std::string &iniSection)
See the class documentation at the top for expected parameters.
This namespace contains representation of robot actions and observations.
Interfaces a Robo Peak LIDAR laser scanner.
void resizeScanAndAssign(const size_t len, const float rangeVal, const bool rangeValidity, const int32_t rangeIntensity=0)
Resizes all data vectors to allocate a given number of scan rays and assign default values...
void loadCommonParams(const mrpt::utils::CConfigFileBase &configSource, const std::string &iniSection)
Should be call by derived classes at "loadConfig" (loads exclusion areas AND exclusion angles)...
GLsizei const GLchar ** string
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
#define RESULT_OPERATION_TIMEOUT
bool checkCOMMs()
Returns true if communication has been established with the device.
virtual bool turnOff()
See base class docs.
virtual bool turnOn()
See base class docs.
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp. Where available, this should contain the accurate satellite-based time...
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
poses::CPose3D m_sensorPose
The sensor 6D pose:
void setFromValues(const double x0, const double y0, const double z0, const double yaw=0, const double pitch=0, const double roll=0)
Set the pose from a 3D position (meters) and yaw/pitch/roll angles (radians) - This method recomputes...
void processPreview(const mrpt::obs::CObservation2DRangeScan &obs)
Must be called inside the capture method to allow optional GUI preview of scans.
The namespace for 3D scene representation and rendering.
float aperture
The "aperture" or field-of-view of the range finder, in radians (typically M_PI = 180 degrees)...
#define RESULT_OPERATION_FAIL
#define ASSERTMSG_(f, __ERROR_MSG)
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot at the moment of starting the scan.
virtual ~CRoboPeakLidar()
Destructor: turns the laser off.
bool rightToLeft
The scanning direction: true=counterclockwise; false=clockwise.
void setScanRangeValidity(const size_t i, const bool val)
#define RPLIDAR_STATUS_OK