ViSP
Main Page
Related Pages
Modules
Classes
Examples
All
Classes
Functions
Variables
Enumerations
Enumerator
Friends
Groups
Pages
servoAfma6Point2DCamVelocity.cpp
1
/****************************************************************************
2
*
3
* $Id: servoAfma6Point2DCamVelocity.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
* tests the control law
36
* eye-in-hand control
37
* velocity computed in the camera frame
38
*
39
* Authors:
40
* Eric Marchand
41
* Fabien Spindler
42
*
43
*****************************************************************************/
44
68
#include <visp/vpConfig.h>
69
#include <visp/vpDebug.h>
// Debug trace
70
#include <stdlib.h>
71
#if (defined (VISP_HAVE_AFMA6) && defined (VISP_HAVE_DC1394_2))
72
73
#include <visp/vp1394TwoGrabber.h>
74
#include <visp/vpImage.h>
75
#include <visp/vpImagePoint.h>
76
#include <visp/vpMath.h>
77
#include <visp/vpHomogeneousMatrix.h>
78
#include <visp/vpFeaturePoint.h>
79
#include <visp/vpPoint.h>
80
#include <visp/vpServo.h>
81
#include <visp/vpFeatureBuilder.h>
82
#include <visp/vpRobotAfma6.h>
83
#include <visp/vpIoTools.h>
84
#include <visp/vpException.h>
85
#include <visp/vpMatrixException.h>
86
#include <visp/vpServoDisplay.h>
87
#include <visp/vpDot.h>
88
#include <visp/vpDisplay.h>
89
#include <visp/vpDisplayX.h>
90
#include <visp/vpDisplayOpenCV.h>
91
#include <visp/vpDisplayGTK.h>
92
93
int
94
main()
95
{
96
// Log file creation in /tmp/$USERNAME/log.dat
97
// This file contains by line:
98
// - the 6 computed cam velocities (m/s, rad/s) to achieve the task
99
// - the 6 mesured joint velocities (m/s, rad/s)
100
// - the 6 mesured joint positions (m, rad)
101
// - the 2 values of s - s*
102
std::string username;
103
// Get the user login name
104
vpIoTools::getUserName
(username);
105
106
// Create a log filename to save velocities...
107
std::string logdirname;
108
logdirname =
"/tmp/"
+ username;
109
110
// Test if the output path exist. If no try to create it
111
if
(
vpIoTools::checkDirectory
(logdirname) ==
false
) {
112
try
{
113
// Create the dirname
114
vpIoTools::makeDirectory
(logdirname);
115
}
116
catch
(...) {
117
std::cerr << std::endl
118
<<
"ERROR:"
<< std::endl;
119
std::cerr <<
" Cannot create "
<< logdirname << std::endl;
120
exit(-1);
121
}
122
}
123
std::string logfilename;
124
logfilename = logdirname +
"/log.dat"
;
125
126
// Open the log file name
127
std::ofstream flog(logfilename.c_str());
128
129
try
130
{
131
vpServo
task ;
132
133
vpImage<unsigned char>
I ;
134
135
vp1394TwoGrabber
g;
136
g.
setVideoMode
(
vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8
);
137
g.
setFramerate
(
vp1394TwoGrabber::vpFRAMERATE_60
);
138
g.
open
(I) ;
139
140
g.
acquire
(I) ;
141
142
#ifdef VISP_HAVE_X11
143
vpDisplayX
display(I,100,100,
"Current image"
) ;
144
#elif defined(VISP_HAVE_OPENCV)
145
vpDisplayOpenCV
display(I,100,100,
"Current image"
) ;
146
#elif defined(VISP_HAVE_GTK)
147
vpDisplayGTK
display(I,100,100,
"Current image"
) ;
148
#endif
149
150
vpDisplay::display
(I) ;
151
vpDisplay::flush
(I) ;
152
153
vpDot
dot ;
154
vpImagePoint
cog;
155
156
std::cout <<
"Click on a dot..."
<< std::endl;
157
dot.
initTracking
(I) ;
158
cog = dot.
getCog
();
159
vpDisplay::displayCross
(I, cog, 10,
vpColor::blue
) ;
160
vpDisplay::flush
(I);
161
162
vpRobotAfma6
robot ;
163
164
vpCameraParameters
cam ;
165
// Update camera parameters
166
robot.
getCameraParameters
(cam, I);
167
168
// sets the current position of the visual feature
169
vpFeaturePoint
p ;
170
// retrieve x,y and Z of the vpPoint structure
171
vpFeatureBuilder::create
(p,cam, dot);
172
173
// sets the desired position of the visual feature
174
vpFeaturePoint
pd ;
175
pd.
buildFrom
(0,0,1) ;
176
177
// define the task
178
// - we want an eye-in-hand control law
179
// - robot is controlled in the camera frame
180
task.
setServo
(
vpServo::EYEINHAND_CAMERA
) ;
181
182
// - we want to see a point on a point
183
task.
addFeature
(p,pd) ;
184
185
// - set the constant gain
186
task.
setLambda
(0.8) ;
187
188
// Display task information
189
task.
print
() ;
190
191
// Now the robot will be controlled in velocity
192
robot.
setRobotState
(
vpRobot::STATE_VELOCITY_CONTROL
) ;
193
194
std::cout <<
"\nHit CTRL-C to stop the loop...\n"
<< std::flush;
195
for
( ; ; ) {
196
// Acquire a new image from the camera
197
g.
acquire
(I) ;
198
199
// Display this image
200
vpDisplay::display
(I) ;
201
202
// Achieve the tracking of the dot in the image
203
dot.
track
(I) ;
204
205
// Get the dot cog
206
cog = dot.
getCog
();
207
208
// Display a green cross at the center of gravity position in the image
209
vpDisplay::displayCross
(I, cog, 10,
vpColor::green
) ;
210
211
// Update the point feature from the dot location
212
vpFeatureBuilder::create
(p, cam, dot);
213
214
vpColVector
v ;
215
// Compute the visual servoing skew vector
216
v = task.
computeControlLaw
() ;
217
218
// Display the current and desired feature points in the image display
219
vpServoDisplay::display
(task, cam, I) ;
220
221
// Apply the computed joint velocities to the robot
222
robot.
setVelocity
(
vpRobot::CAMERA_FRAME
, v) ;
223
224
// Save velocities applied to the robot in the log file
225
// v[0], v[1], v[2] correspond to camera translation velocities in m/s
226
// v[3], v[4], v[5] correspond to camera rotation velocities in rad/s
227
flog << v[0] <<
" "
<< v[1] <<
" "
<< v[2] <<
" "
228
<< v[3] <<
" "
<< v[4] <<
" "
<< v[5] <<
" "
;
229
230
// Get the measured joint velocities of the robot
231
vpColVector
qvel;
232
robot.
getVelocity
(
vpRobot::ARTICULAR_FRAME
, qvel);
233
// Save measured joint velocities of the robot in the log file:
234
// - qvel[0], qvel[1], qvel[2] correspond to measured joint translation
235
// velocities in m/s
236
// - qvel[3], qvel[4], qvel[5] correspond to measured joint rotation
237
// velocities in rad/s
238
flog << qvel[0] <<
" "
<< qvel[1] <<
" "
<< qvel[2] <<
" "
239
<< qvel[3] <<
" "
<< qvel[4] <<
" "
<< qvel[5] <<
" "
;
240
241
// Get the measured joint positions of the robot
242
vpColVector
q;
243
robot.
getPosition
(
vpRobot::ARTICULAR_FRAME
, q);
244
// Save measured joint positions of the robot in the log file
245
// - q[0], q[1], q[2] correspond to measured joint translation
246
// positions in m
247
// - q[3], q[4], q[5] correspond to measured joint rotation
248
// positions in rad
249
flog << q[0] <<
" "
<< q[1] <<
" "
<< q[2] <<
" "
250
<< q[3] <<
" "
<< q[4] <<
" "
<< q[5] <<
" "
;
251
252
// Save feature error (s-s*) for the feature point. For this feature
253
// point, we have 2 errors (along x and y axis). This error is expressed
254
// in meters in the camera frame
255
flog << ( task.
getError
() ).t() << std::endl;
256
257
// Flush the display
258
vpDisplay::flush
(I) ;
259
260
}
261
262
flog.close() ;
// Close the log file
263
264
// Display task information
265
task.
print
() ;
266
267
// Kill the task
268
task.
kill
();
269
270
return
0;
271
}
272
catch
(...)
273
{
274
flog.close() ;
// Close the log file
275
vpERROR_TRACE
(
" Test failed"
) ;
276
return
0;
277
}
278
}
279
280
281
#else
282
int
283
main()
284
{
285
vpERROR_TRACE
(
"You do not have an afma6 robot or a firewire framegrabber connected to your computer..."
);
286
}
287
#endif
example
servo-afma6
servoAfma6Point2DCamVelocity.cpp
Generated on Thu Oct 24 2013 14:47:35 for ViSP by
1.8.4