42 #include <visp/vpConfig.h>
44 #ifdef VISP_HAVE_AFMA6
48 #include <sys/types.h>
51 #include <visp/vpRobotException.h>
52 #include <visp/vpExponentialMap.h>
53 #include <visp/vpDebug.h>
54 #include <visp/vpVelocityTwistMatrix.h>
55 #include <visp/vpThetaUVector.h>
56 #include <visp/vpRobotAfma6.h>
57 #include <visp/vpRotationMatrix.h>
63 bool vpRobotAfma6::robotAlreadyCreated =
false;
85 void emergencyStopAfma6(
int signo)
87 std::cout <<
"Stop the Afma6 application by signal ("
88 << signo <<
"): " << (char)7 ;
92 std::cout <<
"SIGINT (stop by ^C) " << std::endl ; break ;
94 std::cout <<
"SIGBUS (stop due to a bus error) " << std::endl ; break ;
96 std::cout <<
"SIGSEGV (stop due to a segmentation fault) " << std::endl ; break ;
98 std::cout <<
"SIGKILL (stop by CTRL \\) " << std::endl ; break ;
100 std::cout <<
"SIGQUIT " << std::endl ; break ;
102 std::cout << signo << std::endl ;
106 PrimitiveSTOP_Afma6();
107 std::cout <<
"Robot was stopped\n";
112 fprintf(stdout,
"Application ");
114 kill(getpid(), SIGKILL);
158 vpRobotAfma6::vpRobotAfma6 (
bool verbose)
183 signal(SIGINT, emergencyStopAfma6);
184 signal(SIGBUS, emergencyStopAfma6) ;
185 signal(SIGSEGV, emergencyStopAfma6) ;
186 signal(SIGKILL, emergencyStopAfma6);
187 signal(SIGQUIT, emergencyStopAfma6);
191 std::cout <<
"Open communication with MotionBlox.\n";
202 vpRobotAfma6::robotAlreadyCreated =
true;
239 time_prev_getvel = 0;
240 first_time_getvel =
true;
245 first_time_getdis =
true;
248 Try( InitializeConnection(
verbose_) );
251 Try( InitializeNode_Afma6() );
253 Try( PrimitiveRESET_Afma6() );
259 UInt32 HIPowerStatus;
261 Try( PrimitiveSTATUS_Afma6(NULL, NULL, &EStopStatus, NULL, NULL, NULL,
267 std::cout <<
"Robot status: ";
268 switch(EStopStatus) {
271 if (HIPowerStatus == 0)
272 std::cout <<
"Power is OFF" << std::endl;
274 std::cout <<
"Power is ON" << std::endl;
276 case ESTOP_ACTIVATED:
277 std::cout <<
"Emergency stop is activated" << std::endl;
280 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
281 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
284 std::cout << std::endl;
297 if (TryStt == -20001)
298 printf(
"No connection detected. Check if the robot is powered on \n"
299 "and if the firewire link exist between the MotionBlox and this computer.\n");
300 else if (TryStt == -675)
301 printf(
" Timeout enabling power...\n");
305 PrimitivePOWEROFF_Afma6();
307 ShutDownConnection();
309 std::cout <<
"Cannot open connexion with the motionblox..." << std::endl;
311 "Cannot open connexion with the motionblox");
368 for (
unsigned int i=0; i < 3; i ++) {
369 eMc_pose[i] =
_etc[i];
370 eMc_pose[i+3] =
_erc[i];
373 Try( PrimitiveCAMERA_CONST_Afma6(eMc_pose) );
404 UInt32 HIPowerStatus;
405 Try( PrimitiveSTATUS_Afma6(NULL, NULL, NULL, NULL, NULL, NULL,
417 ShutDownConnection();
419 vpRobotAfma6::robotAlreadyCreated =
false;
442 Try( PrimitiveSTOP_Afma6() );
448 std::cout <<
"Change the control mode from velocity to position control.\n";
449 Try( PrimitiveSTOP_Afma6() );
459 std::cout <<
"Change the control mode from stop to velocity control.\n";
489 Try( PrimitiveSTOP_Afma6() );
496 "Cannot stop robot motion.");
515 UInt32 HIPowerStatus;
517 bool firsttime =
true;
518 unsigned int nitermax = 10;
520 for (
unsigned int i=0; i<nitermax; i++) {
521 Try( PrimitiveSTATUS_Afma6(NULL, NULL, &EStopStatus, NULL, NULL, NULL,
523 if (EStopStatus == ESTOP_AUTO) {
526 else if (EStopStatus == ESTOP_MANUAL) {
529 else if (EStopStatus == ESTOP_ACTIVATED) {
531 std::cout <<
"Emergency stop is activated! \n"
532 <<
"Check the emergency stop button and push the yellow button before continuing." << std::endl;
535 fprintf(stdout,
"Remaining time %ds \r", nitermax-i);
540 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
541 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
543 ShutDownConnection();
548 if (EStopStatus == ESTOP_ACTIVATED)
549 std::cout << std::endl;
551 if (EStopStatus == ESTOP_ACTIVATED) {
552 std::cout <<
"Sorry, cannot power on the robot." << std::endl;
554 "Cannot power on the robot.");
557 if (HIPowerStatus == 0) {
558 fprintf(stdout,
"Power ON the Afma6 robot\n");
561 Try( PrimitivePOWERON_Afma6() );
568 "Cannot power off the robot.");
587 UInt32 HIPowerStatus;
588 Try( PrimitiveSTATUS_Afma6(NULL, NULL, NULL, NULL, NULL, NULL,
592 if (HIPowerStatus == 1) {
593 fprintf(stdout,
"Power OFF the Afma6 robot\n");
596 Try( PrimitivePOWEROFF_Afma6() );
603 "Cannot power off the robot.");
624 UInt32 HIPowerStatus;
625 Try( PrimitiveSTATUS_Afma6(NULL, NULL, NULL, NULL, NULL, NULL,
629 if (HIPowerStatus == 1) {
637 "Cannot get the power status.");
695 Try( PrimitiveACQ_POS_Afma6(position, ×tamp) );
699 for (
unsigned int i=0; i <
njoint; i++)
743 Try( PrimitiveACQ_POS_Afma6(position, ×tamp) );
747 for (
unsigned int i=0; i <
njoint; i++)
792 positioningVelocity = velocity;
803 return positioningVelocity;
892 for (
unsigned int i=0; i < 3; i++) {
893 position[i] = pose[i];
894 position[i+3] = rxyz[i];
898 "Positionning error: "
899 "Joint frame not implemented for pose positionning.");
993 "Modification of the robot state");
997 double _destination[6];
1005 Try( PrimitiveACQ_POS_Afma6(_q, ×tamp) );
1008 for (
unsigned int i=0; i <
njoint; i++)
1018 for (
unsigned int i=0; i < 3; i++) {
1019 txyz[i] = position[i];
1020 rxyz[i] = position[i+3];
1031 bool nearest =
true;
1034 for (
unsigned int i=0; i <
njoint; i ++) {
1035 _destination[i] = q[i];
1037 Try( PrimitiveMOVE_Afma6(_destination, positioningVelocity) );
1038 Try( WaitState_Afma6(ETAT_ATTENTE_AFMA6, 1000) );
1048 for (
unsigned int i=0; i <
njoint; i ++) {
1049 _destination[i] = position[i];
1051 Try( PrimitiveMOVE_Afma6(_destination, positioningVelocity) );
1052 Try( WaitState_Afma6(ETAT_ATTENTE_AFMA6, 1000) );
1060 for (
unsigned int i=0; i < 3; i++) {
1061 txyz[i] = position[i];
1062 rxyz[i] = position[i+3];
1070 bool nearest =
true;
1073 for (
unsigned int i=0; i <
njoint; i ++) {
1074 _destination[i] = q[i];
1076 Try( PrimitiveMOVE_Afma6(_destination, positioningVelocity) );
1077 Try( WaitState_Afma6(ETAT_ATTENTE_AFMA6, 1000) );
1088 vpERROR_TRACE (
"Positionning error. Mixt frame not implemented");
1090 "Positionning error: "
1091 "Mixt frame not implemented.");
1097 if (TryStt == InvalidPosition || TryStt == -1023)
1098 std::cout <<
" : Position out of range.\n";
1099 else if (TryStt < 0)
1100 std::cout <<
" : Unknown error (see Fabien).\n";
1101 else if (error == -1)
1102 std::cout <<
"Position out of range.\n";
1104 if (TryStt < 0 || error < 0) {
1107 "Position out of range.");
1190 position[0] = pos1 ;
1191 position[1] = pos2 ;
1192 position[2] = pos3 ;
1193 position[3] = pos4 ;
1194 position[4] = pos5 ;
1195 position[5] = pos6 ;
1257 "Bad position in filename.");
1332 Try( PrimitiveACQ_POS_Afma6(_q, ×tamp) );
1333 for (
unsigned int i=0; i <
njoint; i ++) {
1334 position[i] = _q[i];
1341 Try( PrimitiveACQ_POS_Afma6(_q, ×tamp) );
1344 for (
unsigned int i=0; i <
njoint; i++)
1357 for (
unsigned int i=0; i < 3; i++) {
1358 position[i] = fMc[i][3];
1359 position[i+3] = rxyz[i];
1364 vpERROR_TRACE (
"Cannot get position in mixt frame: not implemented");
1366 "Cannot get position in mixt frame: "
1376 "Cannot get position.");
1387 PrimitiveACQ_TIME_Afma6(×tamp);
1423 for(
unsigned int j=0;j<3;j++)
1424 RxyzVect[j]=posRxyz[j+3];
1429 for(
unsigned int j=0;j<3;j++)
1431 position[j]=posRxyz[j];
1432 position[j+3]=RtuVect[j];
1513 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1515 "Cannot send a velocity to the robot "
1516 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1521 for (
unsigned int i=0; i<3; i++)
1523 for (
unsigned int i=3; i<6; i++)
1532 Try( PrimitiveMOVESPEED_CART_Afma6(vel_sat.
data, REPCAM_AFMA6) );
1537 Try( PrimitiveMOVESPEED_Afma6(vel_sat.
data) );
1541 Try( PrimitiveMOVESPEED_CART_Afma6(vel_sat.
data, REPFIX_AFMA6) );
1545 Try( PrimitiveMOVESPEED_CART_Afma6(vel_sat.
data, REPMIX_AFMA6) );
1550 "Case not taken in account.");
1557 if (TryStt == VelStopOnJoint) {
1558 Int32 axisInJoint[
njoint];
1559 PrimitiveSTATUS_Afma6(NULL, NULL, NULL, NULL, NULL, axisInJoint, NULL);
1560 for (
unsigned int i=0; i <
njoint; i ++) {
1562 std::cout <<
"\nWarning: Velocity control stopped: axis "
1563 << i+1 <<
" on joint limit!" <<std::endl;
1567 printf(
"\n%s(%d): Error %d", __FUNCTION__, TryLine, TryStt);
1568 if (TryString != NULL) {
1570 printf(
" Error sentence %s\n", TryString);
1656 Try( PrimitiveACQ_POS_Afma6(q, ×tamp) );
1657 time_cur = timestamp;
1658 for (
unsigned int i=0; i <
njoint; i ++) {
1665 if ( ! first_time_getvel ) {
1670 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1679 velocity = (q_cur - q_prev_getvel) / (time_cur - time_prev_getvel);
1685 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1700 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1708 for (
unsigned int i=0; i < 3; i++) {
1710 velocity[i] = fMc_prev_getvel[i][3] - fMc_cur[i][3];
1712 velocity[i+3] = thetaU[i];
1716 velocity /= (time_cur - time_prev_getvel);
1722 first_time_getvel =
false;
1726 fMc_prev_getvel = fMc_cur;
1729 q_prev_getvel = q_cur;
1732 time_prev_getvel = time_cur;
1739 "Cannot get velocity.");
1879 fd = fopen(filename,
"r") ;
1883 char line[FILENAME_MAX];
1884 char dummy[FILENAME_MAX];
1886 bool sortie =
false;
1890 if (fgets (line, FILENAME_MAX, fd) != NULL) {
1891 if ( strncmp (line,
"#", 1) != 0) {
1893 if ( strncmp (line, head,
sizeof(head)-1) == 0) {
1905 while ( sortie !=
true );
1909 sscanf(line,
"%s %lf %lf %lf %lf %lf %lf",
1911 &q[0], &q[1], &q[2],
1912 &q[3], &q[4], &q[5]);
1915 for (
unsigned int i=3; i <
njoint; i ++)
1951 fd = fopen(filename,
"w") ;
1956 #AFMA6 - Position - Version 2.01\n\
1959 # Joint position: X, Y, Z: translations in meters\n\
1960 # A, B, C: rotations in degrees\n\
1965 fprintf(fd,
"R: %lf %lf %lf %lf %lf %lf\n",
2031 Try( PrimitiveGripper_Afma6(1) );
2032 std::cout <<
"Open the gripper..." << std::endl;
2037 "Cannot open the gripper.");
2052 Try( PrimitiveGripper_Afma6(0) );
2053 std::cout <<
"Close the gripper..." << std::endl;
2058 "Cannot close the gripper.");
2076 vpRobotAfma6::getCameraDisplacement(
vpColVector &displacement)
2092 vpRobotAfma6::getArticularDisplacement(
vpColVector &displacement)
2132 Try( PrimitiveACQ_POS_Afma6(q, ×tamp) );
2133 for (
unsigned int i=0; i <
njoint; i ++) {
2140 if ( ! first_time_getdis ) {
2144 c_prevMc_cur = fMc_prev_getdis.
inverse() * fMc_cur;
2154 for (
unsigned int i=0; i<3; i++) {
2155 displacement[i] = t[i];
2156 displacement[i+3] = rxyz[i];
2162 displacement = q_cur - q_prev_getdis;
2167 std::cout <<
"getDisplacement() REFERENCE_FRAME not implemented\n";
2173 std::cout <<
"getDisplacement() MIXT_FRAME not implemented\n";
2180 first_time_getdis =
false;
2184 q_prev_getdis = q_cur;
2187 fMc_prev_getdis = fMc_cur;
2193 "Cannot get velocity.");
2210 Int32 axisInJoint[
njoint];
2215 Try (PrimitiveSTATUS_Afma6(NULL, NULL, NULL, NULL, NULL, axisInJoint,
2217 for (
unsigned int i=0; i <
njoint; i ++) {
2218 if (axisInJoint[i]){
2219 std::cout <<
"\nWarning: Velocity control stopped: axis "
2220 << i+1 <<
" on joint limit!" <<std::endl;
2221 jointsStatus[i] = axisInJoint[i];
2225 jointsStatus[i] = 0;
2233 "Cannot check joint limits.");
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
Modelisation of Irisa's gantry robot named Afma6.
static vpColVector inverse(const vpHomogeneousMatrix &M)
Definition of the vpMatrix class.
bool checkJointLimits(vpColVector &jointsStatus)
static const unsigned int njoint
Number of joint.
void get_eJe(vpMatrix &_eJe)
Error that can be emited by the vpRobot class and its derivates.
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void setVerbose(bool verbose)
static bool savePosFile(const char *filename, const vpColVector &q)
vpHomogeneousMatrix get_fMc(const vpColVector &q)
virtual vpRobotStateType getRobotState(void)
void setPosition(const vpRobot::vpControlFrameType frame, const vpPoseVector &pose)
double getMaxTranslationVelocity(void) const
Initialize the position controller.
vpAfma6ToolType
List of possible tools that can be attached to the robot end-effector.
class that defines a generic virtual robot
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
double getPositioningVelocity(void)
double getMaxRotationVelocity(void) const
vpThetaUVector buildFrom(const vpHomogeneousMatrix &M)
virtual ~vpRobotAfma6(void)
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)
void setPositioningVelocity(const double velocity)
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
void setToolType(vpAfma6::vpAfma6ToolType tool)
Set the current tool type.
The vpRotationMatrix considers the particular case of a rotation matrix.
double * data
address of the first element of the data array
void get_cMe(vpHomogeneousMatrix &cMe)
vpRotationMatrix buildFrom(const vpThetaUVector &v)
Transform a vector vpThetaUVector into an rotation matrix.
static const vpAfma6ToolType defaultTool
Default tool attached to the robot end effector.
Initialize the velocity controller.
void get_eJe(const vpColVector &q, vpMatrix &eJe)
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
int getInverseKinematics(const vpHomogeneousMatrix &fMc, vpColVector &q, const bool &nearest=true, const bool &verbose=false)
vpCameraParametersProjType
void get_fJe(vpMatrix &_fJe)
void extract(vpRotationMatrix &R) const
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
Class that consider the particular case of twist transformation matrix that allows to transform a vel...
void get_cVe(vpVelocityTwistMatrix &_cVe)
static double rad(double deg)
void get_cMe(vpHomogeneousMatrix &_cMe)
void move(const char *filename)
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...
The pose is a complete representation of every rigid motion in the euclidian space.
vpHomogeneousMatrix inverse() const
void get_fJe(const vpColVector &q, vpMatrix &fJe)
Class that consider the case of the Euler angle using the x-y-z convention, where are respectively ...
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity)
static bool readPosFile(const char *filename, vpColVector &q)
void buildFrom(const double phi, const double theta, const double psi)
Class that consider the case of a translation vector.
Class that consider the case of the parameterization for the rotation.
static const double defaultPositioningVelocity
void getDisplacement(vpRobot::vpControlFrameType frame, vpColVector &displacement)
void resize(const unsigned int i, const bool flagNullify=true)