46#include <visp3/core/vpConfig.h>
48#if defined(VISP_HAVE_AFMA6) && defined(VISP_HAVE_REALSENSE2) && defined(VISP_HAVE_DISPLAY)
50#include <visp3/core/vpImage.h>
51#include <visp3/core/vpIoTools.h>
52#include <visp3/gui/vpDisplayFactory.h>
53#include <visp3/io/vpImageIo.h>
54#include <visp3/sensor/vpRealSense2.h>
55#include <visp3/blob/vpDot2.h>
56#include <visp3/robot/vpRobotAfma6.h>
57#include <visp3/vision/vpPose.h>
58#include <visp3/visual_features/vpFeatureBuilder.h>
59#include <visp3/visual_features/vpFeaturePoint.h>
60#include <visp3/vs/vpServo.h>
61#include <visp3/vs/vpServoDisplay.h>
69#ifdef ENABLE_VISP_NAMESPACE
75 std::string logdirname =
"/tmp/" + username;
83 std::cerr << std::endl <<
"ERROR:" << std::endl;
84 std::cerr <<
" Cannot create " << logdirname << std::endl;
93 config.enable_stream(RS2_STREAM_COLOR, width, height, RS2_FORMAT_RGBA8, fps);
94 config.enable_stream(RS2_STREAM_DEPTH, width, height, RS2_FORMAT_Z16, fps);
95 config.enable_stream(RS2_STREAM_INFRARED, width, height, RS2_FORMAT_Y8, fps);
100 for (
size_t i = 0;
i < 10; ++
i) {
109 std::cout <<
"-------------------------------------------------------" << std::endl;
110 std::cout <<
" Test program for vpServo " << std::endl;
111 std::cout <<
" Eye-to-hand task control" << std::endl;
112 std::cout <<
" Simulation " << std::endl;
113 std::cout <<
" task : servo a point " << std::endl;
114 std::cout <<
"-------------------------------------------------------" << std::endl;
121 for (
int i = 0;
i < nbPoint; ++
i) {
145 robot.getCameraParameters(cam, I);
150 for (
int i = 0;
i < nbPoint; ++
i) {
163 std::cout <<
"c_M_o: \n" << c_M_o << std::endl;
168 std::cout <<
"Learning (0/1)? " << std::endl;
169 std::string
filename =
"cd_M_o.dat";
171 std::cin >> learning;
174 std::cout <<
"Save the location of the object cMo in " <<
filename << std::endl;
175 c_M_o.
save(filename);
179 std::cout <<
"Loading desired location of the object cMo from " <<
filename << std::endl;
180 cd_M_o.
load(filename);
185 for (
int i = 0;
i < nbPoint; ++
i) {
202 for (
int i = 0;
i < nbPoint; ++
i) {
203 task.addFeature(s[i], s_d[i]);
209 double convergence_threshold = 0.00;
212 unsigned int iter = 0;
217 o_M_camrobot[0][3] = -0.05;
221 std::list<vpImagePoint> Lcog;
223 while ((error > convergence_threshold) && (!quit)) {
224 std::cout <<
"---------------------------------------------" <<
iter++ << std::endl;
230 for (
int i = 0;
i < nbPoint; ++
i) {
232 Lcog.push_back(dot[i].getCog());
236 std::cout <<
"Error detected while tracking visual features" << std::endl;
244 for (
int i = 0;
i < nbPoint; ++
i) {
267 robot.get_cMe(camrobot_M_e);
268 c_M_e = c_M_o * o_M_camrobot * camrobot_M_e;
274 robot.get_eJe(e_J_e);
280 task.setLambda(lambda_adaptive);
285 for (std::list<vpImagePoint>::const_iterator it_cog = Lcog.begin(); it_cog != Lcog.end(); ++it_cog) {
296 std::cout <<
"|| s - s* || = " <<
error << std::endl;
299 std::cout <<
"Error detected while tracking visual features" << std::endl;
304 if ((SAVE == 1) && (iter % 3 == 0)) {
322 std::cout <<
"Visual servo failed with exception: " <<
e << std::endl;
330 std::cout <<
"You do not have an afma6 robot connected to your computer..." << std::endl;
Adaptive gain computation.
void initStandard(double gain_at_zero, double gain_at_infinity, double slope_at_zero)
Generic class defining intrinsic camera parameters.
@ perspectiveProjWithoutDistortion
Perspective projection without distortion model.
Implementation of column vector and the associated operations.
static const vpColor blue
static const vpColor green
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
static void flush(const vpImage< unsigned char > &I)
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage.
void initTracking(const vpImage< unsigned char > &I)
void setGraphics(bool activate)
vpImagePoint getCog() const
void track(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
Implementation of an homogeneous matrix and operations on such kind of matrices.
void load(std::ifstream &f)
void save(std::ofstream &f) const
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
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.
Implementation of a matrix and operations on matrices.
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
void set_x(double x)
Set the point x coordinate in the image plane.
void projection(const vpColVector &_cP, vpColVector &_p) const VP_OVERRIDE
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, unsigned int thickness=1) VP_OVERRIDE
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const VP_OVERRIDE
void setWorldCoordinates(double oX, double oY, double oZ)
void set_y(double y)
Set the point y coordinate in the image plane.
Class used for pose computation from N points (pose from point only). Some of the algorithms implemen...
void addPoint(const vpPoint &P)
@ DEMENTHON_LAGRANGE_VIRTUAL_VS
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, FuncCheckValidityPose func=nullptr)
void acquire(vpImage< unsigned char > &grey, double *ts=nullptr)
bool open(const rs2::config &cfg=rs2::config())
Control of Irisa's gantry robot named Afma6.
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
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)
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.