ViSP  2.6.2
servoSimuThetaUCamVelocity.cpp
1 /****************************************************************************
2  *
3  * $Id: servoSimuThetaUCamVelocity.cpp 2457 2010-01-07 10:41:18Z nmelchio $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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  * Simulation of a visual servoing using theta U visual features.
36  * tests the control law
37  * eye-in-hand control
38  * velocity computed in the camera frame
39  * using theta U visual feature
40  *
41  * Authors:
42  * Eric Marchand
43  * Fabien Spindler
44  *
45  *****************************************************************************/
46 
47 
65 #include <visp/vpMath.h>
66 #include <visp/vpHomogeneousMatrix.h>
67 #include <visp/vpFeatureThetaU.h>
68 #include <visp/vpFeatureTranslation.h>
69 #include <visp/vpServo.h>
70 #include <visp/vpRobotCamera.h>
71 #include <visp/vpDebug.h>
72 #include <visp/vpParseArgv.h>
73 
74 
75 #include <stdlib.h>
76 #include <stdio.h>
77 // List of allowed command line options
78 #define GETOPTARGS "h"
79 
88 void usage(const char *name, const char *badparam)
89 {
90  fprintf(stdout, "\n\
91 Simulation of avisual servoing using theta U visual feature:\n\
92 - eye-in-hand control law,\n\
93 - velocity computed in the camera frame,\n\
94 - without display.\n\
95  \n\
96 SYNOPSIS\n\
97  %s [-h]\n", name);
98 
99  fprintf(stdout, "\n\
100 OPTIONS: Default\n\
101  \n\
102  -h\n\
103  Print the help.\n");
104 
105  if (badparam)
106  fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
107 }
108 
119 bool getOptions(int argc, const char **argv)
120 {
121  const char *optarg;
122  int c;
123  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg)) > 1) {
124 
125  switch (c) {
126  case 'h': usage(argv[0], NULL); return false; break;
127 
128  default:
129  usage(argv[0], optarg);
130  return false; break;
131  }
132  }
133 
134  if ((c == 1) || (c == -1)) {
135  // standalone param or error
136  usage(argv[0], NULL);
137  std::cerr << "ERROR: " << std::endl;
138  std::cerr << " Bad argument " << optarg << std::endl << std::endl;
139  return false;
140  }
141 
142  return true;
143 }
144 
145 int
146 main(int argc, const char ** argv)
147 {
148  // Read the command line options
149  if (getOptions(argc, argv) == false) {
150  exit (-1);
151  }
152 
153  vpServo task ;
154  vpRobotCamera robot ;
155 
156  std::cout << std::endl ;
157  std::cout << "-------------------------------------------------------" << std::endl ;
158  std::cout << " Test program for vpServo " <<std::endl ;
159  std::cout << " Eye-in-hand task control, velocity computed in the camera frame" << std::endl ;
160  std::cout << " Simulation " << std::endl ;
161  std::cout << " task : servo using theta U visual feature " << std::endl ;
162  std::cout << "-------------------------------------------------------" << std::endl ;
163  std::cout << std::endl ;
164 
165 
166  vpTRACE("sets the initial camera location " ) ;
167  vpPoseVector c_r_o(0.1,0.2,2,
168  vpMath::rad(20), vpMath::rad(10), vpMath::rad(50)
169  ) ;
170 
171  vpCTRACE ; std::cout << std::endl ;
172  vpHomogeneousMatrix cMo(c_r_o) ;
173  vpCTRACE ; std::cout << std::endl ;
174  robot.setPosition(cMo) ;
175  vpCTRACE ; std::cout << std::endl ;
176 
177  vpTRACE("sets the desired camera location " ) ;
178  vpPoseVector cd_r_o(0,0,1,
180  vpHomogeneousMatrix cdMo(cd_r_o) ;
181 
182 
183  vpTRACE("compute the rotation that the camera has to realize " ) ;
184  vpHomogeneousMatrix cdMc ;
185  cdMc = cdMo*cMo.inverse() ;
187  tu.buildFrom(cdMc) ;
188 
189 
190  vpTRACE("define the task") ;
191  vpTRACE("\t we want an eye-in-hand control law") ;
192  vpTRACE("\t robot is controlled in the camera frame") ;
195 
196  task.addFeature(tu) ;
197 
198  vpTRACE("\t set the gain") ;
199  task.setLambda(1) ;
200 
201 
202  vpTRACE("Display task information " ) ;
203  task.print() ;
204 
205  unsigned int iter=0 ;
206  vpTRACE("\t loop") ;
207  while(iter++ < 200)
208  {
209  std::cout << "---------------------------------------------" << iter <<std::endl ;
210  vpColVector v ;
211 
212  if (iter==1) vpTRACE("\t\t get the robot position ") ;
213  robot.getPosition(cMo) ;
214 
215  if (iter==1) vpTRACE("\t\t new rotation to realize ") ;
216  cdMc = cdMo*cMo.inverse() ;
217  tu.buildFrom(cdMc) ;
218 
219 
220  if (iter==1) vpTRACE("\t\t compute the control law ") ;
221  v = task.computeControlLaw() ;
222  if (iter==1) task.print() ;
223 
224  if (iter==1) vpTRACE("\t\t send the camera velocity to the controller ") ;
226 
227 
228  std::cout << ( task.getError() ).sumSquare() <<std::endl ; ;
229  }
230 
231  vpTRACE("Display task information " ) ;
232  task.print() ;
233  task.kill();
234 }
235 
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
#define vpTRACE
Definition: vpDebug.h:401
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, const unsigned int select=vpBasicFeature::FEATURE_ALL)
create a new ste of two visual features
Definition: vpServo.cpp:444
void setLambda(double _lambda)
set the gain lambda
Definition: vpServo.h:250
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:79
#define vpCTRACE
Definition: vpDebug.h:327
void kill()
destruction (memory deallocation if required)
Definition: vpServo.cpp:177
vpColVector getError() const
Definition: vpServo.h:298
vpColVector computeControlLaw()
compute the desired control law
Definition: vpServo.cpp:883
Class that defines the simplest robot: a free flying camera.
Definition: vpRobotCamera.h:65
void getPosition(vpColVector &q)
void setPosition(const vpRobot::vpControlFrameType, const vpColVector &)
Set a displacement (frame has to be specified) in position control.
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
Construction from translation vector and rotation matrix.
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Set the type of the interaction matrix (current, mean, desired, user).
Definition: vpServo.cpp:509
static double rad(double deg)
Definition: vpMath.h:100
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
The pose is a complete representation of every rigid motion in the euclidian space.
Definition: vpPoseVector.h:92
vpHomogeneousMatrix inverse() const
Class that defines a 3D visual feature from a axis/angle parametrization that represent the rotatio...
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
Definition: vpServo.cpp:258
Class required to compute the visual servoing control law.
Definition: vpServo.h:150
void setServo(vpServoType _servo_type)
Choice of the visual servoing control law.
Definition: vpServo.cpp:214