36#include <visp3/core/vpConfig.h>
37#include <visp3/robot/vpRobotPioneer.h>
38#include <visp3/core/vpDisplay.h>
39#include <visp3/core/vpImage.h>
40#include <visp3/core/vpIoTools.h>
41#include <visp3/core/vpTime.h>
42#include <visp3/gui/vpDisplayFactory.h>
43#include <visp3/io/vpImageIo.h>
45#ifndef VISP_HAVE_PIONEER
48 std::cout <<
"\nThis example requires Aria 3rd party library. You should "
56#ifdef ENABLE_VISP_NAMESPACE
62#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
63std::shared_ptr<vpDisplay> display;
68static bool isInitialized =
false;
69static int half_size = 256 * 2;
71void sonarPrinter(
void)
73 fprintf(stdout,
"in sonarPrinter()\n");
75 double scale =
static_cast<double>(half_size) /
static_cast<double>(sonar.getMaxRange());
106 printf(
"Closest readings within polar sections:\n");
108 double start_angle = -45;
109 double end_angle = 45;
110 range = sonar.currentReadingPolar(start_angle, end_angle, &angle);
111 printf(
" front quadrant: %5.0f ", range);
113 if (std::fabs(range - sonar.getMaxRange()) > std::numeric_limits<double>::epsilon())
114 printf(
"%3.0f ", angle);
116#if defined(VISP_HAVE_DISPLAY)
118 if (isInitialized && std::fabs(range - sonar.getMaxRange()) > std::numeric_limits<double>::epsilon()) {
124 double j = -
y * scale + half_size;
125 double i = -
x * scale + half_size;
135 range = sonar.currentReadingPolar(-135, -45, &angle);
136 printf(
" right quadrant: %5.0f ", range);
138 if (std::fabs(range - sonar.getMaxRange()) > std::numeric_limits<double>::epsilon())
139 printf(
"%3.0f ", angle);
142 range = sonar.currentReadingPolar(45, 135, &angle);
143 printf(
" left quadrant: %5.0f ", range);
145 if (std::fabs(range - sonar.getMaxRange()) > std::numeric_limits<double>::epsilon())
146 printf(
"%3.0f ", angle);
149 range = sonar.currentReadingPolar(-135, 135, &angle);
150 printf(
" back quadrant: %5.0f ", range);
152 if (std::fabs(range - sonar.getMaxRange()) > std::numeric_limits<double>::epsilon())
153 printf(
"%3.0f ", angle);
159 ArSensorReading *reading;
160 for (
int sensor = 0; sensor < robot->getNumSonar(); sensor++) {
161 reading = robot->getSonarReading(sensor);
162 if (reading !=
nullptr) {
163 angle = reading->getSensorTh();
164 range = reading->getRange();
165 double sx = reading->getSensorX();
166 double sy = reading->getSensorY();
174 double sj = -sy * scale + half_size;
175 double si = -sx * scale + half_size;
176 double j = -
y * scale + half_size;
177 double i = -
x * scale + half_size;
184#if defined(VISP_HAVE_DISPLAY)
186 if (isInitialized && std::fabs(range - sonar.getMaxRange()) > std::numeric_limits<double>::epsilon()) {
189 std::stringstream legend;
190 legend << sensor <<
": " << std::setprecision(2) << float(range) / 1000.;
197#if defined(VISP_HAVE_DISPLAY)
210int main(
int argc,
char **argv)
213 ArArgumentParser
parser(&argc, argv);
214 parser.loadDefaultArguments();
220 ArRobotConnector robotConnector(&parser, robot);
221 if (!robotConnector.connectRobot()) {
222 ArLog::log(ArLog::Terse,
"Could not connect to the robot");
223 if (
parser.checkHelpAndWarnUnparsed()) {
228 if (!Aria::parseArgs()) {
234 std::cout <<
"Robot connected" << std::endl;
236#if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)
238 if (isInitialized ==
false) {
239 I.resize(
static_cast<unsigned int>(half_size * 2),
static_cast<unsigned int>(half_size * 2));
242#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
247 isInitialized =
true;
252 ArGlobalFunctor sonarPrinterCB(&sonarPrinter);
253 robot->addRangeDevice(&sonar);
254 robot->addUserTask(
"Sonar printer", 50, &sonarPrinterCB);
256 robot->useSonar(
true);
261 for (
int i = 0;
i < 1000;
i++) {
265 std::cout <<
"Trans. vel= " << v_mes[0] <<
" m/s, Rot. vel=" <<
vpMath::deg(v_mes[1]) <<
" deg/s" << std::endl;
267 std::cout <<
"Left wheel vel= " << v_mes[0] <<
" m/s, Right wheel vel=" << v_mes[1] <<
" m/s" << std::endl;
268 std::cout <<
"Battery=" << robot->getBatteryVoltage() << std::endl;
270#if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)
278#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
295 std::cerr << std::endl <<
"ERROR:" << std::endl;
296 std::cerr <<
" Cannot create " << opath << std::endl;
300 std::string
filename = opath +
"/sonar.png";
313 ArLog::log(ArLog::Normal,
"simpleMotionCommands: Stopping.");
320 ArLog::log(ArLog::Normal,
321 "simpleMotionCommands: Pose=(%.2f,%.2f,%.2f), Trans. "
322 "Vel=%.2f, Rot. Vel=%.2f, Battery=%.2fV",
323 robot->getX(), robot->getY(), robot->getTh(), robot->getVel(), robot->getRotVel(),
324 robot->getBatteryVoltage());
327 std::cout <<
"Ending robot thread..." << std::endl;
328 robot->stopRunning();
330#if defined(VISP_HAVE_DISPLAY) && (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
331 if (isInitialized && (display !=
nullptr)) {
337 robot->waitForRunExit();
342 ArLog::log(ArLog::Normal,
"simpleMotionCommands: Exiting.");
346 std::cout <<
"Catch an exception: " <<
e << std::endl;
347#if defined(VISP_HAVE_DISPLAY) && (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
348 if (display !=
nullptr) {
Implementation of column vector and the associated operations.
static const vpColor blue
static const vpColor green
Class that defines generic functionalities for display.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition of the vpImage class member functions.
static double rad(double deg)
static double deg(double rad)
Interface for Pioneer mobile robots based on Aria 3rd party library.
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)