ViSP  2.8.0
moveAfma4.cpp
1 /****************************************************************************
2  *
3  * $Id: moveAfma4.cpp 4086 2013-02-02 07:26:19Z 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  * Test for Afma 4 dof robot.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
58 #include <visp/vpConfig.h>
59 #include <visp/vpDebug.h>
60 
61 #ifdef VISP_HAVE_AFMA4
62 
63 #include <unistd.h>
64 #include <stdlib.h>
65 
66 #include <visp/vpParseArgv.h>
67 #include <visp/vpRobotAfma4.h>
68 
69 // List of allowed command line options
70 #define GETOPTARGS "mh"
71 
80 void usage(const char *name, const char *badparam)
81 {
82  fprintf(stdout, "\n\
83 Example of a positionning control followed by a velocity control \n\
84 of the Afma4 robot.\n \
85 \n\
86 SYNOPSIS\n\
87  %s [-m] [-h]\n \
88 ", name);
89 
90  fprintf(stdout, "\n\
91 OPTIONS: Default\n\
92  -m\n\
93  Turn off the control of the robot. This option is\n\
94  essentially useful for security reasons during nightly\n\
95  tests.\n\
96 \n\
97  -h\n\
98  Print the help.\n\n");
99 
100  if (badparam) {
101  fprintf(stderr, "ERROR: \n" );
102  fprintf(stderr, "\nBad parameter [%s]\n", badparam);
103  }
104 
105 }
106 
118 bool getOptions(int argc, const char **argv, bool &control)
119 {
120  const char *optarg;
121  int c;
122  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg)) > 1) {
123 
124  switch (c) {
125  case 'm': control = false; break;
126  case 'h': usage(argv[0], NULL); return false; break;
127 
128  default:
129  usage(argv[0], optarg); return false; break;
130  }
131  }
132 
133  if ((c == 1) || (c == -1)) {
134  // standalone param or error
135  usage(argv[0], NULL);
136  std::cerr << "ERROR: " << std::endl;
137  std::cerr << " Bad argument " << optarg << std::endl << std::endl;
138  return false;
139  }
140 
141  return true;
142 }
143 
144 int
145 main(int argc, const char ** argv)
146 {
147  try
148  {
149  bool control = true; // Turn on the robot control by applying positions
150  // and velocities to the robot.
151  // Read the command line options
152  if (getOptions(argc, argv, control) == false) {
153  exit (-1);
154  }
155 
156  vpRobotAfma4 robot ;
157 
158  vpColVector qd(robot.njoint) ;
159  vpColVector q(robot.njoint) ;
160 
161  //
162  // Position control in articular
163  //
164  qd[0] = vpMath::rad(10);
165  qd[1] = -0.1;
166  qd[2] = vpMath::rad(20);
167  qd[3] = vpMath::rad(-10);
168 
169  std::cout << "Position control: in articular..." << std::endl;
170  std::cout << " position to reach: " << qd.t() << std::endl;
172  if (control)
174  sleep(1) ;
175 
176 
178  std::cout << " measured position: " << q.t() ;
179  sleep(1) ;
180 
182 
183  //
184  // Velocity control in articular
185  //
186  std::cout << "Velocity control: in articular..." << std::endl;
187 
188  q = 0 ;
189  q[0] = vpMath::rad(2) ; // rotation arround vertical axis
190  std::cout << " rotation arround vertical axis: " << q[0] << std::endl;
191  if (control)
193  sleep(5) ;
194 
195  q = 0 ;
196  q[1] = 0.2 ; // Vertical translation
197  std::cout << " vertical translation: " << q[1] << std::endl;
198  if (control)
200  sleep(5) ;
201 
202  q = 0 ;
203  q[1] = -0.2 ; // Vertical translation
204  std::cout << " vertical translation: " << q[1] << std::endl;
205  if (control)
207  sleep(5) ;
208  q = 0 ;
209  q[2] = vpMath::rad(3) ; // pan
210  std::cout << " pan rotation: " << q[2] << std::endl;
211  if (control)
213  sleep(5) ;
214 
215  q = 0 ;
216  q[3] = vpMath::rad(2) ; // tilt
217  std::cout << " tilt rotation: " << q[3] << std::endl;
218  if (control)
220  sleep(5) ;
221 
222  //
223  // Velocity control in camera frame
224  //
226  std::cout << "Velocity control: in camera frame..." << std::endl;
227  q.resize(2) ;
228  q = 0.0;
229  q[0] = vpMath::rad(2) ; // rotation arround vertical axis
230  std::cout << " rx rotation: " << q[0] << std::endl;
231  if (control)
233  sleep(5) ;
234 
235  q.resize(2) ;
236  q = 0.0;
237  q[1] = vpMath::rad(2) ; // rotation arround vertical axis
238  std::cout << " ry rotation: " << q[1] << std::endl;
239  if (control)
241  sleep(5) ;
242 
243  std::cout << "The end" << std::endl;
244  }
245  catch (...) {
246  vpERROR_TRACE(" Test failed") ;
247  }
248  return 0;
249 }
250 #else
251 int
252 main()
253 {
254  vpERROR_TRACE("You do not have an afma4 robot connected to your computer...");
255  return 0;
256 }
257 
258 #endif
#define vpERROR_TRACE
Definition: vpDebug.h:379
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity)
Initialize the position controller.
Definition: vpRobot.h:71
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:79
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position)
Initialize the velocity controller.
Definition: vpRobot.h:70
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)
static const unsigned int njoint
Number of joint.
Definition: vpAfma4.h:141
static double rad(double deg)
Definition: vpMath.h:100
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
Control of Irisa's cylindrical robot named Afma4.
Definition: vpRobotAfma4.h:181