Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpRobotPioneer.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 * Interface for Pioneer robots based on Aria 3rd party library.
32 */
33
34#include <visp3/core/vpConfig.h>
35#include <visp3/robot/vpRobotException.h>
36#include <visp3/robot/vpRobotPioneer.h>
37// Warning: vpMath.h should be included after Aria.h to avoid the build issue:
38// "/usr/include/Aria/ariaUtil.h:732:21: error: ‘isfinite’ was not declared
39// in this scope"
40// This error is due to cmath header included from vpMath.h that makes
41// isfinite() ambiguous between ::isfinite() and std::isfinite()
42#include <visp3/core/vpMath.h>
43#include <visp3/core/vpDebug.h>
44
45#ifdef VISP_HAVE_PIONEER
46
52{
53 isInitialized = false;
54
55 Aria::init();
56}
57
62{
63#if 0
64 std::cout << "Ending robot thread..." << std::endl;
65 stopRunning();
66
67 // wait for the thread to stop
68 waitForRunExit();
69#endif
70}
71
99{
100 init();
101
102 /*
103 if (vpRobot::STATE_VELOCITY_CONTROL != getRobotState ()) {
104 vpERROR_TRACE ("Cannot send a velocity to the robot "
105 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
106 throw vpRobotException (vpRobotException::wrongStateError,
107 "Cannot send a velocity to the robot "
108 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
109 } */
110
111 if (vel.size() != 2) {
112 throw(vpRobotException(vpRobotException::dimensionError, "Velocity vector is not a 2 dimension vector"));
113 }
114
115 vpColVector vel_max(2);
116 vpColVector vel_sat;
117
118 if (frame == vpRobot::REFERENCE_FRAME) {
119 vel_max[0] = getMaxTranslationVelocity();
120 vel_max[1] = getMaxRotationVelocity();
121
122 vel_sat = vpRobot::saturateVelocities(vel, vel_max, true);
123 this->lock();
124 this->setVel(vel_sat[0] * 1000.); // convert velocity in mm/s
125 this->setRotVel(vpMath::deg(vel_sat[1])); // convert velocity in deg/s
126 this->unlock();
127 }
128 else if (frame == vpRobot::ARTICULAR_FRAME) {
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.,
136 vel_sat[1] * 1000.); // convert velocity in mm/s
137 this->unlock();
138 }
139 else {
141 "Cannot send the robot velocity in the specified control frame");
142 }
143}
144
154{
155 if (!isInitialized) {
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
189{
190 init();
191 velocity.resize(2);
192
193 if (frame == vpRobot::ARTICULAR_FRAME) {
194 this->lock();
195 velocity[0] = this->getLeftVel() / 1000.;
196 velocity[1] = this->getRightVel() / 1000;
197 this->unlock();
198 }
199 else if (frame == vpRobot::REFERENCE_FRAME) {
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
232{
233 vpColVector velocity;
234 getVelocity(frame, velocity);
235 return velocity;
236}
237END_VISP_NAMESPACE
238#elif !defined(VISP_BUILD_SHARED_LIBS)
239// Work around to avoid warning: libvisp_robot.a(vpRobotPioneer.cpp.o) has no symbols
240void dummy_vpRobotPioneer() { }
241#endif
unsigned int size() const
Return the number of elements of the 2D array.
Definition vpArray2D.h:435
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
@ dimensionError
Bad dimension.
Definition vpException.h:71
static double rad(double deg)
Definition vpMath.h:129
static double deg(double rad)
Definition vpMath.h:119
Error that can be emitted by the vpRobot class and its derivatives.
@ wrongStateError
Wrong robot state.
virtual ~vpRobotPioneer() VP_OVERRIDE
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition vpRobot.cpp:162
vpControlFrameType
Definition vpRobot.h:74
@ REFERENCE_FRAME
Definition vpRobot.h:75
@ ARTICULAR_FRAME
Definition vpRobot.h:77
double getMaxRotationVelocity(void) const
Definition vpRobot.cpp:272
double getMaxTranslationVelocity(void) const
Definition vpRobot.cpp:250