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 
42 {
43 protected:
46 
47  std::mutex mutex;
48 
49  int cardId;
50  double period;
54  double min_angle;
55  double max_angle;
58  std::string info;
60 
61  enum Laser_mode_type {FAKE_MODE=2, GD_MODE=1, MD_MODE=0};
63  {
64  HOKUYO_STATUS_ACQUISITION_COMPLETE =1,
65  HOKUYO_STATUS_OK = 0,
66  HOKUYO_STATUS_ERROR_BUSY = -1,
67  HOKUYO_STATUS_ERROR_INVALID_COMMAND = -2,
68  HOKUYO_STATUS_ERROR_INVALID_CHECKSUM = -3,
69  HOKUYO_STATUS_ERROR_NOTHING_RECEIVED = -4,
70  HOKUYO_STATUS_NOT_READY = -5
71  };
72 
74 
76  {
77  std::string MODL;
78  int DMIN;
79  int DMAX;
80  int ARES;
81  int AMIN;
82  int AMAX;
83  int AFRT;
84  int SCAN;
85  } sensor_properties;
86 
88 
89 public:
90  laserHokuyo(double period = 0.02) : PeriodicThread(period),
91  pSerial(nullptr),
92  mutex(),
93  cardId(0),
94  period(period),
95  sensorsNum(0),
96  start_position(0),
97  end_position(0),
98  min_angle(0.0),
99  max_angle(0.0),
100  error_codes(0),
101  internal_status(0),
102  info(""),
103  device_status(Device_status::DEVICE_OK_STANBY),
104  laser_mode(Laser_mode_type::FAKE_MODE)
105  {}
106 
107 
109  {
110  }
111 
112  bool open(yarp::os::Searchable& config) override;
113  bool close() override;
114  bool threadInit() override;
115  void threadRelease() override;
116  void run() override;
117 
118 public:
119  //IRangefinder2D interface
120  bool getRawData(yarp::sig::Vector &data) override;
121  bool getLaserMeasurement(std::vector<LaserMeasurementData> &data) override;
122  bool getDeviceStatus (Device_status &status) override;
123  bool getDeviceInfo (std::string &device_info) override;
124  bool getDistanceRange (double& min, double& max) override;
125  bool setDistanceRange (double min, double max) override;
126  bool getScanLimits (double& min, double& max) override;
127  bool setScanLimits (double min, double max) override;
128  bool getHorizontalResolution (double& step) override;
129  bool setHorizontalResolution (double step) override;
130  bool getScanRate (double& rate) override;
131  bool setScanRate (double rate) override;
132 
133 private:
134  //laser methods
135  int calculateCheckSum(const char* buffer, int size, char actual_sum);
136  long decodeDataValue(const char* data, int data_byte);
137  int readData(const Laser_mode_type laser_mode, const char* text_data, const int lext_data_len, int current_line, yarp::sig::Vector& values);
138 };
139 
140 #endif
laserHokuyo::max_angle
double max_angle
Definition: laserHokuyo.h:55
laserHokuyo::sensor_property_struct::AMIN
int AMIN
Definition: laserHokuyo.h:81
laserHokuyo::sensor_property_struct::AMAX
int AMAX
Definition: laserHokuyo.h:82
laserHokuyo::cardId
int cardId
Definition: laserHokuyo.h:49
laserHokuyo::device_status
Device_status device_status
Definition: laserHokuyo.h:59
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
IRangefinder2D.h
Vector.h
contains the definition of a Vector type
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
yarp::dev::IRangefinder2D
A generic interface for planar laser range finders.
Definition: IRangefinder2D.h:38
laserHokuyo::laser_data
yarp::sig::Vector laser_data
Definition: laserHokuyo.h:87
yarp::dev::ISerialDevice
A generic interface to serial port devices.
Definition: ISerialDevice.h:28
laserHokuyo::period
double period
Definition: laserHokuyo.h:50
yarp::dev::IRangefinder2D::Device_status
Device_status
Definition: IRangefinder2D.h:41
laserHokuyo::sensor_property_struct
Definition: laserHokuyo.h:76
ControlBoardInterfaces.h
define control board standard interfaces
laserHokuyo::~laserHokuyo
~laserHokuyo()
Definition: laserHokuyo.h:108
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
laserHokuyo::Laser_mode_type
Laser_mode_type
Definition: laserHokuyo.h:61
laserHokuyo::Error_code
Error_code
Definition: laserHokuyo.h:63
laserHokuyo::pSerial
ISerialDevice * pSerial
Definition: laserHokuyo.h:45
yarp::sig::VectorOf< double >
laserHokuyo::laser_mode
Laser_mode_type laser_mode
Definition: laserHokuyo.h:73
laserHokuyo::error_codes
int error_codes
Definition: laserHokuyo.h:56
laserHokuyo::sensor_property_struct::DMAX
int DMAX
Definition: laserHokuyo.h:79
PolyDriver.h
laserHokuyo::start_position
int start_position
Definition: laserHokuyo.h:52
laserHokuyo::sensor_property_struct::MODL
std::string MODL
Definition: laserHokuyo.h:77
yarp::dev::PolyDriver
A container for a device driver.
Definition: PolyDriver.h:27
buffer
Definition: V4L_camera.h:75
laserHokuyo::sensor_property_struct::DMIN
int DMIN
Definition: laserHokuyo.h:78
ISerialDevice.h
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
laserHokuyo::mutex
std::mutex mutex
Definition: laserHokuyo.h:47
laserHokuyo::sensorsNum
int sensorsNum
Definition: laserHokuyo.h:51
PeriodicThread.h
laserHokuyo::sensor_property_struct::SCAN
int SCAN
Definition: laserHokuyo.h:84
laserHokuyo::info
std::string info
Definition: laserHokuyo.h:58
laserHokuyo::sensor_property_struct::ARES
int ARES
Definition: laserHokuyo.h:80
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
laserHokuyo::driver
PolyDriver driver
Definition: laserHokuyo.h:44
laserHokuyo::sensor_property_struct::AFRT
int AFRT
Definition: laserHokuyo.h:83
laserHokuyo::internal_status
int internal_status
Definition: laserHokuyo.h:57
laserHokuyo::end_position
int end_position
Definition: laserHokuyo.h:53
laserHokuyo::laserHokuyo
laserHokuyo(double period=0.02)
Definition: laserHokuyo.h:90
laserHokuyo
laserHokuyo: Documentation to be added
Definition: laserHokuyo.h:42
laserHokuyo::min_angle
double min_angle
Definition: laserHokuyo.h:54