6#define _USE_MATH_DEFINES
16#include <opencv2/opencv.hpp>
17#include <opencv2/core/version.hpp>
18#include <opencv2/highgui/highgui_c.h>
19#include <opencv2/highgui.hpp>
39#define DEG2RAD M_PI/180.0
61 const float step = (0.5 * scale);
70 std::string
fmt =
"%3.1fm";
76 else if (scale > 50 && scale <=174)
80 else if (scale > 22 && scale <= 50)
84 else if (scale > 9 && scale <= 22)
95 cv::putText(img, buff,
cvPoint(img.cols / 2,
int(
float(img.rows) / 2.0 -
float(step) *
rad)), cv::FONT_HERSHEY_SIMPLEX, 0.4,
cvScalar(0, 0, 0), 1, cv::LINE_AA);
120 cv::circle(img, cv::Point(img.cols/2, img.rows/2), (
int)(
v2),
color_black);
121 cv::circle(img, cv::Point(img.cols/2, img.rows/2), (
int)(
v3),
color_black);
134 for (
int i=0; i<360; i+=10)
140 ang = i + (*comp)[0] + 180;
151 if (i==0) {
sprintf(buff,
"N");
tempSize = cv::getTextSize( buff, cv::FONT_HERSHEY_SIMPLEX, 0.8, 1, &
lw ); cv::putText(img, buff,
cvPoint(
tx-
tempSize.width/2,
ty+
tempSize.height/2), cv::FONT_HERSHEY_SIMPLEX, 0.8,
cvScalar(0, 0, 0), 1, cv::LINE_AA);}
152 else if (i==90) {
sprintf(buff,
"E");
tempSize = cv::getTextSize( buff, cv::FONT_HERSHEY_SIMPLEX, 0.8, 1, &
lw ); cv::putText(img, buff,
cvPoint(
tx-
tempSize.width/2,
ty+
tempSize.height/2), cv::FONT_HERSHEY_SIMPLEX, 0.8,
cvScalar(0, 0, 0), 1, cv::LINE_AA);}
153 else if (i==180) {
sprintf(buff,
"S");
tempSize = cv::getTextSize( buff, cv::FONT_HERSHEY_SIMPLEX, 0.8, 1, &
lw ); cv::putText(img, buff,
cvPoint(
tx-
tempSize.width/2,
ty+
tempSize.height/2), cv::FONT_HERSHEY_SIMPLEX, 0.8,
cvScalar(0, 0, 0), 1, cv::LINE_AA);}
154 else if (i==270) {
sprintf(buff,
"W");
tempSize = cv::getTextSize( buff, cv::FONT_HERSHEY_SIMPLEX, 0.8, 1, &
lw ); cv::putText(img, buff,
cvPoint(
tx-
tempSize.width/2,
ty+
tempSize.height/2), cv::FONT_HERSHEY_SIMPLEX, 0.8,
cvScalar(0, 0, 0), 1, cv::LINE_AA);}
155 else {
sprintf(buff,
"%d",i);
tempSize = cv::getTextSize( buff, cv::FONT_HERSHEY_SIMPLEX, 0.4, 1, &
lw ); cv::putText(img, buff,
cvPoint(
tx-
tempSize.width/2,
ty+
tempSize.height/2), cv::FONT_HERSHEY_SIMPLEX, 0.4,
cvScalar(0, 0, 0), 1, cv::LINE_AA);}
161 if (display->
size()==8)
163 yError (
"wrong image format!");
177 center.x = (
int)(img.cols/2 );
178 center.y = (
int)(img.rows/2 );
204void drawLaser(
const Vector *comp, std::vector<yarp::sig::LaserMeasurementData> *
las, std::vector<yarp::sig::LaserMeasurementData> *
lmap, cv::Mat& img,
double angle_tot,
int scans,
double sens_position_x,
double sens_position_y,
double sens_position_t,
double scale,
bool absolute,
bool verbose,
int aspect)
206 img.setTo(cv::Scalar(0, 0, 0));
221 if (
las==
nullptr || comp==
nullptr)
228 yError(
"received vector size:%d ",
int(
las->size()));
238 for (
int i = 0; i<scans; i++)
242 (*las)[i].get_cartesian(x, y);
244 if (x == std::numeric_limits<double>::infinity() ||
245 y == std::numeric_limits<double>::infinity())
continue;
247 if (std::isinf(x) || std::isinf(y))
271 if (std::isnan(x) || std::isnan(y))
320 (*lmap)[i].get_cartesian(x, y);
333 yInfo() <<
"Available options:";
334 yInfo() <<
"--scale <double> zoom factor (default 100)";
335 yInfo() <<
"--robot_radius <double> the radius of the displayed robot footprint ";
336 yInfo() <<
"--sens_position_x <double> the position in meters of the laser center respect to the center of the robot (default 0 m)";
337 yInfo() <<
"--sens_position_y <double> the position in meters of the laser center respect to the center of the robot (default 0 m)";
338 yInfo() <<
"--sens_position_theta <double> the orientation in degrees of the laser sensor respect to the center of the robot (default 0 deg)";
339 yInfo() <<
"--verbose <bool> toggles debug messages on/off (default false)";
340 yInfo() <<
"--absolute <bool> display the laser in absolute o relative mode (default false)";
341 yInfo() <<
"--compass <bool> displays the compass (default true) ";
342 yInfo() <<
"--period <double> the refresh period (default 50 ms)";
343 yInfo() <<
"--aspect <0/1> draws line/points (default 0=lines)";
344 yInfo() <<
"--sens_port <string> the name of the port used by rangefinder2D_nwc_yarp to connect to the laser device. (mandatory)";
345 yInfo() <<
"--carrier <string> the name of the carrier used by rangefinder2D_nwc_yarp for connection to the server";
346 yInfo() <<
"--lidar_debug shows NaN values";
347 yInfo() <<
"--local <string> the prefix for the client port. By default /laserScannerGui. Useful in case of multiple instances.";
349 yInfo() <<
"Available commands (pressing the key during execution):";
350 yInfo() <<
"c ...... enables/disables compass.";
351 yInfo() <<
"a ...... set absolute/relative mode.";
352 yInfo() <<
"w ...... zoom in.";
353 yInfo() <<
"s ...... zoom out.";
354 yInfo() <<
"v ...... set verbose mode on/off.";
355 yInfo() <<
"r ...... set refresh period (50/100/200ms).";
356 yInfo() <<
"b ...... change aspect (lines/points)";
359int main(
int argc,
char *argv[])
368 if (rf.
check(
"help"))
373 double scale = rf.
check(
"scale",
Value(100),
"global scale factor").asFloat64();
378 bool verbose = rf.
check(
"verbose",
Value(
false),
"verbose [0/1]").asBool();
381 int period = rf.
check(
"period",
Value(50),
"period [ms]").asInt32();
382 int aspect = rf.
check(
"aspect",
Value(0),
"0 draw lines, 1 draw points").asInt32();
383 std::string
laserport = rf.
check(
"sens_port",
Value(
"/laser:o"),
"laser port name").asString();
384 std::string carrier = rf.
check(
"carrier",
Value(
"tcp"),
"rangefinder2D_nwc_yarp connection carrier").asString();
385 std::string
localprefix = rf.
check(
"local",
Value(
"/laserScannerGui"),
"prefix for the client port").asString();
402 lasOptions.put(
"device",
"rangefinder2D_nwc_yarp");
409 yError() <<
"Unable to open polydriver";
417 yError() <<
"Unable to get IRangefinder2D interface";
422 double angle_min = 0;
423 double angle_max = 0;
425 iLas->getScanLimits(angle_min, angle_max);
426 double angle_tot = (angle_max - angle_min);
429 std::vector<yarp::sig::LaserMeasurementData> laser_data;
439 cv::Mat img = cv::Mat(width, height,
CV_8UC3);
464 iLas->getLaserMeasurement(laser_data);
495 yWarning() <<
"Problem detected in size of laser measurement vector";
499 drawLaser(&
compass_data, &laser_data,
nullptr, img,
angle_tot, scans,
sens_position_x,
sens_position_y,
sens_position_t, scale,
absolute, verbose,
aspect);
515 cv::addWeighted(img, 0.7,
img2, 0.3, 0.0, img);
531 yInfo(
"scale factor is now:%.3f",scale);
537 yInfo(
"scale factor is now:%.3f", scale);
543 yInfo(
"verbose mode is now ON");
545 yInfo(
"verbose mode is now OFF");
552 yInfo(
"display is now in ABSOLUTE mode");
554 yInfo(
"display is now in RELATIVE mode");
561 }
else if (period == 50) {
563 }
else if (period == 100) {
565 }
else if (period == 200) {
568 yInfo(
"refresh period set to %d ms.", period);
586 yInfo(
"available commands:");
587 yInfo(
"c ...... enables/disables compass.");
588 yInfo(
"a ...... set absolute/relative mode.");
589 yInfo(
"w ...... zoom in.");
590 yInfo(
"s ...... zoom out.");
591 yInfo(
"v ...... set verbose mode on/off.");
592 yInfo(
"r ...... set refresh rate.");
593 yInfo(
"b ...... change aspect");
contains the definition of a Vector type
bool view(T *&x)
Get an interface to the device driver.
A generic interface for planar laser range finders.
A container for a device driver.
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.
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
T * read(bool shouldWait=true) override
Read an available object from the port.
Utilities for manipulating the YARP network, including initialization and shutdown.
A class for storing options and configuration information.
Helper class for finding config files and other external resources.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
bool configure(int argc, char *argv[], bool skipFirstArgument=true)
Sets up the ResourceFinder.
bool setDefaultConfigFile(const std::string &fname)
Provide a default value for the configuration file (can be overridden from command line with the –fro...
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.
void drawLaser(const Vector *comp, std::vector< yarp::sig::LaserMeasurementData > *las, std::vector< yarp::sig::LaserMeasurementData > *lmap, cv::Mat &img, double angle_tot, int scans, double sens_position_x, double sens_position_y, double sens_position_t, double scale, bool absolute, bool verbose, int aspect)
int main(int argc, char *argv[])
void drawCompass(const yarp::sig::Vector *comp, cv::Mat &img, bool absolute)
const CvScalar color_gray
void drawNav(const yarp::os::Bottle *display, cv::Mat &img, double scale)
void drawGrid(cv::Mat &img, double scale)
const CvScalar color_yellow
const CvScalar color_white
void drawRobot(cv::Mat &img, double robot_radius, double scale)
const CvScalar color_bwhite
const CvScalar color_black
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.
The main, catch-all namespace for YARP.
bool absolute(const char *path)