ViSP  2.8.0
movePioneer.cpp
1 /****************************************************************************
2  *
3  * $Id: movePioneer.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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  std::cout << "\nWARNING: this program does no sensing or avoiding of obstacles, \n"
73  "the robot WILL collide with any objects in the way! Make sure 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 such as type and name,
83  // and then loads parameter files for this robot.
84  ArRobotConnector robotConnector(&parser, &robot);
85  if(!robotConnector.connectRobot())
86  {
87  ArLog::log(ArLog::Terse, "Could not connect to the robot.");
88  if(parser.checkHelpAndWarnUnparsed())
89  {
90  Aria::logOptions();
91  Aria::exit(1);
92  }
93  }
94  if (!Aria::parseArgs())
95  {
96  Aria::logOptions();
97  Aria::shutdown();
98  return false;
99  }
100 
101  std::cout << "Robot connected" << std::endl;
102  robot.useSonar(false); // disable the sonar device usage
103 
104  // Robot velocities
105  vpColVector v(2), v_mes(2);
106 
107  for (int i=0; i < 100; i++)
108  {
109  double t = vpTime::measureTimeMs();
110 
111  v = 0;
112  v[0] = i/1000.; // Translational velocity in m/s
113  //v[1] = vpMath::rad(i/5.); // Rotational velocity in rad/sec
115 
116  v_mes = robot.getVelocity(vpRobot::REFERENCE_FRAME);
117  std::cout << "Trans. vel= " << v_mes[0] << " m/s, Rot. vel=" << vpMath::deg(v_mes[1]) << " deg/s" << std::endl;
118  v_mes = robot.getVelocity(vpRobot::ARTICULAR_FRAME);
119  std::cout << "Left wheel vel= " << v_mes[0] << " m/s, Right wheel vel=" << v_mes[1] << " m/s" << std::endl;
120  std::cout << "Battery=" << robot.getBatteryVoltage() << std::endl;
121 
122  vpTime::wait(t, 40);
123  }
124 
125  ArLog::log(ArLog::Normal, "simpleMotionCommands: Stopping.");
126  robot.lock();
127  robot.stop();
128  robot.unlock();
129  ArUtil::sleep(1000);
130 
131  robot.lock();
132  ArLog::log(ArLog::Normal, "simpleMotionCommands: Pose=(%.2f,%.2f,%.2f), Trans. Vel=%.2f, Rot. Vel=%.2f, Battery=%.2fV",
133  robot.getX(), robot.getY(), robot.getTh(), robot.getVel(), robot.getRotVel(), robot.getBatteryVoltage());
134  robot.unlock();
135 
136  std::cout << "Ending robot thread..." << std::endl;
137  robot.stopRunning();
138 
139  // wait for the thread to stop
140  robot.waitForRunExit();
141 
142  // exit
143  ArLog::log(ArLog::Normal, "simpleMotionCommands: Exiting.");
144  return 0;
145 }
146 
147 #endif
148 
void useSonar(bool usage)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
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)