Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
servoPtu46Point2DArtVelocity.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See https://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * tests the control law
33 * eye-in-hand control
34 * velocity computed in articular
35 *
36*****************************************************************************/
37
57#include <visp3/core/vpConfig.h>
58#include <visp3/core/vpDebug.h> // Debug trace
59#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
60#include <unistd.h>
61#endif
62#include <signal.h>
63
64#if (defined(VISP_HAVE_PTU46) & defined(VISP_HAVE_DC1394))
65
66#ifdef VISP_HAVE_PTHREAD
67#include <pthread.h>
68#endif
69
70#include <visp3/core/vpDisplay.h>
71#include <visp3/core/vpImage.h>
72#include <visp3/gui/vpDisplayX.h>
73#include <visp3/sensor/vp1394TwoGrabber.h>
74
75#include <visp3/core/vpHomogeneousMatrix.h>
76#include <visp3/core/vpMath.h>
77#include <visp3/core/vpPoint.h>
78#include <visp3/visual_features/vpFeatureBuilder.h>
79#include <visp3/visual_features/vpFeaturePoint.h>
80#include <visp3/vs/vpServo.h>
81
82#include <visp3/robot/vpRobotPtu46.h>
83
84// Exception
85#include <visp3/core/vpException.h>
86#include <visp3/vs/vpServoDisplay.h>
87
88#include <visp3/blob/vpDot2.h>
89
90#ifdef VISP_HAVE_PTHREAD
91pthread_mutex_t mutexEndLoop = PTHREAD_MUTEX_INITIALIZER;
92#endif
93
94void signalCtrC(int signumber)
95{
96 (void)(signumber);
97#ifdef VISP_HAVE_PTHREAD
98 pthread_mutex_unlock(&mutexEndLoop);
99#endif
100 usleep(1000 * 10);
101 vpTRACE("Ctrl-C pressed...");
102}
103
104int main()
105{
106 std::cout << std::endl;
107 std::cout << "-------------------------------------------------------" << std::endl;
108 std::cout << " Test program for vpServo " << std::endl;
109 std::cout << " Eye-in-hand task control, velocity computed in the camera frame" << std::endl;
110 std::cout << " Simulation " << std::endl;
111 std::cout << " task : servo a point " << std::endl;
112 std::cout << "-------------------------------------------------------" << std::endl;
113 std::cout << std::endl;
114
115 try {
116
117#ifdef VISP_HAVE_PTHREAD
118 pthread_mutex_lock(&mutexEndLoop);
119#endif
120 signal(SIGINT, &signalCtrC);
121
122 vpRobotPtu46 robot;
123 {
124 vpColVector q(2);
125 q = 0;
127 robot.setPosition(vpRobot::ARTICULAR_FRAME, q);
128 }
129
131
133
134 g.open(I);
135
136 try {
137 g.acquire(I);
138 } catch (...) {
139 vpERROR_TRACE(" Error caught");
140 return EXIT_FAILURE;
141 }
142
143 vpDisplayX display(I, 100, 100, "testDisplayX.cpp ");
144 vpTRACE(" ");
145
146 try {
149 } catch (...) {
150 vpERROR_TRACE(" Error caught");
151 return EXIT_FAILURE;
152 }
153
154 vpServo task;
155
156 vpDot2 dot;
157
158 try {
159 vpERROR_TRACE("start dot.initTracking(I) ");
160 vpImagePoint germ;
161 vpDisplay::getClick(I, germ);
162 dot.setCog(germ);
163 vpDEBUG_TRACE(25, "Click!");
164 // dot.initTracking(I) ;
165 dot.track(I);
166 vpERROR_TRACE("after dot.initTracking(I) ");
167 } catch (...) {
168 vpERROR_TRACE(" Error caught ");
169 return EXIT_FAILURE;
170 }
171
173
174 vpTRACE("sets the current position of the visual feature ");
176 vpFeatureBuilder::create(p, cam, dot); // retrieve x,y and Z of the vpPoint structure
177
178 p.set_Z(1);
179 vpTRACE("sets the desired position of the visual feature ");
181 pd.buildFrom(0, 0, 1);
182
183 vpTRACE("define the task");
184 vpTRACE("\t we want an eye-in-hand control law");
185 vpTRACE("\t articular velocity are computed");
188
189 vpTRACE("Set the position of the end-effector frame in the camera frame");
191 // robot.get_cMe(cMe) ;
192
194 robot.get_cVe(cVe);
195 std::cout << cVe << std::endl;
196 task.set_cVe(cVe);
197
199 vpTRACE("Set the Jacobian (expressed in the end-effector frame)");
200 vpMatrix eJe;
201 robot.get_eJe(eJe);
202 task.set_eJe(eJe);
203
204 vpTRACE("\t we want to see a point on a point..");
205 std::cout << std::endl;
206 task.addFeature(p, pd);
207
208 vpTRACE("\t set the gain");
209 task.setLambda(0.1);
210
211 vpTRACE("Display task information ");
212 task.print();
213
215
216 unsigned int iter = 0;
217 vpTRACE("\t loop");
218#ifdef VISP_HAVE_PTHREAD
219 while (0 != pthread_mutex_trylock(&mutexEndLoop))
220#else
221 for (;;)
222#endif
223 {
224 std::cout << "---------------------------------------------" << iter << std::endl;
225
226 g.acquire(I);
228
229 dot.track(I);
230
231 vpFeatureBuilder::create(p, cam, dot);
232
233 // get the jacobian
234 robot.get_eJe(eJe);
235 task.set_eJe(eJe);
236
237 // std::cout << (vpMatrix)cVe*eJe << std::endl ;
238
239 vpColVector v;
240 v = task.computeControlLaw();
241
242 vpServoDisplay::display(task, cam, I);
243 std::cout << v.t();
246
247 vpTRACE("\t\t || s - s* || = %f ", (task.getError()).sumSquare());
248 }
249
250 vpTRACE("Display task information ");
251 task.print();
252 } catch (const vpException &e) {
253 std::cout << "Sorry PtU46 not available. Got exception: " << e << std::endl;
254 return EXIT_FAILURE
255 }
256 return EXIT_SUCCESS;
257}
258
259#else
260int main() { std::cout << "You do not have an PTU46 PT robot connected to your computer..." << std::endl; }
261#endif
Class for firewire ieee1394 video devices using libdc1394-2.x api.
void acquire(vpImage< unsigned char > &I)
void open(vpImage< unsigned char > &I)
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
vpRowVector t() const
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition vpDisplayX.h:132
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition vpDot2.h:124
void track(const vpImage< unsigned char > &I, bool canMakeTheWindowGrow=true)
Definition vpDot2.cpp:441
void setCog(const vpImagePoint &ip)
Definition vpDot2.h:257
error that can be emitted by ViSP classes.
Definition vpException.h:59
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
void buildFrom(double x, double y, double Z)
void set_Z(double Z)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
Definition vpImage.h:135
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:152
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
void get_eJe(vpMatrix &eJe)
Interface for the Directed Perception ptu-46 pan, tilt head .
@ ARTICULAR_FRAME
Definition vpRobot.h:76
@ STATE_POSITION_CONTROL
Initialize the position controller.
Definition vpRobot.h:65
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
Definition vpRobot.h:64
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition vpRobot.cpp:198
static void display(const vpServo &s, const vpCameraParameters &cam, const vpImage< unsigned char > &I, vpColor currentColor=vpColor::green, vpColor desiredColor=vpColor::red, unsigned int thickness=1)
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Definition vpServo.cpp:564
@ EYEINHAND_L_cVe_eJe
Definition vpServo.h:155
void set_cVe(const vpVelocityTwistMatrix &cVe_)
Definition vpServo.h:448
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
Definition vpServo.cpp:299
void setLambda(double c)
Definition vpServo.h:403
void set_eJe(const vpMatrix &eJe_)
Definition vpServo.h:506
void setServo(const vpServoType &servo_type)
Definition vpServo.cpp:210
vpColVector getError() const
Definition vpServo.h:276
@ PSEUDO_INVERSE
Definition vpServo.h:199
vpColVector computeControlLaw()
Definition vpServo.cpp:930
@ DESIRED
Definition vpServo.h:183
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
Definition vpServo.cpp:487
vpVelocityTwistMatrix get_cVe() const
Definition vpUnicycle.h:79
#define vpTRACE
Definition vpDebug.h:411
#define vpDEBUG_TRACE
Definition vpDebug.h:482
#define vpERROR_TRACE
Definition vpDebug.h:388