ViSP  2.9.0
testTwistMatrix.cpp
1 /****************************************************************************
2  *
3  * $Id: testTwistMatrix.cpp 4658 2014-02-09 09:50:14Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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 some vpMatrix functionalities.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 
50 #include <visp/vpConfig.h>
51 #include <visp/vpDebug.h>
52 
53 #include <stdlib.h>
54 #include <stdio.h>
55 
56 #include <visp/vpMath.h>
57 #include <visp/vpMatrix.h>
58 #include <visp/vpColVector.h>
59 #include <visp/vpRxyzVector.h>
60 #include <visp/vpTranslationVector.h>
61 #include <visp/vpRotationMatrix.h>
62 #include <visp/vpVelocityTwistMatrix.h>
63 #include <visp/vpParseArgv.h>
64 
65 // List of allowed command line options
66 #define GETOPTARGS "h"
67 void usage(const char *name, const char *badparam);
68 bool getOptions(int argc, const char **argv);
69 
75 void usage(const char *name, const char *badparam)
76 {
77  fprintf(stdout, "\n\
78 Tests some vpMatrix functionalities.\n\
79 \n\
80 SYNOPSIS\n\
81  %s [-h]\n", name);
82 
83  fprintf(stdout, "\n\
84 OPTIONS: Default\n\
85  -h\n\
86  Print the help.\n");
87 
88  if (badparam)
89  fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
90 }
98 bool getOptions(int argc, const char **argv)
99 {
100  const char *optarg_;
101  int c;
102  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
103 
104  switch (c) {
105  case 'h': usage(argv[0], NULL); return false; break;
106 
107  default:
108  usage(argv[0], optarg_);
109  return false; break;
110  }
111  }
112 
113  if ((c == 1) || (c == -1)) {
114  // standalone param or error
115  usage(argv[0], NULL);
116  std::cerr << "ERROR: " << std::endl;
117  std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
118  return false;
119  }
120 
121  return true;
122 }
123 
124 
125 int
126 main(int argc, const char ** argv)
127 {
128  try {
129  // Read the command line options
130  if (getOptions(argc, argv) == false) {
131  exit (-1);
132  }
133 
134  vpTRACE("--------------------------");
135  vpTRACE("--- TEST vpVelocityTwistMatrix ---");
136  vpTRACE("--------------------------");
137 
138  // Set the translation
140  cte[0] = 1.;
141  cte[1] = 0.5;
142  cte[2] = -1.;
143 
144  // Set the rotation
145  vpRxyzVector cre;
146  cre[0] = M_PI/2.;
147  cre[1] = -M_PI/2.;
148  cre[2] = -M_PI/4.;
149 
150  // Build rotation matrix
151  vpRotationMatrix cRe(cre);
152 
153  // Build the twist matrix
154  vpVelocityTwistMatrix cVe(cte, cRe);
155 
156  vpTRACE("cVe twist matrix:");
157  cVe.print (std::cout, 6);
158 
159 
160  // Set a speed skew
161  vpColVector ev(6);
162 
163  ev[0] = 1.;
164  ev[1] = 0.1;
165  ev[2] = -0.5;
166  ev[3] = M_PI/180.;
167  ev[4] = M_PI/18.;
168  ev[5] = M_PI/10.;
169 
170  vpTRACE("ev colvector:");
171  ev.print (std::cout, 6);
172 
173  // Set a speed skew
174  vpColVector cv;
175 
176  cv = cVe * ev;
177 
178  vpTRACE("cv = cVe * ev:");
179  cv.print (std::cout, 6);
180  return 0;
181  }
182  catch(vpException e) {
183  std::cout << "Catch an exception: " << e << std::endl;
184  return 1;
185  }
186 }
#define vpTRACE
Definition: vpDebug.h:418
error that can be emited by ViSP classes.
Definition: vpException.h:76
int print(std::ostream &s, unsigned int length, char const *intro=0)
Definition: vpMatrix.cpp:2668
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:79
The vpRotationMatrix considers the particular case of a rotation matrix.
Class that consider the particular case of twist transformation matrix that allows to transform a vel...
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
Class that consider the case of the Euler angle using the x-y-z convention, where are respectively ...
Definition: vpRxyzVector.h:152
Class that consider the case of a translation vector.