48 #include <visp3/core/vpConfig.h>
50 #if defined(VISP_HAVE_REALSENSE2) && defined(VISP_HAVE_AFMA6)
52 #include <visp3/core/vpImage.h>
53 #include <visp3/gui/vpDisplayGTK.h>
54 #include <visp3/gui/vpDisplayOpenCV.h>
55 #include <visp3/gui/vpDisplayX.h>
56 #include <visp3/io/vpImageIo.h>
57 #include <visp3/sensor/vpRealSense2.h>
58 #include <visp3/core/vpCylinder.h>
59 #include <visp3/core/vpHomogeneousMatrix.h>
60 #include <visp3/core/vpMath.h>
61 #include <visp3/me/vpMeLine.h>
62 #include <visp3/visual_features/vpFeatureBuilder.h>
63 #include <visp3/visual_features/vpFeatureLine.h>
64 #include <visp3/robot/vpRobotAfma6.h>
65 #include <visp3/vs/vpServoDisplay.h>
66 #include <visp3/vs/vpServo.h>
68 #ifdef ENABLE_VISP_NAMESPACE
80 int main(
int argc,
char **argv)
82 bool opt_verbose =
false;
83 bool opt_adaptive_gain =
false;
85 for (
int i = 1; i < argc; ++i) {
86 if (std::string(argv[i]) ==
"--verbose") {
89 else if (std::string(argv[i]) ==
"--adaptive-gain") {
90 opt_adaptive_gain =
true;
92 else if ((std::string(argv[i]) ==
"--help") || (std::string(argv[i]) ==
"-h")) {
95 <<
" [--adaptive-gain]"
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;
118 unsigned int width = 640, height = 480, fps = 60;
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) {
131 vpDisplayX display(I, 100, 100,
"Current image");
132 #elif defined(HAVE_OPENCV_HIGHGUI)
134 #elif defined(VISP_HAVE_GTK)
141 std::vector<vpMeLine> line(nblines);
151 for (
int i = 0; i < nblines; ++i) {
155 line[i].initTracking(I);
162 robot.getCameraParameters(cam, I);
163 std::cout <<
"cam:\n" << cam << std::endl;
166 std::vector<vpFeatureLine> s_line(nblines);
167 for (
int i = 0; i < nblines; ++i) {
176 cylinder.project(c_M_o);
178 std::vector<vpFeatureLine> s_line_d(nblines);
189 s_line_d[0].setRhoTheta(+fabs(s_line_d[0].getRho()), 0);
190 s_line_d[1].setRhoTheta(+fabs(s_line_d[1].getRho()), M_PI);
204 for (
int i = 0; i < nblines; ++i) {
209 if (opt_adaptive_gain) {
222 bool final_quit =
false;
223 bool send_velocities =
false;
225 while (!final_quit) {
231 std::stringstream ss;
232 ss <<
"Left click to " << (send_velocities ?
"stop the robot" :
"servo the robot") <<
", right click to quit.";
236 for (
int i = 0; i < nblines; ++i) {
250 std::cout <<
"v: " << v_c.
t() << std::endl;
251 std::cout <<
"\t\t || s - s* || = " << task.
getError().
sumSquare() << std::endl;;
254 if (!send_velocities) {
269 send_velocities = !send_velocities;
282 std::cout <<
"Stop the robot " << std::endl;
286 while (!final_quit) {
303 std::cout <<
"ViSP exception: " << e.
what() << std::endl;
304 std::cout <<
"Stop the robot " << std::endl;
315 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...
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
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.
const char * what() const
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpImagePoint &t)
Implementation of an homogeneous matrix and operations on such kind of matrices.
static double rad(double deg)
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.
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
@ STATE_STOP
Stops robot motion especially in velocity and acceleration control.
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
void addFeature(vpBasicFeature &s_cur, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
void setServo(const vpServoType &servo_type)
vpColVector getError() const
vpColVector computeControlLaw()
VISP_EXPORT double measureTimeMs()