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