YARP
Yet Another Robot Platform
laserHokuyo.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef LASERHOKUYO_THREAD_H
20 #define LASERHOKUYO_THREAD_H
21 
22 //#include <cstdio>
23 #include <string>
24 
25 #include <yarp/os/PeriodicThread.h>
26 #include <mutex>
29 #include <yarp/dev/PolyDriver.h>
30 #include <yarp/dev/ISerialDevice.h>
31 #include <yarp/sig/Vector.h>
32 
33 using namespace yarp::os;
34 using namespace yarp::dev;
35 
37 {
38 protected:
41 
42  std::mutex mutex;
43 
44  int cardId;
45  double period;
49  double min_angle;
50  double max_angle;
53  std::string info;
55 
56  enum Laser_mode_type {FAKE_MODE=2, GD_MODE=1, MD_MODE=0};
58  {
59  HOKUYO_STATUS_ACQUISITION_COMPLETE =1,
60  HOKUYO_STATUS_OK = 0,
61  HOKUYO_STATUS_ERROR_BUSY = -1,
62  HOKUYO_STATUS_ERROR_INVALID_COMMAND = -2,
63  HOKUYO_STATUS_ERROR_INVALID_CHECKSUM = -3,
64  HOKUYO_STATUS_ERROR_NOTHING_RECEIVED = -4,
65  HOKUYO_STATUS_NOT_READY = -5
66  };
67 
69 
71  {
72  std::string MODL;
73  int DMIN;
74  int DMAX;
75  int ARES;
76  int AMIN;
77  int AMAX;
78  int AFRT;
79  int SCAN;
80  } sensor_properties;
81 
83 
84 public:
85  laserHokuyo(double period = 0.02) : PeriodicThread(period),
86  pSerial(nullptr),
87  mutex(),
88  cardId(0),
89  period(period),
90  sensorsNum(0),
91  start_position(0),
92  end_position(0),
93  min_angle(0.0),
94  max_angle(0.0),
95  error_codes(0),
96  internal_status(0),
97  info(""),
98  device_status(Device_status::DEVICE_OK_STANBY),
99  laser_mode(Laser_mode_type::FAKE_MODE)
100  {}
101 
102 
104  {
105  }
106 
107  bool open(yarp::os::Searchable& config) override;
108  bool close() override;
109  bool threadInit() override;
110  void threadRelease() override;
111  void run() override;
112 
113 public:
114  //IRangefinder2D interface
115  bool getRawData(yarp::sig::Vector &data) override;
116  bool getLaserMeasurement(std::vector<LaserMeasurementData> &data) override;
117  bool getDeviceStatus (Device_status &status) override;
118  bool getDeviceInfo (std::string &device_info) override;
119  bool getDistanceRange (double& min, double& max) override;
120  bool setDistanceRange (double min, double max) override;
121  bool getScanLimits (double& min, double& max) override;
122  bool setScanLimits (double min, double max) override;
123  bool getHorizontalResolution (double& step) override;
124  bool setHorizontalResolution (double step) override;
125  bool getScanRate (double& rate) override;
126  bool setScanRate (double rate) override;
127 
128 private:
129  //laser methods
130  int calculateCheckSum(const char* buffer, int size, char actual_sum);
131  long decodeDataValue(const char* data, int data_byte);
132  int readData(const Laser_mode_type laser_mode, const char* text_data, const int lext_data_len, int current_line, yarp::sig::Vector& values);
133 };
134 
135 #endif
define control board standard interfaces
contains the definition of a Vector type
Device_status device_status
Definition: laserHokuyo.h:54
std::string info
Definition: laserHokuyo.h:53
PolyDriver driver
Definition: laserHokuyo.h:39
double period
Definition: laserHokuyo.h:45
int error_codes
Definition: laserHokuyo.h:51
int internal_status
Definition: laserHokuyo.h:52
int end_position
Definition: laserHokuyo.h:48
ISerialDevice * pSerial
Definition: laserHokuyo.h:40
std::mutex mutex
Definition: laserHokuyo.h:42
laserHokuyo(double period=0.02)
Definition: laserHokuyo.h:85
int start_position
Definition: laserHokuyo.h:47
yarp::sig::Vector laser_data
Definition: laserHokuyo.h:82
double min_angle
Definition: laserHokuyo.h:49
double max_angle
Definition: laserHokuyo.h:50
int sensorsNum
Definition: laserHokuyo.h:46
Laser_mode_type laser_mode
Definition: laserHokuyo.h:68
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
A generic interface for planar laser range finders.
A generic interface to serial port devices.
Definition: ISerialDevice.h:28
A container for a device driver.
Definition: PolyDriver.h:27
An abstraction for a periodic thread.
A base class for nested structures that can be searched.
Definition: Searchable.h:69
An interface for the device drivers.
An interface to the operating system, including Port based communication.