Visual Servoing Platform  version 3.0.0
vpRobotPioneer.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Interface for Pioneer robots based on Aria 3rd party library.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
38 #include <visp3/core/vpConfig.h>
39 #include <visp3/robot/vpRobotException.h>
40 #include <visp3/robot/vpRobotPioneer.h>
41 // Warning: vpMath.h should be included after Aria.h to avoid the build issue:
42 // "/usr/include/Aria/ariaUtil.h:732:21: error: ‘isfinite’ was not declared
43 // in this scope"
44 // This error is due to cmath header included from vpMath.h that makes
45 // isfinite() ambiguous between ::isfinite() and std::isfinite()
46 #include <visp3/core/vpMath.h>
47 
48 #ifdef VISP_HAVE_PIONEER
49 
54 {
55  isInitialized = false;
56 
57  Aria::init();
58 }
59 
64 {
65 #if 0
66  std::cout << "Ending robot thread..." << std::endl;
67  stopRunning();
68 
69  // wait for the thread to stop
70  waitForRunExit();
71 #endif
72 }
73 
96 {
97  init();
98 
99  /*
100  if (vpRobot::STATE_VELOCITY_CONTROL != getRobotState ()) {
101  vpERROR_TRACE ("Cannot send a velocity to the robot "
102  "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
103  throw vpRobotException (vpRobotException::wrongStateError,
104  "Cannot send a velocity to the robot "
105  "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
106  } */
107 
108  if (vel.size() != 2)
109  {
110  throw(vpRobotException(vpRobotException::dimensionError, "Velocity vector is not a 2 dimension vector"));
111  }
112 
113  vpColVector vel_max(2);
114  vpColVector vel_sat;
115 
116  if (frame == vpRobot::REFERENCE_FRAME)
117  {
118  vel_max[0] = getMaxTranslationVelocity();
119  vel_max[1] = getMaxRotationVelocity();
120 
121  vel_sat = vpRobot::saturateVelocities(vel, vel_max, true);
122  this->lock();
123  this->setVel(vel_sat[0]*1000.); // convert velocity in mm/s
124  this->setRotVel( vpMath::deg(vel_sat[1]) ); // convert velocity in deg/s
125  this->unlock();
126  }
127  else if (frame == vpRobot::ARTICULAR_FRAME)
128  {
129  vel_max[0] = getMaxTranslationVelocity();
130  vel_max[1] = getMaxTranslationVelocity();
131 
132  vel_sat = vpRobot::saturateVelocities(vel, vel_max, true);
133  this->lock();
134  //std::cout << "v: " << (vel*1000).t() << " mm/s" << std::endl;
135  this->setVel2(vel_sat[0]*1000., vel_sat[1]*1000.); // convert velocity in mm/s
136  this->unlock();
137  }
138  else
139  {
141  "Cannot send the robot velocity in the specified control frame");
142  }
143 }
144 
153 {
154  if ( ! isInitialized )
155  {
156  // Start the robot processing cycle running in the background.
157  // True parameter means that if the connection is lost, then the
158  // run loop ends.
159  this->runAsync(true);
160  this->lock();
161  this->enableMotors();
162  this->unlock();
163 
164  isInitialized = true;
165  }
166 }
167 
187 {
188  init();
189  velocity.resize(2);
190 
191  if (frame == vpRobot::ARTICULAR_FRAME)
192  {
193  this->lock();
194  velocity[0] = this->getLeftVel() / 1000.;
195  velocity[1] = this->getRightVel() / 1000;
196  this->unlock();
197  }
198  else if (frame == vpRobot::REFERENCE_FRAME)
199  {
200  this->lock();
201  velocity[0] = this->getVel() / 1000.;
202  velocity[1] = vpMath::rad( this->getRotVel() );
203  this->unlock();
204  }
205  else {
207  "Cannot get the robot volocity in the specified control frame");
208  }
209 }
210 
230 {
231  vpColVector velocity;
232  getVelocity(frame, velocity);
233  return velocity;
234 }
235 
236 #elif !defined(VISP_BUILD_SHARED_LIBS)
237 // Work arround to avoid warning: libvisp_robot.a(vpRobotPioneer.cpp.o) has no symbols
238 void dummy_vpRobotPioneer() {};
239 #endif
Error that can be emited by the vpRobot class and its derivates.
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
double getMaxTranslationVelocity(void) const
Definition: vpRobot.cpp:250
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition: vpRobot.cpp:163
vpControlFrameType
Definition: vpRobot.h:76
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:156
double getMaxRotationVelocity(void) const
Definition: vpRobot.cpp:275
virtual ~vpRobotPioneer()
Generic functions for Pioneer mobile robots.
Definition: vpPioneer.h:90
static double rad(double deg)
Definition: vpMath.h:104
static double deg(double rad)
Definition: vpMath.h:97
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:217