52#include <visp3/core/vpConfig.h>
54#if defined(VISP_HAVE_REALSENSE2) && defined(VISP_HAVE_AFMA6)
56#include <visp3/core/vpImage.h>
57#include <visp3/gui/vpDisplayFactory.h>
58#include <visp3/io/vpImageIo.h>
59#include <visp3/sensor/vpRealSense2.h>
60#include <visp3/core/vpCylinder.h>
61#include <visp3/core/vpHomogeneousMatrix.h>
62#include <visp3/core/vpMath.h>
63#include <visp3/me/vpMeLine.h>
64#include <visp3/visual_features/vpFeatureBuilder.h>
65#include <visp3/visual_features/vpFeatureLine.h>
66#include <visp3/robot/vpRobotAfma6.h>
67#include <visp3/vs/vpServoDisplay.h>
68#include <visp3/vs/vpServo.h>
70#ifdef ENABLE_VISP_NAMESPACE
74int main(
int argc,
char **argv)
76 bool opt_verbose =
false;
77 bool opt_adaptive_gain =
false;
79 for (
int i = 1;
i < argc; ++
i) {
80 if (std::string(argv[i]) ==
"--verbose") {
83 else if (std::string(argv[i]) ==
"--adaptive-gain") {
84 opt_adaptive_gain =
true;
86 else if ((std::string(argv[i]) ==
"--help") || (std::string(argv[i]) ==
"-h")) {
89 <<
" [--adaptive-gain]"
104#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
105 std::shared_ptr<vpDisplay> display;
111 std::cout <<
"WARNING: This example will move the robot! "
112 <<
"Please make sure to have the user stop button at hand!" << std::endl
113 <<
"Press Enter to continue..." << std::endl;
119 config.enable_stream(RS2_STREAM_COLOR, width, height, RS2_FORMAT_RGBA8, fps);
120 config.enable_stream(RS2_STREAM_DEPTH, width, height, RS2_FORMAT_Z16, fps);
121 config.enable_stream(RS2_STREAM_INFRARED, width, height, RS2_FORMAT_Y8, fps);
126 for (
size_t i = 0;
i < 10; ++
i) {
130#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
139 std::vector<vpMeLine> line(nblines);
149 for (
int i = 0;
i < nblines; ++
i) {
153 line[
i].initTracking(I);
160 robot.getCameraParameters(cam, I);
161 std::cout <<
"cam:\n" <<
cam << std::endl;
164 std::vector<vpFeatureLine> s_line(nblines);
165 for (
int i = 0;
i < nblines; ++
i) {
174 cylinder.project(c_M_o);
176 std::vector<vpFeatureLine> s_line_d(nblines);
181 std::cout <<
"Desired features: " << std::endl;
182 std::cout <<
" - line 1: rho: " << s_line_d[0].getRho() <<
" theta: " <<
vpMath::deg(s_line_d[0].getTheta()) <<
"deg" << std::endl;
183 std::cout <<
" - line 2: rho: " << s_line_d[1].getRho() <<
" theta: " <<
vpMath::deg(s_line_d[1].getTheta()) <<
"deg" << std::endl;
193 s_line_d[0].setRhoTheta(+fabs(s_line_d[0].getRho()), 0);
194 s_line_d[1].setRhoTheta(+fabs(s_line_d[1].getRho()), M_PI);
208 for (
int i = 0;
i < nblines; ++
i) {
209 task.addFeature(s_line[i], s_line_d[i]);
213 if (opt_adaptive_gain) {
215 task.setLambda(lambda);
226 bool final_quit =
false;
227 bool send_velocities =
false;
228 double task_error = 1.;
231 while ((task_error > 0.00001) && (!final_quit)) {
237 std::stringstream ss;
238 ss <<
"Left click to " << (send_velocities ?
"stop the robot" :
"servo the robot") <<
", right click to quit.";
242 for (
int i = 0;
i < nblines; ++
i) {
253 v_c =
task.computeControlLaw();
254 task_error =
task.getError().sumSquare();
257 std::cout <<
"v: " << v_c.t() << std::endl;
258 std::cout <<
"\t\t || s - s* || = " << task_error << std::endl;
261 if (!send_velocities) {
278 send_velocities = !send_velocities;
295 unsigned long iter = 0;
296 double secondary_task_speed = 0.02;
297 unsigned int tempo = 1200;
299 while (!final_quit) {
305 std::stringstream ss;
306 ss <<
"Left click to " << (send_velocities ?
"stop the robot" :
"servo the robot") <<
", right click to quit.";
310 for (
int i = 0;
i < nblines; ++
i) {
321 v_c =
task.computeControlLaw();
324 if (iter % tempo < 400 /*&& iter%tempo >= 0*/) {
326 e1[0] = fabs(secondary_task_speed);
327 proj_e1 =
task.secondaryTask(e1);
328 double frac = secondary_task_speed / proj_e1[0];
335 if (iter % tempo < 600 && iter % tempo >= 400) {
337 e2[1] = fabs(secondary_task_speed);
338 proj_e2 =
task.secondaryTask(e2);
339 double frac = secondary_task_speed / proj_e2[1];
344 if (iter % tempo < 1000 && iter % tempo >= 600) {
346 e1[0] = -fabs(secondary_task_speed);
347 proj_e1 =
task.secondaryTask(e1);
348 double frac = -secondary_task_speed / proj_e1[0];
353 if (iter % tempo < 1200 && iter % tempo >= 1000) {
355 e2[1] = -fabs(secondary_task_speed);
356 proj_e2 =
task.secondaryTask(e2);
357 double frac = -secondary_task_speed / proj_e2[1];
378 std::cout <<
"Stop the robot " << std::endl;
382 while (!final_quit) {
399 std::cout <<
"ViSP exception: " <<
e.what() << std::endl;
400 std::cout <<
"Stop the robot " << std::endl;
402#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
403 if (display !=
nullptr) {
410#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
411 if (display !=
nullptr) {
421 std::cout <<
"You do not have an afma6 robot connected to your computer..." << std::endl;
Adaptive gain computation.
Generic class defining intrinsic camera parameters.
vpCameraParametersProjType
@ perspectiveProjWithDistortion
Perspective projection with distortion model.
Implementation of column vector and the associated operations.
static const vpColor green
Class that defines a 3D cylinder in the object frame and allows forward projection of a 3D cylinder i...
Class that defines generic functionalities for display.
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)
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.
Definition of the vpImage class member functions.
static double rad(double deg)
static double deg(double rad)
void setPointsToTrack(const int &points_to_track)
void setRange(const unsigned int &range)
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
void setThreshold(const double &threshold)
void setSampleStep(const double &sample_step)
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.
@ STATE_STOP
Stops robot motion especially in velocity and acceleration control.
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT double measureTimeMs()