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