Visual Servoing Platform  version 3.3.0
tutorial-ibvs-4pts-plotter-continuous-gain-adaptive.cpp
#include <visp3/gui/vpPlot.h>
#include <visp3/robot/vpSimulatorCamera.h>
#include <visp3/visual_features/vpFeatureBuilder.h>
#include <visp3/vs/vpServo.h>
int main()
{
try {
vpHomogeneousMatrix cdMo(0, 0, 0.75, 0, 0, 0);
vpHomogeneousMatrix cMo(0.15, -0.1, 1., vpMath::rad(10), vpMath::rad(-10), vpMath::rad(50));
vpPoint point[4];
point[0].setWorldCoordinates(-0.1, -0.1, 0);
point[1].setWorldCoordinates(0.1, -0.1, 0);
point[2].setWorldCoordinates(0.1, 0.1, 0);
point[3].setWorldCoordinates(-0.1, 0.1, 0);
vpServo task;
vpAdaptiveGain lambda(4, 0.4, 30);
task.setLambda(lambda);
vpFeaturePoint p[4], pd[4];
for (unsigned int i = 0; i < 4; i++) {
point[i].track(cdMo);
vpFeatureBuilder::create(pd[i], point[i]);
point[i].track(cMo);
vpFeatureBuilder::create(p[i], point[i]);
task.addFeature(p[i], pd[i]);
}
robot.setSamplingTime(0.040);
robot.getPosition(wMc);
wMo = wMc * cMo;
#ifdef VISP_HAVE_DISPLAY
vpPlot plotter(2, 250 * 2, 500, 100, 200, "Real time curves plotter");
plotter.setTitle(0, "Visual features error");
plotter.setTitle(1, "Camera velocities");
plotter.initGraph(0, 8);
plotter.initGraph(1, 6);
plotter.setLegend(0, 0, "x1");
plotter.setLegend(0, 1, "y1");
plotter.setLegend(0, 2, "x2");
plotter.setLegend(0, 3, "y2");
plotter.setLegend(0, 4, "x3");
plotter.setLegend(0, 5, "y3");
plotter.setLegend(0, 6, "x4");
plotter.setLegend(0, 7, "y4");
plotter.setLegend(1, 0, "v_x");
plotter.setLegend(1, 1, "v_y");
plotter.setLegend(1, 2, "v_z");
plotter.setLegend(1, 3, "w_x");
plotter.setLegend(1, 4, "w_y");
plotter.setLegend(1, 5, "w_z");
#endif
unsigned int iter = 0;
while (1) {
robot.getPosition(wMc);
cMo = wMc.inverse() * wMo;
for (unsigned int i = 0; i < 4; i++) {
point[i].track(cMo);
vpFeatureBuilder::create(p[i], point[i]);
}
vpColVector v = task.computeControlLaw(iter * robot.getSamplingTime());
#ifdef VISP_HAVE_DISPLAY
plotter.plot(0, iter, task.getError());
plotter.plot(1, iter, v);
#endif
if ((task.getError()).sumSquare() < 0.0001)
break;
iter++;
}
std::cout << "Convergence in " << iter << " iterations" << std::endl;
task.kill();
#ifdef VISP_HAVE_DISPLAY
plotter.saveData(0, "error.dat");
plotter.saveData(1, "vc.dat");
#endif
} catch (const vpException &e) {
std::cout << "Catch an exception: " << e << std::endl;
}
}
vpServo::kill
void kill()
Definition: vpServo.cpp:191
vpServo::CURRENT
Definition: vpServo.h:185
vpMath::rad
static double rad(double deg)
Definition: vpMath.h:107
vpServo::setLambda
void setLambda(double c)
Definition: vpServo.h:405
vpPlot::I
vpImage< unsigned char > I
Definition: vpPlot.h:117
vpRobotSimulator::getSamplingTime
double getSamplingTime() const
Definition: vpRobotSimulator.h:81
vpServo::EYEINHAND_CAMERA
Definition: vpServo.h:158
vpFeatureBuilder::create
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Definition: vpFeatureBuilderPoint.cpp:92
vpSimulatorCamera
Class that defines the simplest robot: a free flying camera.
Definition: vpSimulatorCamera.h:106
vpColVector
Implementation of column vector and the associated operations.
Definition: vpColVector.h:129
vpServo::setServo
void setServo(const vpServoType &servo_type)
Definition: vpServo.cpp:222
vpSimulatorCamera::getPosition
vpHomogeneousMatrix getPosition() const
Definition: vpSimulatorCamera.cpp:118
vpPlot::setLegend
void setLegend(unsigned int graphNum, unsigned int curveNum, const std::string &legend)
Definition: vpPlot.cpp:546
vpPoint::setWorldCoordinates
void setWorldCoordinates(double oX, double oY, double oZ)
Definition: vpPoint.cpp:112
vpAdaptiveGain
Adaptive gain computation.
Definition: vpAdaptiveGain.h:120
vpPlot::saveData
void saveData(unsigned int graphNum, const std::string &dataFile, const std::string &title_prefix="")
Definition: vpPlot.cpp:645
vpServo::getError
vpColVector getError() const
Definition: vpServo.h:281
vpRobot::CAMERA_FRAME
Definition: vpRobot.h:81
vpServo::addFeature
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
Definition: vpServo.cpp:496
vpPlot::setTitle
void setTitle(unsigned int graphNum, const std::string &title)
Definition: vpPlot.cpp:497
vpFeaturePoint
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
Definition: vpFeaturePoint.h:180
vpServo::setInteractionMatrixType
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Definition: vpServo.cpp:573
vpPlot::plot
void plot(unsigned int graphNum, unsigned int curveNum, double x, double y)
Definition: vpPlot.cpp:285
vpServo
Definition: vpServo.h:149
vpServo::computeControlLaw
vpColVector computeControlLaw()
Definition: vpServo.cpp:934
vpRobotSimulator::setSamplingTime
virtual void setSamplingTime(const double &delta_t)
Definition: vpRobotSimulator.h:90
vpHomogeneousMatrix::inverse
vpHomogeneousMatrix inverse() const
Definition: vpHomogeneousMatrix.cpp:640
vpPlot::initGraph
void initGraph(unsigned int graphNum, unsigned int curveNbr)
Definition: vpPlot.cpp:205
vpPoint
Class that defines what is a point.
Definition: vpPoint.h:57
vpDisplay::getClick
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Definition: vpDisplay_uchar.cpp:764
vpHomogeneousMatrix
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition: vpHomogeneousMatrix.h:148
vpSimulatorCamera::setVelocity
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
Definition: vpSimulatorCamera.cpp:197
vpException
error that can be emited by ViSP classes.
Definition: vpException.h:70
vpPlot
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:114
vpForwardProjection::track
void track(const vpHomogeneousMatrix &cMo)
Definition: vpForwardProjection.cpp:110