48#include <visp3/core/vpConfig.h>
50#if defined(VISP_HAVE_AFMA6) && defined(VISP_HAVE_REALSENSE2) && defined(VISP_HAVE_DISPLAY)
52#include <visp3/core/vpImage.h>
53#include <visp3/core/vpIoTools.h>
54#include <visp3/gui/vpDisplayFactory.h>
55#include <visp3/sensor/vpRealSense2.h>
56#include <visp3/blob/vpDot2.h>
57#include <visp3/robot/vpRobotAfma6.h>
58#include <visp3/vision/vpPose.h>
59#include <visp3/visual_features/vpFeatureBuilder.h>
60#include <visp3/visual_features/vpFeaturePoint.h>
61#include <visp3/vs/vpServo.h>
62#include <visp3/vs/vpServoDisplay.h>
68#ifdef ENABLE_VISP_NAMESPACE
85void compute_pose(std::vector<vpPoint> &point,
const std::vector<vpDot2> &dot,
const vpCameraParameters &cam,
92 for (
size_t i = 0;
i < point.size(); ++
i) {
94 cog = dot[
i].getCog();
124 std::string logdirname =
"/tmp/" + username;
133 std::cerr << std::endl <<
"ERROR:" << std::endl;
134 std::cerr <<
" Cannot create " << logdirname << std::endl;
138 std::string logfilename = logdirname +
"/log.dat";
141 std::ofstream flog(logfilename.c_str());
147 config.enable_stream(RS2_STREAM_COLOR, width, height, RS2_FORMAT_RGBA8, fps);
148 config.enable_stream(RS2_STREAM_DEPTH, width, height, RS2_FORMAT_Z16, fps);
149 config.enable_stream(RS2_STREAM_INFRARED, width, height, RS2_FORMAT_Y8, fps);
155 for (
size_t i = 0;
i < 10; ++
i) {
164 std::cout <<
"-------------------------------------------------------" << std::endl;
165 std::cout <<
" Test program for vpServo " << std::endl;
166 std::cout <<
" Eye-in-hand task control, velocity computed in the camera frame" << std::endl;
167 std::cout <<
" Use of the Afma6 robot " << std::endl;
168 std::cout <<
" Interaction matrix computed with the current features " << std::endl;
169 std::cout <<
" task : servo 4 points on a square with dimension " << L <<
" meters" << std::endl;
170 std::cout <<
"-------------------------------------------------------" << std::endl;
172 std::vector<vpDot2> dot(4);
174 std::cout <<
"Click on the 4 dots clockwise starting from upper/left dot..." << std::endl;
175 for (
size_t i = 0;
i < dot.size(); ++
i) {
176 dot[
i].initTracking(I);
191 robot.getCameraParameters(cam, I);
194 std::vector<vpFeaturePoint>
s(4);
195 for (
size_t i = 0;
i <
s.size(); ++
i) {
201 std::vector<vpPoint> point(4);
202 point[0].setWorldCoordinates(-L, -L, 0);
203 point[1].setWorldCoordinates(+L, -L, 0);
204 point[2].setWorldCoordinates(+L, +L, 0);
205 point[3].setWorldCoordinates(-L, +L, 0);
215 std::vector<vpFeaturePoint> s_d(4);
217 for (
size_t i = 0;
i < s_d.size(); ++
i) {
219 point[
i].changeFrame(c_M_o, cP);
220 point[
i].projection(cP, p);
236 for (
size_t i = 0;
i <
s.size(); ++
i) {
237 task.addFeature(s[i], s_d[i]);
249 std::cout <<
"\nHit CTRL-C to stop the loop...\n" << std::flush;
251 bool init_pose_from_linear_method =
true;
262 for (
size_t i = 0;
i < dot.size(); ++
i) {
269 compute_pose(point, dot, cam, c_M_o, init_pose_from_linear_method);
270 if (init_pose_from_linear_method) {
271 init_pose_from_linear_method =
false;
274 for (
size_t i = 0;
i < dot.size(); ++
i) {
279 point[
i].changeFrame(c_M_o, cP);
296 flog <<
v[0] <<
" " <<
v[1] <<
" " <<
v[2] <<
" " <<
v[3] <<
" " <<
v[4] <<
" " <<
v[5] <<
" ";
306 flog << qvel[0] <<
" " << qvel[1] <<
" " << qvel[2] <<
" " << qvel[3] <<
" " << qvel[4] <<
" " << qvel[5] <<
" ";
316 flog << q[0] <<
" " << q[1] <<
" " << q[2] <<
" " << q[3] <<
" " << q[4] <<
" " << q[5] <<
" ";
321 flog << (
task.getError()).
t() <<
" ";
325 flog << c_t_o[0] <<
" " << c_t_o[1] <<
" " << c_t_o[2] <<
" "
326 << c_r_o[0] <<
" " << c_r_o[1] <<
" " << c_r_o[2] << std::endl;
349 std::cout <<
"Visual servo failed with exception: " <<
e << std::endl;
357 std::cout <<
"You do not have an afma6 robot connected to your computer..." << std::endl;
Generic class defining intrinsic camera parameters.
vpCameraParametersProjType
@ perspectiveProjWithDistortion
Perspective projection with distortion model.
Implementation of column vector and the associated operations.
static const vpColor blue
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
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.
static double rad(double deg)
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
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.
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as Euler angle minimal representation.
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)
Class that consider the case of a translation vector.
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.