Visual Servoing Platform  version 3.0.0
moveAfma4.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Test for Afma 4 dof robot.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
54 #include <visp3/core/vpConfig.h>
55 #include <visp3/core/vpDebug.h>
56 
57 #ifdef VISP_HAVE_AFMA4
58 
59 #include <unistd.h>
60 #include <stdlib.h>
61 
62 #include <visp3/io/vpParseArgv.h>
63 #include <visp3/robot/vpRobotAfma4.h>
64 
65 // List of allowed command line options
66 #define GETOPTARGS "mh"
67 
76 void usage(const char *name, const char *badparam)
77 {
78  fprintf(stdout, "\n\
79 Example of a positionning control followed by a velocity control \n\
80 of the Afma4 robot.\n \
81 \n\
82 SYNOPSIS\n\
83  %s [-m] [-h]\n \
84 ", name);
85 
86  fprintf(stdout, "\n\
87 OPTIONS: Default\n\
88  -m\n\
89  Turn off the control of the robot. This option is\n\
90  essentially useful for security reasons during nightly\n\
91  tests.\n\
92 \n\
93  -h\n\
94  Print the help.\n\n");
95 
96  if (badparam) {
97  fprintf(stderr, "ERROR: \n" );
98  fprintf(stderr, "\nBad parameter [%s]\n", badparam);
99  }
100 
101 }
102 
114 bool getOptions(int argc, const char **argv, bool &control)
115 {
116  const char *optarg;
117  int c;
118  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg)) > 1) {
119 
120  switch (c) {
121  case 'm': control = false; break;
122  case 'h': usage(argv[0], NULL); return false; break;
123 
124  default:
125  usage(argv[0], optarg); return false; break;
126  }
127  }
128 
129  if ((c == 1) || (c == -1)) {
130  // standalone param or error
131  usage(argv[0], NULL);
132  std::cerr << "ERROR: " << std::endl;
133  std::cerr << " Bad argument " << optarg << std::endl << std::endl;
134  return false;
135  }
136 
137  return true;
138 }
139 
140 int
141 main(int argc, const char ** argv)
142 {
143  try
144  {
145  bool control = true; // Turn on the robot control by applying positions
146  // and velocities to the robot.
147  // Read the command line options
148  if (getOptions(argc, argv, control) == false) {
149  exit (-1);
150  }
151 
152  vpRobotAfma4 robot ;
153 
154  vpColVector qd(robot.njoint) ;
155  vpColVector q(robot.njoint) ;
156 
157  //
158  // Position control in articular
159  //
160  qd[0] = vpMath::rad(10);
161  qd[1] = -0.1;
162  qd[2] = vpMath::rad(20);
163  qd[3] = vpMath::rad(-10);
164 
165  std::cout << "Position control: in articular..." << std::endl;
166  std::cout << " position to reach: " << qd.t() << std::endl;
168  if (control)
170  sleep(1) ;
171 
172 
174  std::cout << " measured position: " << q.t() ;
175  sleep(1) ;
176 
178 
179  //
180  // Velocity control in articular
181  //
182  std::cout << "Velocity control: in articular..." << std::endl;
183 
184  q = 0 ;
185  q[0] = vpMath::rad(2) ; // rotation arround vertical axis
186  std::cout << " rotation arround vertical axis: " << q[0] << std::endl;
187  if (control)
189  sleep(5) ;
190 
191  q = 0 ;
192  q[1] = 0.2 ; // Vertical translation
193  std::cout << " vertical translation: " << q[1] << std::endl;
194  if (control)
196  sleep(5) ;
197 
198  q = 0 ;
199  q[1] = -0.2 ; // Vertical translation
200  std::cout << " vertical translation: " << q[1] << std::endl;
201  if (control)
203  sleep(5) ;
204  q = 0 ;
205  q[2] = vpMath::rad(3) ; // pan
206  std::cout << " pan rotation: " << q[2] << std::endl;
207  if (control)
209  sleep(5) ;
210 
211  q = 0 ;
212  q[3] = vpMath::rad(2) ; // tilt
213  std::cout << " tilt rotation: " << q[3] << std::endl;
214  if (control)
216  sleep(5) ;
217 
218  //
219  // Velocity control in camera frame
220  //
222  std::cout << "Velocity control: in camera frame..." << std::endl;
223  q.resize(2) ;
224  q = 0.0;
225  q[0] = vpMath::rad(2) ; // rotation arround vertical axis
226  std::cout << " rx rotation: " << q[0] << std::endl;
227  if (control)
229  sleep(5) ;
230 
231  q.resize(2) ;
232  q = 0.0;
233  q[1] = vpMath::rad(2) ; // rotation arround vertical axis
234  std::cout << " ry rotation: " << q[1] << std::endl;
235  if (control)
237  sleep(5) ;
238 
239  std::cout << "The end" << std::endl;
240  return 0;
241  }
242  catch(vpException e) {
243  std::cout << "Catch a ViSP exception: " << e << std::endl;
244  return 1;
245  }
246 }
247 #else
248 int
249 main()
250 {
251  vpERROR_TRACE("You do not have an afma4 robot connected to your computer...");
252  return 0;
253 }
254 
255 #endif
#define vpERROR_TRACE
Definition: vpDebug.h:391
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity)
Initialize the position controller.
Definition: vpRobot.h:69
error that can be emited by ViSP classes.
Definition: vpException.h:73
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:76
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position)
Initialize the velocity controller.
Definition: vpRobot.h:68
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)
static const unsigned int njoint
Number of joint.
Definition: vpAfma4.h:138
static double rad(double deg)
Definition: vpMath.h:104
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
Control of Irisa's cylindrical robot named Afma4.
Definition: vpRobotAfma4.h:177