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