6 #define _USE_MATH_DEFINES
21 #define DEG2RAD M_PI/180.0
32 info =
"Hokuyo Laser";
37 bool br = config.
check(
"GENERAL");
40 yCError(LASERHOKUYO,
"cannot read 'GENERAL' section");
47 period = general_config.
check(
"Period",
Value(50),
"Period of the sampling thread").asInt32() / 1000.0;
49 if (general_config.
check(
"max_angle") ==
false) {
yCError(LASERHOKUYO) <<
"Missing max_angle param";
return false; }
50 if (general_config.
check(
"min_angle") ==
false) {
yCError(LASERHOKUYO) <<
"Missing min_angle param";
return false; }
57 error_codes = general_config.
check(
"Convert_Error_Codes",
Value(0),
"Substitute error codes with legal measurments").asInt32();
58 std::string s = general_config.
check(
"Laser_Mode",
Value(
"GD"),
"Laser Mode (GD/MD").asString();
60 if (general_config.
check(
"Measurement_Units"))
62 yCError(LASERHOKUYO) <<
"Deprecated parameter 'Measurement_Units'. Please Remove it from the configuration file.";
67 yCInfo(LASERHOKUYO,
"'error_codes' option enabled. Invalid samples will be substituted with out-of-range measurements.");
72 yCInfo(LASERHOKUYO,
"Using GD mode (single acquisition)");
77 yCInfo(LASERHOKUYO,
"Using MD mode (continuous acquisition)");
82 yCError(LASERHOKUYO,
"Laser_mode not found. Using GD mode (single acquisition)");
86 bool br2 = config.
check(
"SERIAL_PORT_CONFIGURATION");
89 yCError(LASERHOKUYO,
"cannot read 'SERIAL_PORT_CONFIGURATION' section");
93 std::string ss = serial_config.
toString();
96 prop.
put(
"device",
"serialport");
101 yCError(LASERHOKUYO,
"Error opening PolyDriver check parameters");
110 yCError(LASERHOKUYO,
"Error opening serial driver. Device not available");
125 yCInfo(LASERHOKUYO,
"URG device successfully initialized.");
130 yCError(LASERHOKUYO,
"Error: URG device not found.");
152 yCDebug(LASERHOKUYO,
"%s",ans.c_str());
162 yCDebug(LASERHOKUYO,
"%s", ans.c_str());
183 yCDebug(LASERHOKUYO,
"%s", ans.c_str());
186 found = ans.find(
"MODL");
187 if (found != std::string::npos) {
190 found = ans.find(
"DMIN");
191 if (found != std::string::npos) {
194 found = ans.find(
"DMAX");
195 if (found != std::string::npos) {
198 found = ans.find(
"ARES");
199 if (found != std::string::npos) {
202 found = ans.find(
"AMIN");
203 if (found != std::string::npos) {
206 found = ans.find(
"AMAX");
207 if (found != std::string::npos) {
210 found = ans.find(
"AFRT");
211 if (found != std::string::npos) {
214 found = ans.find(
"SCAN");
215 if (found != std::string::npos) {
258 return PeriodicThread::start();
263 PeriodicThread::stop();
292 yCError(LASERHOKUYO,
"setDistanceRange NOT YET IMPLEMENTED");
306 yCError(LASERHOKUYO,
"setScanLimits NOT YET IMPLEMENTED");
318 yCError(LASERHOKUYO,
"setHorizontalResolution NOT YET IMPLEMENTED");
330 yCError(LASERHOKUYO,
"setScanRate NOT YET IMPLEMENTED");
359 yCError(LASERHOKUYO) <<
"getLaserMeasurement failed";
365 for (
size_t i = 0; i < size; i++)
388 yCTrace(LASERHOKUYO,
"laserHokuyo:: thread initialising...");
389 yCTrace(LASERHOKUYO,
"... done!");
393 inline int laserHokuyo::calculateCheckSum(
const char*
buffer,
int size,
char actual_sum)
395 char expected_sum = 0x00;
398 for (i = 0; i < size; ++i)
400 expected_sum +=
buffer[i];
402 expected_sum = (expected_sum & 0x3f) + 0x30;
404 return (expected_sum == actual_sum) ? 0 : -1;
407 inline long laserHokuyo::decodeDataValue(
const char* data,
int data_byte)
410 for (
int i = 0; i < data_byte; ++i)
414 value |= data[i] - 0x30;
419 int laserHokuyo::readData(
const Laser_mode_type laser_mode,
const char* text_data,
const int text_data_len,
int current_line,
yarp::sig::Vector& data)
421 static char data_block [4000];
423 if (text_data_len==0)
431 if (text_data_len == 1 &&
432 text_data[0] ==
'\n')
435 int len = strlen(data_block);
436 for (
int value_counter =0; value_counter < len; value_counter+=3)
438 int value = decodeDataValue(data_block+value_counter, 3);
450 if (current_line == 0)
456 yCTrace(LASERHOKUYO,
"Invalid answer to a MD command: %s", text_data);
464 if (current_line == 1)
466 if ((
laser_mode ==
MD_MODE && (text_data[0] !=
'9' || text_data[1] !=
'9' || text_data[2] !=
'b' )) ||
467 (
laser_mode ==
GD_MODE && (text_data[0] !=
'0' || text_data[1] !=
'0' || text_data[2] !=
'P' )))
469 yCTrace(LASERHOKUYO,
"Invalid sensor status: %s", text_data);
477 if (current_line >= 2)
479 char expected_checksum = text_data[text_data_len - 2];
480 if (calculateCheckSum(text_data, text_data_len - 2, expected_checksum) < 0)
482 yCTrace(LASERHOKUYO,
"Checksum error, line: %d: %s", current_line, text_data);
488 if (current_line == 2)
494 if (current_line >= 3)
496 strncat (data_block, text_data, text_data_len-2 );
510 constexpr
int buffer_size = 128;
511 char command [buffer_size];
512 char answer [buffer_size];
516 std::string data_text;
519 bool timeout =
false;
520 bool rx_completed =
false;
541 if (t2 - t1 > maxtime) {
545 while (rx_completed ==
false && timeout ==
false && error ==
false);
549 yCError(LASERHOKUYO,
"laserHokuyo Timeout!");
555 yCTrace(LASERHOKUYO,
"time: %.3f %.3f",t2-t1, t2-old);
578 yCTrace(LASERHOKUYO,
"laserHokuyo Thread releasing...");
579 yCTrace(LASERHOKUYO,
"... done.");
586 this->
mutex.unlock();
Device_status device_status
bool setScanRate(double rate) override
set the scan rate (scans per seconds)
bool getDeviceStatus(Device_status &status) override
get the device status
@ HOKUYO_STATUS_ERROR_INVALID_CHECKSUM
@ HOKUYO_STATUS_NOT_READY
@ HOKUYO_STATUS_ERROR_BUSY
@ HOKUYO_STATUS_ERROR_INVALID_COMMAND
@ HOKUYO_STATUS_ERROR_NOTHING_RECEIVED
@ HOKUYO_STATUS_ACQUISITION_COMPLETE
bool getLaserMeasurement(std::vector< LaserMeasurementData > &data) override
Get the device measurements.
void run() override
Loop function.
bool getScanRate(double &rate) override
get the scan rate (scans per seconds)
bool getScanLimits(double &min, double &max) override
get the scan angular range.
bool getDistanceRange(double &min, double &max) override
get the device detection range
void threadRelease() override
Release method.
yarp::sig::Vector laser_data
struct laserHokuyo::sensor_property_struct sensor_properties
bool setHorizontalResolution(double step) override
get the angular step between two measurments (if available)
bool threadInit() override
Initialization method.
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool setDistanceRange(double min, double max) override
set the device detection range.
bool getDeviceInfo(std::string &device_info) override
get the device hardware charactestics
Laser_mode_type laser_mode
bool setScanLimits(double min, double max) override
set the scan angular range.
bool getHorizontalResolution(double &step) override
get the angular step between two measurments.
bool getRawData(yarp::sig::Vector &data) override
Get the device measurements.
bool view(T *&x)
Get an interface to the device driver.
virtual int receiveLine(char *line, const int MaxLineLength)=0
Gets one line (a sequence of chars with a ending '\n' or '\r') from the receive queue.
virtual bool send(const yarp::os::Bottle &msg)=0
Sends a string of chars to the serial communications channel.
virtual bool receive(yarp::os::Bottle &msg)=0
Gets the existing chars in the receive queue.
bool close() override
Close the DeviceDriver.
bool isValid() const
Check if device is valid.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A simple collection of objects that can be described and transmitted in a portable way.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void clear()
Empties the bottle of any objects it contains.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
bool setPeriod(double period)
Set the (new) period of the thread.
void step()
Call this to "step" the thread rather than starting it.
A class for storing options and configuration information.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
A base class for nested structures that can be searched.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
static double nowSystem()
static void delaySystem(double seconds)
A single value (typically within a Bottle).
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual std::string asString() const
Get string value.
std::string toString(int precision=-1, int width=-1) const
Creates a string object containing a text representation of the object.
void resize(size_t size) override
Resize the vector.
void push_back(const T &elem)
Push a new element in the vector: size is changed.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)