Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
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
47
BEGIN_VISP_NAMESPACE
51
vpRobotPioneer::vpRobotPioneer
() :
vpPioneer
(), ArRobot()
52
{
53
isInitialized
=
false
;
54
55
Aria::init();
56
}
57
61
vpRobotPioneer::~vpRobotPioneer
()
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
98
void
vpRobotPioneer::setVelocity
(
const
vpRobot::vpControlFrameType
frame,
const
vpColVector
&vel)
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
{
140
throw
vpRobotException
(
vpRobotException::wrongStateError
,
141
"Cannot send the robot velocity in the specified control frame"
);
142
}
143
}
144
153
void
vpRobotPioneer::init
()
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
188
void
vpRobotPioneer::getVelocity
(
const
vpRobot::vpControlFrameType
frame,
vpColVector
&velocity)
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
{
206
throw
vpRobotException
(
vpRobotException::wrongStateError
,
207
"Cannot get the robot volocity in the specified control frame"
);
208
}
209
}
210
231
vpColVector
vpRobotPioneer::getVelocity
(
const
vpRobot::vpControlFrameType
frame)
232
{
233
vpColVector
velocity;
234
getVelocity
(frame, velocity);
235
return
velocity;
236
}
237
END_VISP_NAMESPACE
238
#elif !defined(VISP_BUILD_SHARED_LIBS)
239
// Work around to avoid warning: libvisp_robot.a(vpRobotPioneer.cpp.o) has no symbols
240
void
dummy_vpRobotPioneer() { }
241
#endif
vpArray2D::size
unsigned int size() const
Return the number of elements of the 2D array.
Definition
vpArray2D.h:435
vpColVector
Implementation of column vector and the associated operations.
Definition
vpColVector.h:191
vpColVector::resize
void resize(unsigned int i, bool flagNullify=true)
Definition
vpColVector.h:1159
vpException::dimensionError
@ dimensionError
Bad dimension.
Definition
vpException.h:71
vpMath::rad
static double rad(double deg)
Definition
vpMath.h:129
vpMath::deg
static double deg(double rad)
Definition
vpMath.h:119
vpPioneer::vpPioneer
vpPioneer()
Definition
vpPioneer.h:92
vpRobotException
Error that can be emitted by the vpRobot class and its derivatives.
Definition
vpRobotException.h:54
vpRobotException::wrongStateError
@ wrongStateError
Wrong robot state.
Definition
vpRobotException.h:70
vpRobotPioneer::isInitialized
bool isInitialized
Definition
vpRobotPioneer.h:132
vpRobotPioneer::vpRobotPioneer
vpRobotPioneer()
Definition
vpRobotPioneer.cpp:51
vpRobotPioneer::~vpRobotPioneer
virtual ~vpRobotPioneer() VP_OVERRIDE
Definition
vpRobotPioneer.cpp:61
vpRobotPioneer::getVelocity
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
Definition
vpRobotPioneer.cpp:188
vpRobotPioneer::setVelocity
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
Definition
vpRobotPioneer.cpp:98
vpRobotPioneer::init
void init()
Definition
vpRobotPioneer.cpp:153
vpRobot::saturateVelocities
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition
vpRobot.cpp:162
vpRobot::vpControlFrameType
vpControlFrameType
Definition
vpRobot.h:74
vpRobot::REFERENCE_FRAME
@ REFERENCE_FRAME
Definition
vpRobot.h:75
vpRobot::ARTICULAR_FRAME
@ ARTICULAR_FRAME
Definition
vpRobot.h:77
vpRobot::getMaxRotationVelocity
double getMaxRotationVelocity(void) const
Definition
vpRobot.cpp:272
vpRobot::getMaxTranslationVelocity
double getMaxTranslationVelocity(void) const
Definition
vpRobot.cpp:250
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
robot
src
real-robot
pioneer
vpRobotPioneer.cpp
Generated by
1.17.0