6 #define _USE_MATH_DEFINES
26 #define DEG2RAD M_PI/180.0
40 now=SystemClock::nowSystem();
53 now=SystemClock::nowSystem();
58 double tmpDT=
now-prev;
60 if (tmpDT > deltaTMax) {
63 if (tmpDT < deltaTMin) {
83 getEnvelope(newStamp);
86 if (lastStamp.isValid()==
false)
100 lastStamp = newStamp;
122 ranges= lastScan.scans;
172 yCError(RANGEFINDER2DCLIENT,
"open() error you have to provide valid local name");
177 yCError(RANGEFINDER2DCLIENT,
"open() error you have to provide valid remote name");
181 std::string local_rpc = local;
182 local_rpc +=
"/rpc:o";
183 std::string remote_rpc = remote;
184 remote_rpc +=
"/rpc:i";
186 if (!inputPort.open(local))
188 yCError(RANGEFINDER2DCLIENT,
"open() error could not open port %s, check network\n",local.c_str());
191 inputPort.useCallback();
193 if (!rpcPort.open(local_rpc))
195 yCError(RANGEFINDER2DCLIENT,
"open() error could not open rpc port %s, check network\n", local_rpc.c_str());
199 bool ok=Network::connect(remote.c_str(), local.c_str(),
"udp");
202 yCError(RANGEFINDER2DCLIENT,
"open() error could not connect to %s\n", remote.c_str());
206 ok=Network::connect(local_rpc, remote_rpc);
209 yCError(RANGEFINDER2DCLIENT,
"open() error could not connect to %s\n", remote_rpc.c_str());
216 this->getScanLimits(tmp_min, tmp_max);
219 device_position_x = 0;
220 device_position_y = 0;
221 device_position_theta = 0;
224 TransformClientOptions.
put(
"device",
"transformClient");
225 TransformClientOptions.
put(
"local",
"/rangefinder2DTransformClient");
226 TransformClientOptions.
put(
"remote",
"/transformServer");
227 TransformClientOptions.
put(
"period",
"10");
229 bool b_canOpenTransformClient =
false;
230 if (config.
check(
"laser_frame_name") &&
231 config.
check(
"robot_frame_name"))
233 laser_frame_name = config.
find(
"laser_frame_name").
toString();
234 robot_frame_name = config.
find(
"robot_frame_name").
toString();
235 b_canOpenTransformClient = drv->open(TransformClientOptions);
238 if (b_canOpenTransformClient)
244 yCError(RANGEFINDER2DCLIENT) <<
"A Problem occurred while trying to view the IFrameTransform interface";
251 iTrf->
getTransform(laser_frame_name, robot_frame_name, mat);
253 device_position_x = mat[0][3];
254 device_position_y = mat[1][3];
255 device_position_theta = v[2];
256 if (fabs(v[0]) < 1e-6 && fabs(v[1]) < 1e-6)
258 yCError(RANGEFINDER2DCLIENT) <<
"Laser device is not planar";
260 yCInfo(RANGEFINDER2DCLIENT) <<
"Position information obtained fromtransform server";
265 if (config.
check(
"device_position_x") &&
266 config.
check(
"device_position_y") &&
267 config.
check(
"device_position_theta"))
269 yCInfo(RANGEFINDER2DCLIENT) <<
"Position information obtained from configuration parameters";
270 device_position_x = config.
find(
"device_position_x").
asFloat64();
271 device_position_y = config.
find(
"device_position_y").
asFloat64();
272 device_position_theta = config.
find(
"device_position_theta").
asFloat64();
276 yCDebug(RANGEFINDER2DCLIENT) <<
"No position information provided for this device";
293 inputPort.getData(data);
300 inputPort.getData(ranges);
301 size_t size = ranges.
size();
303 if (scan_angle_max < scan_angle_min) {
yCError(RANGEFINDER2DCLIENT) <<
"getLaserMeasurement failed";
return false; }
304 double laser_angle_of_view = scan_angle_max - scan_angle_min;
305 for (
size_t i = 0; i < size; i++)
307 double angle = (i / double(size)*laser_angle_of_view + device_position_theta + scan_angle_min)*
DEG2RAD;
308 double value = ranges[i];
310 data[i].set_cartesian(value * cos(angle) + device_position_x, value * sin(angle) + device_position_y);
312 data[i].set_polar(value,angle);
324 bool ok = rpcPort.write(cmd, response);
325 if (CHECK_FAIL(ok, response) !=
false)
342 bool ok = rpcPort.write(cmd, response);
345 scan_angle_min = min;
346 scan_angle_max = max;
348 return (CHECK_FAIL(ok, response));
357 bool ok = rpcPort.write(cmd, response);
358 if (CHECK_FAIL(ok, response) !=
false)
375 bool ok = rpcPort.write(cmd, response);
376 return (CHECK_FAIL(ok, response));
385 bool ok = rpcPort.write(cmd, response);
386 if (CHECK_FAIL(ok, response) !=
false)
401 bool ok = rpcPort.write(cmd, response);
402 return (CHECK_FAIL(ok, response));
411 bool ok = rpcPort.write(cmd, response);
412 if (CHECK_FAIL(ok, response) !=
false)
427 bool ok = rpcPort.write(cmd, response);
428 return (CHECK_FAIL(ok, response));
433 status = inputPort.getStatus();
443 bool ok = rpcPort.write(cmd, response);
444 if (CHECK_FAIL(ok, response)!=
false)
constexpr yarp::conf::vocab32_t VOCAB_GET
constexpr yarp::conf::vocab32_t VOCAB_SET
constexpr yarp::conf::vocab32_t VOCAB_LASER_ANGULAR_RANGE
constexpr yarp::conf::vocab32_t VOCAB_LASER_SCAN_RATE
constexpr yarp::conf::vocab32_t VOCAB_ILASER2D
constexpr yarp::conf::vocab32_t VOCAB_LASER_DISTANCE_RANGE
constexpr yarp::conf::vocab32_t VOCAB_DEVICE_INFO
constexpr yarp::conf::vocab32_t VOCAB_LASER_ANGULAR_STEP
bool setDistanceRange(double min, double max) override
set the device detection range.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool getHorizontalResolution(double &step) override
get the angular step between two measurments.
bool getScanRate(double &rate) override
get the scan rate (scans per seconds)
yarp::os::Stamp getLastInputStamp() override
Get the time stamp for the last read data.
bool setHorizontalResolution(double step) override
get the angular step between two measurments (if available)
bool close() override
Close the DeviceDriver.
bool setScanRate(double rate) override
set the scan rate (scans per seconds)
bool setScanLimits(double min, double max) override
set the scan angular range.
bool getDistanceRange(double &min, double &max) override
get the device detection range
bool getLaserMeasurement(std::vector< yarp::dev::LaserMeasurementData > &data) override
Get the device measurements.
bool getDeviceStatus(Device_status &status) override
get the device status
bool getRawData(yarp::sig::Vector &data) override
Get the device measurements.
bool getDeviceInfo(std::string &device_info) override
get the device hardware charactestics
bool getScanLimits(double &min, double &max) override
get the scan angular range.
A container for a device driver.
A simple collection of objects that can be described and transmitted in a portable way.
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
A class for storing options and configuration information.
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.
An abstraction for a time stamp and/or sequence number.
double getTime() const
Get the time stamp.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
std::string toString() const override
Return a standard text representation of the content of the object.
virtual std::string asString() const
Get string value.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface for the device drivers.
yarp::sig::Vector dcm2rpy(const yarp::sig::Matrix &R)
Converts a dcm (direction cosine matrix) rotation matrix to roll-pitch-yaw angles (defined in Math....
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.