44 #include <visp/vpConfig.h>
45 #if defined(_WIN32) || defined(VISP_HAVE_PTHREAD)
46 #include <visp/vpSimulatorAfma6.h>
47 #include <visp/vpTime.h>
48 #include <visp/vpImagePoint.h>
49 #include <visp/vpPoint.h>
50 #include <visp/vpMeterPixelConversion.h>
51 #include <visp/vpRobotException.h>
52 #include <visp/vpIoTools.h>
64 q_prev_getdis(), first_time_getdis(true), positioningVelocity(defaultPositioningVelocity),
65 zeroPos(), reposPos(), toolCustom(false), arm_dir()
80 DWORD dwThreadIdArray;
81 hThread = CreateThread(
88 #elif defined (VISP_HAVE_PTHREAD)
95 pthread_attr_init(&
attr);
96 pthread_attr_setdetachstate(&
attr, PTHREAD_CREATE_JOINABLE);
112 q_prev_getdis(), first_time_getdis(true), positioningVelocity(defaultPositioningVelocity),
113 zeroPos(), reposPos(), toolCustom(false), arm_dir()
121 mutex_fMi = CreateMutex(NULL,FALSE,NULL);
128 DWORD dwThreadIdArray;
129 hThread = CreateThread(
136 #elif defined(VISP_HAVE_PTHREAD)
143 pthread_attr_init(&
attr);
144 pthread_attr_setdetachstate(&
attr, PTHREAD_CREATE_JOINABLE);
160 WaitForSingleObject(hThread,INFINITE);
161 CloseHandle(hThread);
167 #elif defined(VISP_HAVE_PTHREAD)
168 pthread_attr_destroy(&
attr);
169 pthread_join(
thread, NULL);
179 for(
int i = 0; i < 6; i++)
200 arm_dir = VISP_ROBOT_ARMS_DIR;
204 std::cout <<
"The simulator uses data from VISP_ROBOT_ARMS_DIR=" << arm_dir << std::endl;
207 std::cout <<
"Cannot get VISP_ROBOT_ARMS_DIR environment variable" << std::endl;
223 reposPos[1] = -M_PI/2; reposPos[2] = M_PI; reposPos[4] = M_PI/2;
230 first_time_getdis =
true;
263 setExternalCameraPosition(
vpHomogeneousMatrix(0,0,0,0,0,
vpMath::rad(180))*
vpHomogeneousMatrix(-0.1,0,4,
vpMath::rad(90),0,0));
294 unsigned int name_length = 30;
295 if (arm_dir.size() > FILENAME_MAX)
297 unsigned int full_length = (
unsigned int)arm_dir.size() + name_length;
298 if (full_length > FILENAME_MAX)
317 char *name_arm =
new char [full_length];
318 strcpy(name_arm, arm_dir.c_str());
319 strcat(name_arm,
"/afma6_tool_ccmop.bnd");
340 char *name_arm =
new char [full_length];
341 strcpy(name_arm, arm_dir.c_str());
342 strcat(name_arm,
"/afma6_tool_gripper.bnd");
364 char *name_arm =
new char [full_length];
366 strcpy(name_arm, arm_dir.c_str());
367 strcat(name_arm,
"/afma6_tool_vacuum.bnd");
375 std::cout <<
"The generic camera is not handled in vpSimulatorAfma6.cpp" << std::endl;
398 const unsigned int &image_width,
399 const unsigned int &image_height)
409 if (image_width == 640 && image_height == 480)
411 std::cout <<
"Get default camera parameters for camera \""
416 vpTRACE(
"Cannot get default intrinsic camera parameters for this image resolution");
422 if (image_width == 640 && image_height == 480) {
423 std::cout <<
"Get default camera parameters for camera \""
428 vpTRACE(
"Cannot get default intrinsic camera parameters for this image resolution");
434 std::cout <<
"The generic camera is not handled in vpSimulatorAfma6.cpp" << std::endl;
495 double tcur_1 =
tcur;
508 double ellapsedTime = (
tcur -
tprev) * 1e-3;
527 articularVelocities = 0.0;
533 articularCoordinates[0] = articularCoordinates[0] + ellapsedTime*articularVelocities[0];
534 articularCoordinates[1] = articularCoordinates[1] + ellapsedTime*articularVelocities[1];
535 articularCoordinates[2] = articularCoordinates[2] + ellapsedTime*articularVelocities[2];
536 articularCoordinates[3] = articularCoordinates[3] + ellapsedTime*articularVelocities[3];
537 articularCoordinates[4] = articularCoordinates[4] + ellapsedTime*articularVelocities[4];
538 articularCoordinates[5] = articularCoordinates[5] + ellapsedTime*articularVelocities[5];
545 ellapsedTime = (
_joint_min[(
unsigned int)(-jl-1)] - articularCoordinates[(
unsigned int)(-jl-1)])/(articularVelocities[(
unsigned int)(-jl-1)]);
547 ellapsedTime = (
_joint_max[(
unsigned int)(jl-1)] - articularCoordinates[(
unsigned int)(jl-1)])/(articularVelocities[(
unsigned int)(jl-1)]);
549 for (
unsigned int i = 0; i < 6; i++)
550 articularCoordinates[i] = articularCoordinates[i] + ellapsedTime*articularVelocities[i];
592 for (
unsigned int k = 1; k < 7; k++)
698 fMit[4][0][0] = s4*s5;
699 fMit[4][1][0] = -c4*s5;
701 fMit[4][0][1] = s4*c5;
702 fMit[4][1][1] = -c4*c5;
707 fMit[4][0][3] = c4*this->
_long_56+q1;
708 fMit[4][1][3] = s4*this->
_long_56+q2;
711 fMit[5][0][0] = s4*s5*c6+c4*s6;
712 fMit[5][1][0] = -c4*s5*c6+s4*s6;
713 fMit[5][2][0] = c5*c6;
714 fMit[5][0][1] = -s4*s5*s6+c4*c6;
715 fMit[5][1][1] = c4*s5*s6+s4*c6;
716 fMit[5][2][1] = -c5*s6;
717 fMit[5][0][2] = -s4*c5;
718 fMit[5][1][2] = c4*c5;
720 fMit[5][0][3] = c4*this->
_long_56+q1;
721 fMit[5][1][3] = s4*this->
_long_56+q2;
724 fMit[6][0][0] = fMit[5][0][0];
725 fMit[6][1][0] = fMit[5][1][0];
726 fMit[6][2][0] = fMit[5][2][0];
727 fMit[6][0][1] = fMit[5][0][1];
728 fMit[6][1][1] = fMit[5][1][1];
729 fMit[6][2][1] = fMit[5][2][1];
730 fMit[6][0][2] = fMit[5][0][2];
731 fMit[6][1][2] = fMit[5][1][2];
732 fMit[6][2][2] = fMit[5][2][2];
733 fMit[6][0][3] = fMit[5][0][3];
734 fMit[6][1][3] = fMit[5][1][3];
735 fMit[6][2][3] = fMit[5][2][3];
745 for (
int i = 0; i < 8; i++)
748 #elif defined(VISP_HAVE_PTHREAD)
750 for (
int i = 0; i < 8; i++)
775 std::cout <<
"Change the control mode from velocity to position control.\n";
785 std::cout <<
"Change the control mode from stop to velocity control.\n";
871 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
873 "Cannot send a velocity to the robot "
874 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
879 double scale_trans_sat = 1;
880 double scale_rot_sat = 1;
881 double scale_sat = 1;
896 vpERROR_TRACE (
"The velocity vector must have a size of 6 !!!!");
900 for (
unsigned int i = 0 ; i < 3; ++ i)
902 vel_abs = fabs (vel[i]);
905 vel_trans_max = vel_abs;
907 "(axis nr. %d).", vel[i], i+1);
910 vel_abs = fabs (vel[i+3]);
912 vel_rot_max = vel_abs;
914 "(axis nr. %d).", vel[i+3], i+4);
924 if ( (scale_trans_sat < 1) || (scale_rot_sat < 1) )
926 if (scale_trans_sat < scale_rot_sat)
927 scale_sat = scale_trans_sat;
929 scale_sat = scale_rot_sat;
939 vpERROR_TRACE (
"The velocity vector must have a size of 6 !!!!");
942 for (
unsigned int i = 0 ; i < 6; ++ i)
944 vel_abs = fabs (vel[i]);
947 vel_rot_max = vel_abs;
949 "(axis nr. %d).", vel[i], i+1);
954 if ( scale_rot_sat < 1 )
955 scale_sat = scale_rot_sat;
978 double scale_rot_sat = 1;
979 double scale_sat = 1;
997 articularVelocity = eJe_*eVc*velocityframe;
1008 articularVelocity = fJe_*velocityframe;
1014 articularVelocity = velocityframe;
1031 for (
unsigned int i = 0 ; i < 6; ++ i)
1033 vel_abs = fabs (articularVelocity[i]);
1036 vel_rot_max = vel_abs;
1038 "(axis nr. %d).", articularVelocity[i], i+1);
1043 if ( scale_rot_sat < 1 )
1044 scale_sat = scale_rot_sat;
1119 vel = cVe*eJe_*articularVelocity;
1124 vel = articularVelocity;
1131 vel = fJe_*articularVelocity;
1141 "Case not taken in account.");
1247 double velmax = fabs(q[0]);
1248 for (
unsigned int i = 1; i < 6; i++)
1250 if (velmax < fabs(q[i]))
1251 velmax = fabs(q[i]);
1338 "Modification of the robot state");
1355 for (
unsigned int i=0; i < 3; i++)
1372 qdes = articularCoordinates;
1377 error = qdes - articularCoordinates;
1394 "Position out of range.");
1396 }
while (errsqr > 1e-8 && nbSol > 0);
1406 error = q - articularCoordinates;
1419 }
while (errsqr > 1e-8);
1430 for (
unsigned int i=0; i < 3; i++)
1442 qdes = articularCoordinates;
1447 error = qdes - articularCoordinates;
1462 }
while (errsqr > 1e-8 && nbSol > 0);
1467 vpERROR_TRACE (
"Positionning error. Mixt frame not implemented");
1469 "Positionning error: "
1470 "Mixt frame not implemented.");
1549 position[0] = pos1 ;
1550 position[1] = pos2 ;
1551 position[2] = pos3 ;
1552 position[3] = pos4 ;
1553 position[4] = pos5 ;
1554 position[5] = pos6 ;
1610 "Bad position in filename.");
1706 for (
unsigned int i=0; i <3; i++)
1716 vpERROR_TRACE (
"Positionning error. Mixt frame not implemented");
1718 "Positionning error: "
1719 "Mixt frame not implemented.");
1780 for(
unsigned int j=0;j<3;j++)
1782 position[j]=posRxyz[j];
1783 position[j+3]=RtuVect[j];
1816 vpTRACE(
"Joint limit vector has not a size of 6 !");
1846 bool cond = fabs(q5-M_PI/2) < 1e-1;
1876 for (
unsigned int i = 0; i < 6; i++)
1878 if (articularCoordinates[i] <=
_joint_min[i])
1880 difft =
_joint_min[i] - articularCoordinates[i];
1884 artNumb = -(int)i-1;
1889 for (
unsigned int i = 0; i < 6; i++)
1891 if (articularCoordinates[i] >=
_joint_max[i])
1893 difft = articularCoordinates[i] -
_joint_max[i];
1897 artNumb = (int)(i+1);
1903 std::cout <<
"\nWarning: Velocity control stopped: axis " << fabs((
float)artNumb) <<
" on joint limit!" <<std::endl;
1920 vpSimulatorAfma6::getCameraDisplacement(
vpColVector &displacement)
1935 vpSimulatorAfma6::getArticularDisplacement(
vpColVector &displacement)
1968 if ( ! first_time_getdis )
1974 std::cout <<
"getDisplacement() CAMERA_FRAME not implemented\n";
1981 displacement = q_cur - q_prev_getdis;
1987 std::cout <<
"getDisplacement() REFERENCE_FRAME not implemented\n";
1994 std::cout <<
"getDisplacement() MIXT_FRAME not implemented\n";
2002 first_time_getdis =
false;
2006 q_prev_getdis = q_cur;
2059 fd = fopen(filename,
"r") ;
2063 char line[FILENAME_MAX];
2064 char dummy[FILENAME_MAX];
2066 bool sortie =
false;
2070 if (fgets (line, FILENAME_MAX, fd) != NULL) {
2071 if ( strncmp (line,
"#", 1) != 0) {
2073 if ( strncmp (line, head,
sizeof(head)-1) == 0) {
2086 while ( sortie !=
true );
2090 int ret = sscanf(line,
"%s %lf %lf %lf %lf %lf %lf",
2092 &q[0], &q[1], &q[2], &q[3], &q[4], &q[5]);
2137 fd = fopen(filename,
"w") ;
2142 #AFMA6 - Position - Version 2.01\n\
2145 # Joint position: X, Y, Z: translations in meters\n\
2146 # A, B, C: rotations in degrees\n\
2151 fprintf(fd,
"R: %lf %lf %lf %lf %lf %lf\n",
2301 std::string scene_dir_;
2303 scene_dir_ = VISP_SCENES_DIR;
2307 std::cout <<
"The simulator uses data from VISP_SCENES_DIR=" << scene_dir_ << std::endl;
2310 std::cout <<
"Cannot get VISP_SCENES_DIR environment variable" << std::endl;
2314 unsigned int name_length = 30;
2315 if (scene_dir_.size() > FILENAME_MAX)
2317 unsigned int full_length = (
unsigned int)scene_dir_.size() + name_length;
2318 if (full_length > FILENAME_MAX)
2321 char *name_cam =
new char [full_length];
2323 strcpy(name_cam, scene_dir_.c_str());
2324 strcat(name_cam,
"/camera.bnd");
2327 if (arm_dir.size() > FILENAME_MAX)
2329 full_length = (
unsigned int)arm_dir.size() + name_length;
2330 if (full_length > FILENAME_MAX)
2333 char *name_arm =
new char [full_length];
2334 strcpy(name_arm, arm_dir.c_str());
2335 strcat(name_arm,
"/afma6_gate.bnd");
2337 strcpy(name_arm, arm_dir.c_str());
2338 strcat(name_arm,
"/afma6_arm1.bnd");
2340 strcpy(name_arm, arm_dir.c_str());
2341 strcat(name_arm,
"/afma6_arm2.bnd");
2343 strcpy(name_arm, arm_dir.c_str());
2344 strcat(name_arm,
"/afma6_arm3.bnd");
2346 strcpy(name_arm, arm_dir.c_str());
2347 strcat(name_arm,
"/afma6_arm4.bnd");
2352 strcpy(name_arm, arm_dir.c_str());
2355 strcat(name_arm,
"/afma6_tool_ccmop.bnd");
2359 strcat(name_arm,
"/afma6_tool_gripper.bnd");
2363 strcat(name_arm,
"/afma6_tool_vacuum.bnd");
2367 std::cout <<
"The generic camera is not handled in vpSimulatorAfma6.cpp" << std::endl;
2373 add_rfstack(IS_BACK);
2375 add_vwstack (
"start",
"depth", 0.0, 100.0);
2376 add_vwstack (
"start",
"window", -0.1,0.1,-0.1,0.1);
2377 add_vwstack (
"start",
"type", PERSPECTIVE);
2391 bool changed =
false;
2395 if (std::fabs(displacement[2][3]) > std::numeric_limits<double>::epsilon())
2418 float w44o[4][4],w44cext[4][4],x,y,z;
2422 add_vwstack (
"start",
"cop", w44cext[3][0],w44cext[3][1],w44cext[3][2]);
2423 x = w44cext[2][0] + w44cext[3][0];
2424 y = w44cext[2][1] + w44cext[3][1];
2425 z = w44cext[2][2] + w44cext[3][2];
2426 add_vwstack (
"start",
"vrp", x,y,z);
2427 add_vwstack (
"start",
"vpn", w44cext[2][0],w44cext[2][1],w44cext[2][2]);
2428 add_vwstack (
"start",
"vup", w44cext[1][0],w44cext[1][1],w44cext[1][2]);
2429 add_vwstack (
"start",
"window", -u, u, -v, v);
2437 vp2jlc_matrix(fMit[0],w44o);
2440 vp2jlc_matrix(fMit[2],w44o);
2443 vp2jlc_matrix(fMit[3],w44o);
2446 vp2jlc_matrix(fMit[4],w44o);
2449 vp2jlc_matrix(fMit[5],w44o);
2457 cMe = fMit[6] * cMe;
2458 vp2jlc_matrix(cMe,w44o);
2464 vp2jlc_matrix(
fMo,w44o);
2505 std::cout <<
"Used joint coordinates (rad): " << articularCoordinates.
t() << std::endl;
2535 fMo = fMit[7] * cMo_;
2561 const double lambda = 5.;
2566 unsigned int i,iter=0;
2586 v = -lambda*cdRc.
t()*cdTc;
2593 err[i+3] = cdTUc[i];
static void displayCamera(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness)
Modelisation of Irisa's gantry robot named Afma6.
Definition of the vpMatrix class.
static const unsigned int njoint
Number of joint.
Error that can be emited by the vpRobot class and its derivates.
vpColVector get_artCoord()
unsigned int getWidth() const
void setMaxTranslationVelocity(const double maxVt)
void get_eJe(vpMatrix &eJe)
int getInverseKinematics(const vpHomogeneousMatrix &fMc, vpColVector &q, const bool &nearest=true, const bool &verbose=false) const
double getSamplingTime() const
vpAfma6ToolType getToolType() const
Get the current tool type.
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
virtual ~vpSimulatorAfma6()
unsigned int jointLimitArt
void get_cVe(vpVelocityTwistMatrix &cVe)
vpHomogeneousMatrix get_fMc(const vpColVector &q) const
void move(const char *filename)
static void * launcher(void *arg)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
bool constantSamplingTimeMode
Flag used to force the sampling time in the thread computing the robot's displacement to a constant v...
bool singularityManagement
double getMaxTranslationVelocity(void) const
static const vpColor none
Initialize the position controller.
void get_eJe(const vpColVector &q, vpMatrix &eJe) const
error that can be emited by ViSP classes.
vpAfma6ToolType
List of possible tools that can be attached to the robot end-effector.
void setJointLimit(const vpColVector &limitMin, const vpColVector &limitMax)
void updateArticularPosition()
void track(const vpHomogeneousMatrix &cMo)
static const double defaultPositioningVelocity
vpRotationMatrix t() const
transpose
vpColVector get_velocity()
void getExternalImage(vpImage< vpRGBa > &I)
vpCameraParameters::vpCameraParametersProjType projModel
static double measureTimeMs()
double get_y() const
Get the point y coordinate in the image plane.
static int wait(double t0, double t)
double sumSquare() const
return sum of the Aij^2 (for all i, for all j)
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
double getMaxRotationVelocity(void) const
vpThetaUVector buildFrom(const vpHomogeneousMatrix &M)
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q)
vpRobot::vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
static bool readPosFile(const char *filename, vpColVector &q)
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Class that defines what is a point.
void setToolType(vpAfma6::vpAfma6ToolType tool)
Set the current tool type.
bool initialiseCameraRelativeToObject(const vpHomogeneousMatrix &cMo)
static const char *const CONST_GRIPPER_CAMERA_NAME
static Type maximum(const Type &a, const Type &b)
The vpRotationMatrix considers the particular case of a rotation matrix.
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &displacement)
pthread_mutex_t mutex_artCoord
pthread_mutex_t mutex_display
bool singularityTest(const vpColVector q, vpMatrix &J)
vpDisplayRobotType displayType
Initialize the velocity controller.
vpCameraParameters cameraParam
void initialiseObjectRelativeToCamera(const vpHomogeneousMatrix &cMo)
void setExternalCameraPosition(const vpHomogeneousMatrix camMf_)
Initialize the acceleration controller.
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
void set_displayBusy(const bool &status)
vpCameraParametersProjType
static void display(const vpImage< unsigned char > &I)
void get_cMe(vpHomogeneousMatrix &cMe) const
vpRowVector t() const
transpose of Vector
void getInternalView(vpImage< vpRGBa > &I)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity)
Generic class defining intrinsic camera parameters.
vpHomogeneousMatrix get_cMo()
vpHomogeneousMatrix getExternalCameraPosition() const
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q)
void extract(vpRotationMatrix &R) const
double get_x() const
Get the point x coordinate in the image plane.
static Type minimum(const Type &a, const Type &b)
void setCameraParameters(const vpCameraParameters &cam)
Class that consider the particular case of twist transformation matrix that allows to transform a vel...
void set_velocity(const vpColVector &vel)
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &q)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness=1)
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
Construction from translation vector and rotation matrix.
static double rad(double deg)
void setExternalCameraParameters(const vpCameraParameters &cam)
vpControlFrameType getRobotFrame(void) const
This class aims to be a basis used to create all the simulators of robots.
vpHomogeneousMatrix * fMi
void setMaxRotationVelocity(const double maxVr)
pthread_mutex_t mutex_fMi
bool setVelocityCalled
Flag used to specify to the thread managing the robot displacements that the setVelocity() method has...
void display_scene(Matrix mat, Bound_scene &sc, const vpImage< vpRGBa > &I, const vpColor &color)
double getPositioningVelocity(void)
vpHomogeneousMatrix camMf
vpHomogeneousMatrix navigation(const vpImage< vpRGBa > &I, bool &changed)
static double deg(double rad)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
double euclideanNorm() const
void get_fJe(vpMatrix &fJe)
The pose is a complete representation of every rigid motion in the euclidian space.
void computeArticularVelocity()
vpHomogeneousMatrix inverse() const
virtual vpRobotStateType getRobotState(void) const
unsigned int getHeight() const
Class that consider the case of the Euler angle using the x-y-z convention, where are respectively ...
void getCameraParameters(vpCameraParameters &cam, const unsigned int &image_width, const unsigned int &image_height)
vpControlFrameType setRobotFrame(vpRobot::vpControlFrameType newFrame)
void get_cMe(vpHomogeneousMatrix &cMe)
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
static double measureTimeSecond()
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void set_artCoord(const vpColVector &coord)
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
void set_artVel(const vpColVector &vel)
void get_fMi(vpHomogeneousMatrix *fMit)
unsigned int getRows() const
Return the number of rows of the matrix.
static const char *const CONST_CCMOP_CAMERA_NAME
pthread_mutex_t mutex_velocity
void get_fJe(const vpColVector &q, vpMatrix &fJe) const
Class that consider the case of a translation vector.
Class that consider the case of the parameterization for the rotation.
pthread_mutex_t mutex_artVel
static double minTimeForUsleepCall
vpHomogeneousMatrix camMf2
static bool savePosFile(const char *filename, const vpColVector &q)
void findHighestPositioningSpeed(vpColVector &q)
void setWorldCoordinates(const double ox, const double oy, const double oz)
Set the point world coordinates. We mean here the coordinates of the point in the object frame...
void resize(const unsigned int i, const bool flagNullify=true)