Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
movePioneer.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Example that shows how to control a Pioneer mobile robot in ViSP.
32 */
33
34#include <iostream>
35
36#include <visp3/core/vpConfig.h>
37#include <visp3/core/vpTime.h>
38#include <visp3/robot/vpRobotPioneer.h>
39
40#ifndef VISP_HAVE_PIONEER
41int main()
42{
43 std::cout << "\nThis example requires Aria 3rd party library. You should "
44 "install it.\n"
45 << std::endl;
46 return EXIT_SUCCESS;
47}
48
49#else
50
63int main(int argc, char **argv)
64{
65#ifdef ENABLE_VISP_NAMESPACE
66 using namespace VISP_NAMESPACE_NAME;
67#endif
68
69 try {
70 std::cout << "\nWARNING: this program does no sensing or avoiding of "
71 "obstacles, \n"
72 "the robot WILL collide with any objects in the way! Make sure "
73 "the \n"
74 "robot has approximately 3 meters of free space on all sides.\n"
75 << std::endl;
76
77 vpRobotPioneer robot;
78
79 ArArgumentParser parser(&argc, argv);
80 parser.loadDefaultArguments();
81
82 // ArRobotConnector connects to the robot, get some initial data from it
83 // such as type and name, and then loads parameter files for this robot.
84 ArRobotConnector robotConnector(&parser, &robot);
85 if (!robotConnector.connectRobot()) {
86 ArLog::log(ArLog::Terse, "Could not connect to the robot.");
87 if (parser.checkHelpAndWarnUnparsed()) {
88 Aria::logOptions();
89 Aria::exit(1);
90 }
91 }
92 if (!Aria::parseArgs()) {
93 Aria::logOptions();
94 Aria::shutdown();
95 return false;
96 }
97
98 std::cout << "Robot connected" << std::endl;
99 robot.useSonar(false); // disable the sonar device usage
100
101 // Robot velocities
102 vpColVector v(2), v_mes(2);
103
104 for (int i = 0; i < 100; i++) {
105 double t = vpTime::measureTimeMs();
106
107 v = 0;
108 v[0] = i / 1000.; // Translational velocity in m/s
109 // v[1] = vpMath::rad(i/5.); // Rotational velocity in rad/sec
110 robot.setVelocity(vpRobot::REFERENCE_FRAME, v);
111
112 v_mes = robot.getVelocity(vpRobot::REFERENCE_FRAME);
113 std::cout << "Trans. vel= " << v_mes[0] << " m/s, Rot. vel=" << vpMath::deg(v_mes[1]) << " deg/s" << std::endl;
114 v_mes = robot.getVelocity(vpRobot::ARTICULAR_FRAME);
115 std::cout << "Left wheel vel= " << v_mes[0] << " m/s, Right wheel vel=" << v_mes[1] << " m/s" << std::endl;
116 std::cout << "Battery=" << robot.getBatteryVoltage() << std::endl;
117
118 vpTime::wait(t, 40);
119 }
120
121 ArLog::log(ArLog::Normal, "simpleMotionCommands: Stopping.");
122 robot.lock();
123 robot.stop();
124 robot.unlock();
125 ArUtil::sleep(1000);
126
127 robot.lock();
128 ArLog::log(ArLog::Normal,
129 "simpleMotionCommands: Pose=(%.2f,%.2f,%.2f), Trans. "
130 "Vel=%.2f, Rot. Vel=%.2f, Battery=%.2fV",
131 robot.getX(), robot.getY(), robot.getTh(), robot.getVel(), robot.getRotVel(), robot.getBatteryVoltage());
132 robot.unlock();
133
134 std::cout << "Ending robot thread..." << std::endl;
135 robot.stopRunning();
136
137 // wait for the thread to stop
138 robot.waitForRunExit();
139
140 // exit
141 ArLog::log(ArLog::Normal, "simpleMotionCommands: Exiting.");
142 return EXIT_SUCCESS;
143 }
144 catch (const vpException &e) {
145 std::cout << "Catch an exception: " << e << std::endl;
146 return EXIT_FAILURE;
147 }
148}
149
150#endif
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:60
static double deg(double rad)
Definition vpMath.h:119
Interface for Pioneer mobile robots based on Aria 3rd party library.
@ REFERENCE_FRAME
Definition vpRobot.h:75
@ ARTICULAR_FRAME
Definition vpRobot.h:77
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)