YARP
Yet Another Robot Platform
laserHokuyo.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 LASERHOKUYO_THREAD_H
7 #define LASERHOKUYO_THREAD_H
8 
9 //#include <cstdio>
10 #include <string>
11 
12 #include <yarp/os/PeriodicThread.h>
13 #include <mutex>
16 #include <yarp/dev/PolyDriver.h>
17 #include <yarp/dev/ISerialDevice.h>
18 #include <yarp/sig/Vector.h>
19 
20 using namespace yarp::os;
21 using namespace yarp::dev;
22 
29 {
30 protected:
33 
34  std::mutex mutex;
35 
36  int cardId;
37  double period;
41  double min_angle;
42  double max_angle;
45  std::string info;
47 
48  enum Laser_mode_type {FAKE_MODE=2, GD_MODE=1, MD_MODE=0};
50  {
51  HOKUYO_STATUS_ACQUISITION_COMPLETE =1,
52  HOKUYO_STATUS_OK = 0,
53  HOKUYO_STATUS_ERROR_BUSY = -1,
54  HOKUYO_STATUS_ERROR_INVALID_COMMAND = -2,
55  HOKUYO_STATUS_ERROR_INVALID_CHECKSUM = -3,
56  HOKUYO_STATUS_ERROR_NOTHING_RECEIVED = -4,
57  HOKUYO_STATUS_NOT_READY = -5
58  };
59 
61 
63  {
64  std::string MODL;
65  int DMIN;
66  int DMAX;
67  int ARES;
68  int AMIN;
69  int AMAX;
70  int AFRT;
71  int SCAN;
72  } sensor_properties;
73 
75 
76 public:
77  laserHokuyo(double period = 0.02) : PeriodicThread(period),
78  pSerial(nullptr),
79  mutex(),
80  cardId(0),
81  period(period),
82  sensorsNum(0),
83  start_position(0),
84  end_position(0),
85  min_angle(0.0),
86  max_angle(0.0),
87  error_codes(0),
88  internal_status(0),
89  info(""),
90  device_status(Device_status::DEVICE_OK_STANBY),
91  laser_mode(Laser_mode_type::FAKE_MODE)
92  {}
93 
94 
96  {
97  }
98 
99  bool open(yarp::os::Searchable& config) override;
100  bool close() override;
101  bool threadInit() override;
102  void threadRelease() override;
103  void run() override;
104 
105 public:
106  //IRangefinder2D interface
107  bool getRawData(yarp::sig::Vector &data, double* timestamp) override;
108  bool getLaserMeasurement(std::vector<LaserMeasurementData> &data, double* timestamp) override;
109  bool getDeviceStatus (Device_status &status) override;
110  bool getDeviceInfo (std::string &device_info) override;
111  bool getDistanceRange (double& min, double& max) override;
112  bool setDistanceRange (double min, double max) override;
113  bool getScanLimits (double& min, double& max) override;
114  bool setScanLimits (double min, double max) override;
115  bool getHorizontalResolution (double& step) override;
116  bool setHorizontalResolution (double step) override;
117  bool getScanRate (double& rate) override;
118  bool setScanRate (double rate) override;
119 
120 private:
121  //laser methods
122  int calculateCheckSum(const char* buffer, int size, char actual_sum);
123  long decodeDataValue(const char* data, int data_byte);
124  int readData(const Laser_mode_type laser_mode, const char* text_data, const int lext_data_len, int current_line, yarp::sig::Vector& values);
125 };
126 
127 #endif
define control board standard interfaces
contains the definition of a Vector type
laserHokuyo: Documentation to be added
Definition: laserHokuyo.h:29
Device_status device_status
Definition: laserHokuyo.h:46
std::string info
Definition: laserHokuyo.h:45
PolyDriver driver
Definition: laserHokuyo.h:31
double period
Definition: laserHokuyo.h:37
int error_codes
Definition: laserHokuyo.h:43
int internal_status
Definition: laserHokuyo.h:44
int end_position
Definition: laserHokuyo.h:40
ISerialDevice * pSerial
Definition: laserHokuyo.h:32
std::mutex mutex
Definition: laserHokuyo.h:34
laserHokuyo(double period=0.02)
Definition: laserHokuyo.h:77
int start_position
Definition: laserHokuyo.h:39
yarp::sig::Vector laser_data
Definition: laserHokuyo.h:74
double min_angle
Definition: laserHokuyo.h:41
double max_angle
Definition: laserHokuyo.h:42
int sensorsNum
Definition: laserHokuyo.h:38
Laser_mode_type laser_mode
Definition: laserHokuyo.h:60
Interface implemented by all device drivers.
Definition: DeviceDriver.h:30
A generic interface for planar laser range finders.
A generic interface to serial port devices.
Definition: ISerialDevice.h:24
A container for a device driver.
Definition: PolyDriver.h:23
An abstraction for a periodic thread.
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.