42 #include <visp/vpConfig.h>
44 #ifdef VISP_HAVE_VIPER850
49 #include <visp/vpRobotException.h>
50 #include <visp/vpExponentialMap.h>
51 #include <visp/vpDebug.h>
52 #include <visp/vpVelocityTwistMatrix.h>
53 #include <visp/vpThetaUVector.h>
54 #include <visp/vpRobot.h>
55 #include <visp/vpRobotViper850.h>
61 bool vpRobotViper850::robotAlreadyCreated =
false;
83 void emergencyStopViper850(
int signo)
85 std::cout <<
"Stop the Viper850 application by signal ("
86 << signo <<
"): " << (char)7 ;
90 std::cout <<
"SIGINT (stop by ^C) " << std::endl ; break ;
92 std::cout <<
"SIGBUS (stop due to a bus error) " << std::endl ; break ;
94 std::cout <<
"SIGSEGV (stop due to a segmentation fault) " << std::endl ; break ;
96 std::cout <<
"SIGKILL (stop by CTRL \\) " << std::endl ; break ;
98 std::cout <<
"SIGQUIT " << std::endl ; break ;
100 std::cout << signo << std::endl ;
104 PrimitiveSTOP_Viper850();
105 std::cout <<
"Robot was stopped\n";
110 fprintf(stdout,
"Application ");
112 kill(getpid(), SIGKILL);
200 signal(SIGINT, emergencyStopViper850);
201 signal(SIGBUS, emergencyStopViper850) ;
202 signal(SIGSEGV, emergencyStopViper850) ;
203 signal(SIGKILL, emergencyStopViper850);
204 signal(SIGQUIT, emergencyStopViper850);
206 std::cout <<
"Open communication with MotionBlox.\n";
217 vpRobotViper850::robotAlreadyCreated =
true;
254 time_prev_getvel = 0;
255 first_time_getvel =
true;
260 first_time_getdis =
true;
264 Try( InitializeConnection() );
267 Try( InitializeNode_Viper850() );
269 Try( PrimitiveRESET_Viper850() );
275 UInt32 HIPowerStatus;
277 Try( PrimitiveSTATUS_Viper850(NULL, NULL, &EStopStatus, NULL, NULL, NULL,
282 std::cout <<
"Robot status: ";
283 switch(EStopStatus) {
286 if (HIPowerStatus == 0)
287 std::cout <<
"Power is OFF" << std::endl;
289 std::cout <<
"Power is ON" << std::endl;
294 if (HIPowerStatus == 0)
295 std::cout <<
"Power is OFF" << std::endl;
297 std::cout <<
"Power is ON" << std::endl;
299 case ESTOP_ACTIVATED:
301 std::cout <<
"Emergency stop is activated" << std::endl;
304 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
305 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
308 std::cout << std::endl;
325 if (TryStt == -20001)
326 printf(
"No connection detected. Check if the robot is powered on \n"
327 "and if the firewire link exist between the MotionBlox and this computer.\n");
328 else if (TryStt == -675)
329 printf(
" Timeout enabling power...\n");
333 PrimitivePOWEROFF_Viper850();
335 ShutDownConnection();
337 std::cout <<
"Cannot open connexion with the motionblox..." << std::endl;
339 "Cannot open connexion with the motionblox");
413 for (
unsigned int i=0; i < 3; i ++) {
414 eMc_pose[i] =
etc[i];
415 eMc_pose[i+3] =
erc[i];
418 Try( PrimitiveCONST_Viper850(eMc_pose) );
453 UInt32 HIPowerStatus;
454 Try( PrimitiveSTATUS_Viper850(NULL, NULL, NULL, NULL, NULL, NULL,
466 ShutDownConnection();
468 vpRobotViper850::robotAlreadyCreated =
false;
492 Try( PrimitiveSTOP_Viper850() );
498 std::cout <<
"Change the control mode from velocity to position control.\n";
499 Try( PrimitiveSTOP_Viper850() );
509 std::cout <<
"Change the control mode from stop to velocity control.\n";
542 Try( PrimitiveSTOP_Viper850() );
549 "Cannot stop robot motion.");
568 UInt32 HIPowerStatus;
570 bool firsttime =
true;
571 unsigned int nitermax = 10;
573 for (
unsigned int i=0; i<nitermax; i++) {
574 Try( PrimitiveSTATUS_Viper850(NULL, NULL, &EStopStatus, NULL, NULL, NULL,
576 switch(EStopStatus) {
577 case ESTOP_AUTO: controlMode =
AUTO;
break;
578 case ESTOP_MANUAL: controlMode =
MANUAL;
break;
579 case ESTOP_ACTIVATED:
582 std::cout <<
"Emergency stop is activated! \n"
583 <<
"Check the emergency stop button and push the yellow button before continuing." << std::endl;
586 fprintf(stdout,
"Remaining time %ds \r", nitermax-i);
591 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
592 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
594 ShutDownConnection();
599 std::cout << std::endl;
601 if (EStopStatus == ESTOP_ACTIVATED) {
602 std::cout <<
"Sorry, cannot power on the robot." << std::endl;
604 "Cannot power on the robot.");
607 if (HIPowerStatus == 0) {
608 fprintf(stdout,
"Power ON the Viper850 robot\n");
611 Try( PrimitivePOWERON_Viper850() );
618 "Cannot power off the robot.");
637 UInt32 HIPowerStatus;
638 Try( PrimitiveSTATUS_Viper850(NULL, NULL, NULL, NULL, NULL, NULL,
642 if (HIPowerStatus == 1) {
643 fprintf(stdout,
"Power OFF the Viper850 robot\n");
646 Try( PrimitivePOWEROFF_Viper850() );
653 "Cannot power off the robot.");
674 UInt32 HIPowerStatus;
675 Try( PrimitiveSTATUS_Viper850(NULL, NULL, NULL, NULL, NULL, NULL,
679 if (HIPowerStatus == 1) {
687 "Cannot get the power status.");
746 Try( PrimitiveACQ_POS_J_Viper850(position) );
750 for (
unsigned int i=0; i <
njoint; i++)
782 Try( PrimitiveACQ_POS_Viper850(position) );
786 for (
unsigned int i=0; i <
njoint; i++)
840 positioningVelocity = velocity;
851 return positioningVelocity;
940 "Modification of the robot state");
951 Try( PrimitiveACQ_POS_Viper850(q.
data) );
963 for (
unsigned int i=0; i < 3; i++) {
964 txyz[i] = position[i];
965 rxyz[i] = position[i+3];
981 Try( PrimitiveMOVE_J_Viper850(destination.
data, positioningVelocity) );
982 Try( WaitState_Viper850(ETAT_ATTENTE_AFMA6, 1000) );
992 destination = position;
997 Try( PrimitiveMOVE_J_Viper850(destination.
data, positioningVelocity) );
998 Try( WaitState_Viper850(ETAT_ATTENTE_AFMA6, 1000) );
1004 vpRxyzVector rxyz(position[3],position[4],position[5]);
1008 for (
unsigned int i=0; i <3; i++) {
1009 destination[i] = position[i];
1012 int configuration = 0;
1015 Try( PrimitiveMOVE_C_Viper850(destination.
data, configuration,
1016 positioningVelocity) );
1017 Try( WaitState_Viper850(ETAT_ATTENTE_AFMA6, 1000) );
1023 vpERROR_TRACE (
"Positionning error. Mixt frame not implemented");
1025 "Positionning error: "
1026 "Mixt frame not implemented.");
1032 if (TryStt == InvalidPosition || TryStt == -1023)
1033 std::cout <<
" : Position out of range.\n";
1034 else if (TryStt == -3019) {
1036 std::cout <<
" : Joint position out of range.\n";
1038 std::cout <<
" : Cartesian position leads to a joint position out of range.\n";
1040 else if (TryStt < 0)
1041 std::cout <<
" : Unknown error (see Fabien).\n";
1042 else if (error == -1)
1043 std::cout <<
"Position out of range.\n";
1045 if (TryStt < 0 || error < 0) {
1048 "Position out of range.");
1129 position[0] = pos1 ;
1130 position[1] = pos2 ;
1131 position[2] = pos3 ;
1132 position[3] = pos4 ;
1133 position[4] = pos5 ;
1134 position[5] = pos6 ;
1194 "Bad position in filename.");
1280 Try( PrimitiveACQ_POS_J_Viper850(position.
data) );
1287 Try( PrimitiveACQ_POS_C_Viper850(position.
data) );
1291 for (
unsigned int i=3; i <6; i++)
1294 vpRzyzVector rzyz(position[3], position[4], position[5]);
1299 for (
unsigned int i=0; i <3; i++)
1300 position[i+3] = rxyz[i];
1310 vpERROR_TRACE (
"Cannot get position in mixt frame: not implemented");
1312 "Cannot get position in mixt frame: "
1322 "Cannot get position.");
1346 for (
unsigned int j=0;j<3;j++)
1347 RxyzVect[j]=posRxyz[j+3];
1352 for (
unsigned int j=0;j<3;j++)
1354 position[j]=posRxyz[j];
1355 position[j+3]=RtuVect[j];
1437 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1439 "Cannot send a velocity to the robot "
1440 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1453 for (
int i=0; i<3; i++)
1455 for (
int i=3; i<6; i++)
1466 for (
int i=0; i<6; i++)
1479 Try( PrimitiveMOVESPEED_CART_Viper850(vel_sat.
data, REPCAM) );
1487 Try( PrimitiveMOVESPEED_Viper850(vel_sat.
data) );
1492 std::cout <<
"Vitesse ref appliquee: " << vel_sat.
t();
1493 Try( PrimitiveMOVESPEED_CART_Viper850(vel_sat.
data, REPFIX) );
1502 "Case not taken in account.");
1509 if (TryStt == VelStopOnJoint) {
1510 UInt32 axisInJoint[
njoint];
1511 PrimitiveSTATUS_Viper850(NULL, NULL, NULL, NULL, NULL, axisInJoint, NULL);
1512 for (
unsigned int i=0; i <
njoint; i ++) {
1514 std::cout <<
"\nWarning: Velocity control stopped: axis "
1515 << i+1 <<
" on joint limit!" <<std::endl;
1519 printf(
"\n%s(%d): Error %d", __FUNCTION__, TryLine, TryStt);
1520 if (TryString != NULL) {
1522 printf(
" Error sentence %s\n", TryString);
1615 Try( PrimitiveACQ_POS_J_Viper850(q_cur.
data) );
1621 if ( ! first_time_getvel ) {
1626 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1635 velocity = (q_cur - q_prev_getvel)
1636 / (time_cur - time_prev_getvel);
1642 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1657 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1665 for (
unsigned int i=0; i < 3; i++) {
1667 velocity[i] = fMc_prev_getvel[i][3] - fMc_cur[i][3];
1669 velocity[i+3] = thetaU[i];
1673 velocity /= (time_cur - time_prev_getvel);
1679 first_time_getvel =
false;
1683 fMc_prev_getvel = fMc_cur;
1686 q_prev_getvel = q_cur;
1689 time_prev_getvel = time_cur;
1696 "Cannot get velocity.");
1829 fd = fopen(filename,
"r") ;
1833 char line[FILENAME_MAX];
1834 char dummy[FILENAME_MAX];
1836 bool sortie =
false;
1840 if (fgets (line, FILENAME_MAX, fd) != NULL) {
1841 if ( strncmp (line,
"#", 1) != 0) {
1843 if ( strncmp (line, head,
sizeof(head)-1) == 0) {
1855 while ( sortie !=
true );
1859 sscanf(line,
"%s %lf %lf %lf %lf %lf %lf",
1861 &q[0], &q[1], &q[2],
1862 &q[3], &q[4], &q[5]);
1899 fd = fopen(filename,
"w") ;
1904 #Viper - Position - Version 1.0\n\
1907 # Joint position in degrees\n\
1912 fprintf(fd,
"R: %lf %lf %lf %lf %lf %lf\n",
2018 Try( PrimitiveACQ_POS_Viper850(q) );
2019 for (
unsigned int i=0; i <
njoint; i ++) {
2023 if ( ! first_time_getdis ) {
2026 std::cout <<
"getDisplacement() CAMERA_FRAME not implemented\n";
2032 displacement = q_cur - q_prev_getdis;
2037 std::cout <<
"getDisplacement() REFERENCE_FRAME not implemented\n";
2043 std::cout <<
"getDisplacement() MIXT_FRAME not implemented\n";
2050 first_time_getdis =
false;
2054 q_prev_getdis = q_cur;
2060 "Cannot get velocity.");
2082 Try( PrimitiveTFS_BIAS_Viper850() );
2091 "Cannot bias the force/torque sensor.");
2141 Try( PrimitiveTFS_ACQ_Viper850(H.
data) );
2147 "Cannot get force/torque measures.");
2160 Try( PrimitiveGripper_Viper850(1) );
2161 std::cout <<
"Open the gripper..." << std::endl;
2166 "Cannot open the gripper.");
2181 Try( PrimitiveGripper_Viper850(0) );
2182 std::cout <<
"Close the gripper..." << std::endl;
2187 "Cannot close the gripper.");
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)
static vpColVector inverse(const vpHomogeneousMatrix &M)
Definition of the vpMatrix class.
double getPositioningVelocity(void)
Error that can be emited by the vpRobot class and its derivates.
static const vpToolType defaultTool
Default tool attached to the robot end effector.
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void get_eJe(const vpColVector &q, vpMatrix &eJe)
void getCameraDisplacement(vpColVector &displacement)
virtual vpRobotStateType getRobotState(void)
void setPositioningVelocity(const double velocity)
double getMaxTranslationVelocity(void) const
Initialize the position controller.
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
class that defines a generic virtual robot
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
void get_eJe(vpMatrix &eJe)
static int wait(double t0, double t)
static bool savePosFile(const char *filename, const vpColVector &q)
double getMaxRotationVelocity(void) const
vpThetaUVector buildFrom(const vpHomogeneousMatrix &M)
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
unsigned int getInverseKinematics(const vpHomogeneousMatrix &fMc, vpColVector &q)
The vpRotationMatrix considers the particular case of a rotation matrix.
void getDisplacement(vpRobot::vpControlFrameType frame, vpColVector &displacement)
double * data
address of the first element of the data array
static bool readPosFile(const char *filename, vpColVector &q)
Initialize the velocity controller.
void setToolType(vpViper850::vpToolType tool)
Set the current tool type.
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
void getForceTorque(vpColVector &H)
vpCameraParametersProjType
vpRowVector t() const
transpose of Vector
vpToolType
List of possible tools that can be attached to the robot end-effector.
Modelisation of the ADEPT Viper 850 robot.
void extract(vpRotationMatrix &R) const
void getArticularDisplacement(vpColVector &displacement)
Class that consider the particular case of twist transformation matrix that allows to transform a vel...
void get_fJe(vpMatrix &fJe)
static double rad(double deg)
void get_fJe(const vpColVector &q, vpMatrix &fJe)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity)
void biasForceTorqueSensor()
static double deg(double rad)
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Manual control mode activated when the dead man switch is in use.
static const double defaultPositioningVelocity
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position)
void get_cVe(vpVelocityTwistMatrix &cVe)
The pose is a complete representation of every rigid motion in the euclidian space.
vpHomogeneousMatrix inverse() const
void get_cMe(vpHomogeneousMatrix &cMe)
Class that consider the case of the Euler angle using the x-y-z convention, where are respectively ...
static double measureTimeSecond()
Emergency stop activated.
Class that consider the case of the Euler angles using the z-y-z convention, where are respectively...
virtual ~vpRobotViper850(void)
Automatic control mode (default).
Class that consider the case of a translation vector.
Class that consider the case of the parameterization for the rotation.
void move(const char *filename)
void get_cMe(vpHomogeneousMatrix &cMe)
static const unsigned int njoint
Number of joint.
vpHomogeneousMatrix get_fMc(const vpColVector &q)
void resize(const unsigned int i, const bool flagNullify=true)