|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
19 #define _USE_MATH_DEFINES
39 #define DEG2RAD M_PI/180.0
53 now=SystemClock::nowSystem();
66 now=SystemClock::nowSystem();
71 double tmpDT=
now-prev;
94 getEnvelope(newStamp);
97 if (lastStamp.isValid()==
false)
111 lastStamp = newStamp;
133 ranges= lastScan.scans;
183 yCError(RANGEFINDER2DCLIENT,
"open() error you have to provide valid local name");
188 yCError(RANGEFINDER2DCLIENT,
"open() error you have to provide valid remote name");
192 std::string local_rpc = local;
193 local_rpc +=
"/rpc:o";
194 std::string remote_rpc = remote;
195 remote_rpc +=
"/rpc:i";
197 if (!inputPort.open(local))
199 yCError(RANGEFINDER2DCLIENT,
"open() error could not open port %s, check network\n",local.c_str());
202 inputPort.useCallback();
204 if (!rpcPort.open(local_rpc))
206 yCError(RANGEFINDER2DCLIENT,
"open() error could not open rpc port %s, check network\n", local_rpc.c_str());
210 bool ok=Network::connect(remote.c_str(), local.c_str(),
"udp");
213 yCError(RANGEFINDER2DCLIENT,
"open() error could not connect to %s\n", remote.c_str());
217 ok=Network::connect(local_rpc, remote_rpc);
220 yCError(RANGEFINDER2DCLIENT,
"open() error could not connect to %s\n", remote_rpc.c_str());
227 this->getScanLimits(tmp_min, tmp_max);
230 device_position_x = 0;
231 device_position_y = 0;
232 device_position_theta = 0;
235 TransformClientOptions.
put(
"device",
"transformClient");
236 TransformClientOptions.
put(
"local",
"/rangefinder2DTransformClient");
237 TransformClientOptions.
put(
"remote",
"/transformServer");
238 TransformClientOptions.
put(
"period",
"10");
240 bool b_canOpenTransformClient =
false;
241 if (config.
check(
"laser_frame_name") &&
242 config.
check(
"robot_frame_name"))
244 laser_frame_name = config.
find(
"laser_frame_name").
toString();
245 robot_frame_name = config.
find(
"robot_frame_name").
toString();
246 b_canOpenTransformClient = drv->open(TransformClientOptions);
249 if (b_canOpenTransformClient)
255 yCError(RANGEFINDER2DCLIENT) <<
"A Problem occurred while trying to view the IFrameTransform interface";
262 iTrf->
getTransform(laser_frame_name, robot_frame_name, mat);
264 device_position_x = mat[0][3];
265 device_position_y = mat[1][3];
266 device_position_theta = v[2];
267 if (fabs(v[0]) < 1e-6 && fabs(v[1]) < 1e-6)
269 yCError(RANGEFINDER2DCLIENT) <<
"Laser device is not planar";
271 yCInfo(RANGEFINDER2DCLIENT) <<
"Position information obtained fromtransform server";
276 if (config.
check(
"device_position_x") &&
277 config.
check(
"device_position_y") &&
278 config.
check(
"device_position_theta"))
280 yCInfo(RANGEFINDER2DCLIENT) <<
"Position information obtained from configuration parameters";
281 device_position_x = config.
find(
"device_position_x").
asFloat64();
282 device_position_y = config.
find(
"device_position_y").
asFloat64();
283 device_position_theta = config.
find(
"device_position_theta").
asFloat64();
287 yCDebug(RANGEFINDER2DCLIENT) <<
"No position information provided for this device";
304 inputPort.getData(data);
311 inputPort.getData(ranges);
312 size_t size = ranges.
size();
314 if (scan_angle_max < scan_angle_min) {
yCError(RANGEFINDER2DCLIENT) <<
"getLaserMeasurement failed";
return false; }
315 double laser_angle_of_view = scan_angle_max - scan_angle_min;
316 for (
size_t i = 0; i < size; i++)
318 double angle = (i / double(size)*laser_angle_of_view + device_position_theta + scan_angle_min)*
DEG2RAD;
319 double value = ranges[i];
320 #if 1 //cartesian version is preferable, even if more computationally expensive, since it takes in account device_position
321 data[i].set_cartesian(value * cos(angle) + device_position_x, value * sin(angle) + device_position_y);
323 data[i].set_polar(value,angle);
335 bool ok = rpcPort.write(cmd, response);
336 if (CHECK_FAIL(ok, response) !=
false)
353 bool ok = rpcPort.write(cmd, response);
356 scan_angle_min = min;
357 scan_angle_max = max;
359 return (CHECK_FAIL(ok, response));
368 bool ok = rpcPort.write(cmd, response);
369 if (CHECK_FAIL(ok, response) !=
false)
386 bool ok = rpcPort.write(cmd, response);
387 return (CHECK_FAIL(ok, response));
396 bool ok = rpcPort.write(cmd, response);
397 if (CHECK_FAIL(ok, response) !=
false)
412 bool ok = rpcPort.write(cmd, response);
413 return (CHECK_FAIL(ok, response));
422 bool ok = rpcPort.write(cmd, response);
423 if (CHECK_FAIL(ok, response) !=
false)
438 bool ok = rpcPort.write(cmd, response);
439 return (CHECK_FAIL(ok, response));
444 status = inputPort.getStatus();
454 bool ok = rpcPort.write(cmd, response);
455 if (CHECK_FAIL(ok, response)!=
false)
A simple collection of objects that can be described and transmitted in a portable way.
yarp::os::Stamp getLastInputStamp() override
Get the time stamp for the last read data.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
constexpr yarp::conf::vocab32_t VOCAB_ILASER2D
A base class for nested structures that can be searched.
bool setScanLimits(double min, double max) override
set the scan angular range.
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....
constexpr yarp::conf::vocab32_t VOCAB_LASER_SCAN_RATE
bool setHorizontalResolution(double step) override
get the angular step between two measurments (if available)
#define YARP_LOG_COMPONENT(name,...)
bool getHorizontalResolution(double &step) override
get the angular step between two measurments.
constexpr yarp::conf::vocab32_t VOCAB_GET
bool getDistanceRange(double &min, double &max) override
get the device detection range
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface for the device drivers.
constexpr yarp::conf::vocab32_t VOCAB_SET
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool close() override
Close the DeviceDriver.
double getTime() const
Get the time stamp.
virtual std::string asString() const
Get string value.
A container for a device driver.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
bool setScanRate(double rate) override
set the scan rate (scans per seconds)
constexpr yarp::conf::vocab32_t VOCAB_LASER_DISTANCE_RANGE
constexpr yarp::conf::vocab32_t VOCAB_LASER_ANGULAR_STEP
void addVocab(int x)
Places a vocabulary item in the bottle, at the end of the list.
bool getScanRate(double &rate) override
get the scan rate (scans per seconds)
An abstraction for a time stamp and/or sequence number.
#define yCError(component,...)
constexpr yarp::conf::vocab32_t VOCAB_DEVICE_INFO
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
bool getDeviceStatus(Device_status &status) override
get the device status
constexpr yarp::conf::vocab32_t VOCAB_LASER_ANGULAR_RANGE
bool getLaserMeasurement(std::vector< yarp::dev::LaserMeasurementData > &data) override
Get the device measurements.
bool setDistanceRange(double min, double max) override
set the device detection range.
bool getRawData(yarp::sig::Vector &data) override
Get the device measurements.
bool getDeviceInfo(std::string &device_info) override
get the device hardware charactestics
std::string toString() const override
Return a standard text representation of the content of the object.
bool getScanLimits(double &min, double &max) override
get the scan angular range.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
A class for storing options and configuration information.