ViSP
Main Page
Related Pages
Modules
Classes
Examples
All
Classes
Functions
Variables
Enumerations
Enumerator
Friends
Groups
Pages
manServo4PointsDisplay.cpp
1
/****************************************************************************
2
*
3
* $Id: manServo4PointsDisplay.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
* Description:
34
* Simulation of a visual servoing with display.
35
*
36
* Authors:
37
* Eric Marchand
38
* Fabien Spindler
39
*
40
*****************************************************************************/
41
52
#include <visp/vpConfig.h>
53
#include <visp/vpDebug.h>
54
55
#ifdef VISP_HAVE_GTK
56
57
#include <visp/vpImage.h>
58
#include <visp/vpCameraParameters.h>
59
#include <visp/vpTime.h>
60
#include <visp/vpImage.h>
61
#include <visp/vpImageConvert.h>
62
#include <visp/vpDisplayGTK.h>
63
64
#include <visp/vpMath.h>
65
#include <visp/vpHomogeneousMatrix.h>
66
#include <visp/vpPose.h>
67
#include <visp/vpFeaturePoint.h>
68
#include <visp/vpServo.h>
69
#include <visp/vpServoDisplay.h>
70
#include <visp/vpRobotCamera.h>
71
#include <visp/vpFeatureBuilder.h>
72
#include <visp/vpIoTools.h>
73
74
int
main()
75
{
77
// sets the initial camera location
78
vpHomogeneousMatrix
cMo(0.3,0.2,3,
79
vpMath::rad
(0),
vpMath::rad
(0),
vpMath::rad
(40)) ;
80
82
// initialize the robot
83
vpRobotCamera
robot ;
84
robot.
setSamplingTime
(0.04);
// 40ms
85
robot.
setPosition
(cMo) ;
86
87
//initialize the camera parameters
88
vpCameraParameters
cam(800,800,240,180);
89
90
//Image definition
91
unsigned
int
height = 360 ;
92
unsigned
int
width = 480 ;
93
vpImage<unsigned char>
I(height,width);
94
95
//Display initialization
96
vpDisplayGTK
disp;
97
disp.
init
(I,100,100,
"Simulation display"
);
98
100
// Desired visual features initialization
101
102
// sets the points coordinates in the object frame (in meter)
103
vpPoint
point[4] ;
104
point[0].
setWorldCoordinates
(-0.1,-0.1,0) ;
105
point[1].
setWorldCoordinates
(0.1,-0.1,0) ;
106
point[2].
setWorldCoordinates
(0.1,0.1,0) ;
107
point[3].
setWorldCoordinates
(-0.1,0.1,0) ;
108
109
// sets the desired camera location
110
vpHomogeneousMatrix
cMo_d(0,0,1,0,0,0) ;
111
112
// computes the 3D point coordinates in the camera frame and its 2D coordinates
113
for
(
int
i = 0 ; i < 4 ; i++)
114
point[i].project(cMo_d) ;
115
116
// creates the associated features
117
vpFeaturePoint
pd[4] ;
118
for
(
int
i = 0 ; i < 4 ; i++)
119
vpFeatureBuilder::create
(pd[i],point[i]) ;
120
121
123
// Current visual features initialization
124
125
// computes the 3D point coordinates in the camera frame and its 2D coordinates
126
for
(
int
i = 0 ; i < 4 ; i++)
127
point[i].project(cMo) ;
128
129
// creates the associated features
130
vpFeaturePoint
p[4] ;
131
for
(
int
i = 0 ; i < 4 ; i++)
132
vpFeatureBuilder::create
(p[i],point[i]) ;
133
134
136
// Task defintion
137
vpServo
task ;
138
// we want an eye-in-hand control law ;
139
task.
setServo
(
vpServo::EYEINHAND_L_cVe_eJe
) ;
140
task.
setInteractionMatrixType
(
vpServo::DESIRED
,
vpServo::PSEUDO_INVERSE
) ;
141
142
// Set the position of the camera in the end-effector frame
143
vpHomogeneousMatrix
cMe ;
144
vpVelocityTwistMatrix
cVe(cMe) ;
145
task.
set_cVe
(cVe) ;
146
// Set the Jacobian (expressed in the end-effector frame)
147
vpMatrix
eJe ;
148
robot.
get_eJe
(eJe) ;
149
task.
set_eJe
(eJe) ;
150
151
// we want to see a point on a point
152
for
(
int
i = 0 ; i < 4 ; i++)
153
task.
addFeature
(p[i],pd[i]) ;
154
// Set the gain
155
task.
setLambda
(1.0) ;
156
// Print the current information about the task
157
task.
print
();
158
159
161
// The control loop
162
int
k = 0;
163
while
(k++ < 200){
164
double
t =
vpTime::measureTimeMs
();
165
166
// Display the image background
167
vpDisplay::display
(I);
168
169
// Update the current features
170
for
(
int
i = 0 ; i < 4 ; i++)
171
{
172
point[i].
project
(cMo) ;
173
vpFeatureBuilder::create
(p[i],point[i]) ;
174
}
175
176
// Display the task features (current and desired)
177
vpServoDisplay::display
(task,cam,I);
178
vpDisplay::flush
(I);
179
180
// Update the robot Jacobian
181
robot.
get_eJe
(eJe) ;
182
task.
set_eJe
(eJe) ;
183
184
// Compute the control law
185
vpColVector
v = task.
computeControlLaw
() ;
186
187
// Send the computed velocity to the robot and compute the new robot position
188
robot.
setVelocity
(
vpRobot::ARTICULAR_FRAME
, v) ;
189
robot.
getPosition
(cMo) ;
190
191
// Print the current information about the task
192
task.
print
();
193
194
// Wait 40 ms
195
vpTime::wait
(t,40);
196
}
197
task.
kill
();
198
return
0;
199
}
200
201
#else
202
int
203
main()
204
{
vpTRACE
(
"You should install GTK"
) ;
205
206
}
207
#endif
example
manual
simulation
manServo4PointsDisplay.cpp
Generated on Tue Sep 17 2013 00:21:34 for ViSP by
1.8.4