39 #include <visp3/core/vpConfig.h> 41 #ifdef VISP_HAVE_AFMA6 45 #include <sys/types.h> 48 #include <visp3/core/vpDebug.h> 49 #include <visp3/core/vpExponentialMap.h> 50 #include <visp3/core/vpIoTools.h> 51 #include <visp3/core/vpRotationMatrix.h> 52 #include <visp3/core/vpThetaUVector.h> 53 #include <visp3/core/vpVelocityTwistMatrix.h> 54 #include <visp3/robot/vpRobotAfma6.h> 55 #include <visp3/robot/vpRobotException.h> 61 bool vpRobotAfma6::robotAlreadyCreated =
false;
83 void emergencyStopAfma6(
int signo)
85 std::cout <<
"Stop the Afma6 application by signal (" << signo <<
"): " << (char)7;
88 std::cout <<
"SIGINT (stop by ^C) " << std::endl;
91 std::cout <<
"SIGBUS (stop due to a bus error) " << std::endl;
94 std::cout <<
"SIGSEGV (stop due to a segmentation fault) " << std::endl;
97 std::cout <<
"SIGKILL (stop by CTRL \\) " << std::endl;
100 std::cout <<
"SIGQUIT " << std::endl;
103 std::cout << signo << std::endl;
107 PrimitiveSTOP_Afma6();
108 std::cout <<
"Robot was stopped\n";
113 fprintf(stdout,
"Application ");
115 kill(getpid(), SIGKILL);
181 signal(SIGINT, emergencyStopAfma6);
182 signal(SIGBUS, emergencyStopAfma6);
183 signal(SIGSEGV, emergencyStopAfma6);
184 signal(SIGKILL, emergencyStopAfma6);
185 signal(SIGQUIT, emergencyStopAfma6);
189 std::cout <<
"Open communication with MotionBlox.\n";
199 vpRobotAfma6::robotAlreadyCreated =
true;
234 time_prev_getvel = 0;
235 first_time_getvel =
true;
240 first_time_getdis =
true;
243 Try(InitializeConnection(
verbose_));
246 Try(InitializeNode_Afma6());
248 Try(PrimitiveRESET_Afma6());
254 UInt32 HIPowerStatus;
256 Try(PrimitiveSTATUS_Afma6(NULL, NULL, &EStopStatus, NULL, NULL, NULL, &HIPowerStatus));
261 std::cout <<
"Robot status: ";
262 switch (EStopStatus) {
265 if (HIPowerStatus == 0)
266 std::cout <<
"Power is OFF" << std::endl;
268 std::cout <<
"Power is ON" << std::endl;
270 case ESTOP_ACTIVATED:
271 std::cout <<
"Emergency stop is activated" << std::endl;
274 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
275 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
278 std::cout << std::endl;
292 if (TryStt == -20001)
293 printf(
"No connection detected. Check if the robot is powered on \n" 294 "and if the firewire link exist between the MotionBlox and this " 296 else if (TryStt == -675)
297 printf(
" Timeout enabling power...\n");
301 PrimitivePOWEROFF_Afma6();
303 ShutDownConnection();
305 std::cout <<
"Cannot open connection with the motionblox..." << std::endl;
360 for (
unsigned int i = 0; i < 3; i++) {
361 eMc_pose[i] =
_etc[i];
362 eMc_pose[i + 3] =
_erc[i];
365 Try(PrimitiveCAMERA_CONST_Afma6(eMc_pose));
399 for (
unsigned int i = 0; i < 3; i++) {
400 eMc_pose[i] =
_etc[i];
401 eMc_pose[i + 3] =
_erc[i];
404 Try(PrimitiveCAMERA_CONST_Afma6(eMc_pose));
457 for (
unsigned int i = 0; i < 3; i++) {
458 eMc_pose[i] =
_etc[i];
459 eMc_pose[i + 3] =
_erc[i];
462 Try(PrimitiveCAMERA_CONST_Afma6(eMc_pose));
535 for (
unsigned int i = 0; i < 3; i++) {
536 eMc_pose[i] =
_etc[i];
537 eMc_pose[i + 3] =
_erc[i];
540 Try(PrimitiveCAMERA_CONST_Afma6(eMc_pose));
567 UInt32 HIPowerStatus;
568 Try(PrimitiveSTATUS_Afma6(NULL, NULL, NULL, NULL, NULL, NULL, &HIPowerStatus));
579 ShutDownConnection();
581 vpRobotAfma6::robotAlreadyCreated =
false;
600 Try(PrimitiveSTOP_Afma6());
606 std::cout <<
"Change the control mode from velocity to position control.\n";
607 Try(PrimitiveSTOP_Afma6());
617 std::cout <<
"Change the control mode from stop to velocity control.\n";
645 Try(PrimitiveSTOP_Afma6());
669 UInt32 HIPowerStatus;
671 bool firsttime =
true;
672 unsigned int nitermax = 10;
674 for (
unsigned int i = 0; i < nitermax; i++) {
675 Try(PrimitiveSTATUS_Afma6(NULL, NULL, &EStopStatus, NULL, NULL, NULL, &HIPowerStatus));
676 if (EStopStatus == ESTOP_AUTO) {
678 }
else if (EStopStatus == ESTOP_MANUAL) {
680 }
else if (EStopStatus == ESTOP_ACTIVATED) {
682 std::cout <<
"Emergency stop is activated! \n" 683 <<
"Check the emergency stop button and push the yellow " 684 "button before continuing." 688 fprintf(stdout,
"Remaining time %us \r", nitermax - i);
692 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
693 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
695 ShutDownConnection();
700 if (EStopStatus == ESTOP_ACTIVATED)
701 std::cout << std::endl;
703 if (EStopStatus == ESTOP_ACTIVATED) {
704 std::cout <<
"Sorry, cannot power on the robot." << std::endl;
708 if (HIPowerStatus == 0) {
709 fprintf(stdout,
"Power ON the Afma6 robot\n");
712 Try(PrimitivePOWERON_Afma6());
736 UInt32 HIPowerStatus;
737 Try(PrimitiveSTATUS_Afma6(NULL, NULL, NULL, NULL, NULL, NULL, &HIPowerStatus));
740 if (HIPowerStatus == 1) {
741 fprintf(stdout,
"Power OFF the Afma6 robot\n");
744 Try(PrimitivePOWEROFF_Afma6());
770 UInt32 HIPowerStatus;
771 Try(PrimitiveSTATUS_Afma6(NULL, NULL, NULL, NULL, NULL, NULL, &HIPowerStatus));
774 if (HIPowerStatus == 1) {
832 Try(PrimitiveACQ_POS_Afma6(position, ×tamp));
836 for (
unsigned int i = 0; i <
njoint; i++)
876 Try(PrimitiveACQ_POS_Afma6(position, ×tamp));
880 for (
unsigned int i = 0; i <
njoint; i++)
1013 for (
unsigned int i = 0; i < 3; i++) {
1014 position[i] = pose[i];
1015 position[i + 3] = rxyz[i];
1019 "Joint frame not implemented for pose positionning.");
1111 "Modification of the robot state");
1115 double _destination[6];
1123 Try(PrimitiveACQ_POS_Afma6(_q, ×tamp));
1126 for (
unsigned int i = 0; i <
njoint; i++)
1136 for (
unsigned int i = 0; i < 3; i++) {
1137 txyz[i] = position[i];
1138 rxyz[i] = position[i + 3];
1149 bool nearest =
true;
1152 for (
unsigned int i = 0; i <
njoint; i++) {
1153 _destination[i] = q[i];
1155 Try(PrimitiveMOVE_Afma6(_destination, positioningVelocity));
1156 Try(WaitState_Afma6(ETAT_ATTENTE_AFMA6, 1000));
1165 for (
unsigned int i = 0; i <
njoint; i++) {
1166 _destination[i] = position[i];
1168 Try(PrimitiveMOVE_Afma6(_destination, positioningVelocity));
1169 Try(WaitState_Afma6(ETAT_ATTENTE_AFMA6, 1000));
1176 for (
unsigned int i = 0; i < 3; i++) {
1177 txyz[i] = position[i];
1178 rxyz[i] = position[i + 3];
1186 bool nearest =
true;
1189 for (
unsigned int i = 0; i <
njoint; i++) {
1190 _destination[i] = q[i];
1192 Try(PrimitiveMOVE_Afma6(_destination, positioningVelocity));
1193 Try(WaitState_Afma6(ETAT_ATTENTE_AFMA6, 1000));
1202 vpERROR_TRACE(
"Positionning error. Mixt frame not implemented");
1204 "Mixt frame not implemented.");
1209 if (TryStt == InvalidPosition || TryStt == -1023)
1210 std::cout <<
" : Position out of range.\n";
1211 else if (TryStt < 0)
1212 std::cout <<
" : Unknown error (see Fabien).\n";
1213 else if (error == -1)
1214 std::cout <<
"Position out of range.\n";
1216 if (TryStt < 0 || error < 0) {
1292 const double pos3,
const double pos4,
const double pos5,
const double pos6)
1434 Try(PrimitiveACQ_POS_Afma6(_q, ×tamp));
1435 for (
unsigned int i = 0; i <
njoint; i++) {
1436 position[i] = _q[i];
1443 Try(PrimitiveACQ_POS_Afma6(_q, ×tamp));
1446 for (
unsigned int i = 0; i <
njoint; i++)
1459 for (
unsigned int i = 0; i < 3; i++) {
1460 position[i] = fMc[i][3];
1461 position[i + 3] = rxyz[i];
1466 vpERROR_TRACE(
"Cannot get position in mixt frame: not implemented");
1487 PrimitiveACQ_TIME_Afma6(×tamp);
1522 for (
unsigned int j = 0; j < 3; j++)
1523 RxyzVect[j] = posRxyz[j + 3];
1528 for (
unsigned int j = 0; j < 3; j++) {
1529 position[j] = posRxyz[j];
1530 position[j + 3] = RtuVect[j];
1617 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1619 "Cannot send a velocity to the robot " 1620 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1625 for (
unsigned int i = 0; i < 3; i++)
1627 for (
unsigned int i = 3; i < 6; i++)
1636 Try(PrimitiveMOVESPEED_CART_Afma6(vel_sat.
data, REPCAM_AFMA6));
1641 Try(PrimitiveMOVESPEED_Afma6(vel_sat.
data));
1645 Try(PrimitiveMOVESPEED_CART_Afma6(vel_sat.
data, REPFIX_AFMA6));
1649 Try(PrimitiveMOVESPEED_CART_Afma6(vel_sat.
data, REPMIX_AFMA6));
1654 "Case not taken in account.");
1661 if (TryStt == VelStopOnJoint) {
1662 Int32 axisInJoint[
njoint];
1663 PrimitiveSTATUS_Afma6(NULL, NULL, NULL, NULL, NULL, axisInJoint, NULL);
1664 for (
unsigned int i = 0; i <
njoint; i++) {
1666 std::cout <<
"\nWarning: Velocity control stopped: axis " << i + 1 <<
" on joint limit!" << std::endl;
1669 printf(
"\n%s(%d): Error %d", __FUNCTION__, TryLine, TryStt);
1670 if (TryString != NULL) {
1672 printf(
" Error sentence %s\n", TryString);
1749 Try(PrimitiveACQ_POS_Afma6(q, ×tamp));
1750 time_cur = timestamp;
1751 for (
unsigned int i = 0; i <
njoint; i++) {
1758 if (!first_time_getvel) {
1763 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1772 velocity = (q_cur - q_prev_getvel) / (time_cur - time_prev_getvel);
1778 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1793 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1801 for (
unsigned int i = 0; i < 3; i++) {
1803 velocity[i] = fMc_prev_getvel[i][3] - fMc_cur[i][3];
1805 velocity[i + 3] = thetaU[i];
1809 velocity /= (time_cur - time_prev_getvel);
1814 first_time_getvel =
false;
1818 fMc_prev_getvel = fMc_cur;
1821 q_prev_getvel = q_cur;
1824 time_prev_getvel = time_cur;
1964 std::ifstream fd(filename.c_str(), std::ios::in);
1966 if (!fd.is_open()) {
1971 std::string key(
"R:");
1972 std::string id(
"#AFMA6 - Position");
1973 bool pos_found =
false;
1978 while (std::getline(fd, line)) {
1981 if (!(line.compare(0,
id.size(), id) == 0)) {
1982 std::cout <<
"Error: this position file " << filename <<
" is not for Afma6 robot" << std::endl;
1986 if ((line.compare(0, 1,
"#") == 0)) {
1989 if ((line.compare(0, key.size(), key) == 0)) {
1992 if (chain.size() <
njoint + 1)
1994 if (chain.size() <
njoint + 1)
1997 std::istringstream ss(line);
2000 for (
unsigned int i = 0; i <
njoint; i++)
2015 std::cout <<
"Error: unable to find a position for Afma6 robot in " << filename << std::endl;
2050 fd = fopen(filename.c_str(),
"w");
2055 #AFMA6 - Position - Version 2.01\n\ 2058 # Joint position: X, Y, Z: translations in meters\n\ 2059 # A, B, C: rotations in degrees\n\ 2122 Try(PrimitiveGripper_Afma6(1));
2123 std::cout <<
"Open the gripper..." << std::endl;
2141 Try(PrimitiveGripper_Afma6(0));
2142 std::cout <<
"Close the gripper..." << std::endl;
2181 Try(PrimitiveACQ_POS_Afma6(q, ×tamp));
2182 for (
unsigned int i = 0; i <
njoint; i++) {
2189 if (!first_time_getdis) {
2193 c_prevMc_cur = fMc_prev_getdis.
inverse() * fMc_cur;
2203 for (
unsigned int i = 0; i < 3; i++) {
2204 displacement[i] = t[i];
2205 displacement[i + 3] = rxyz[i];
2211 displacement = q_cur - q_prev_getdis;
2216 std::cout <<
"getDisplacement() REFERENCE_FRAME not implemented\n";
2221 std::cout <<
"getDisplacement() MIXT_FRAME not implemented\n";
2226 first_time_getdis =
false;
2230 q_prev_getdis = q_cur;
2233 fMc_prev_getdis = fMc_cur;
2254 Int32 axisInJoint[
njoint];
2259 Try(PrimitiveSTATUS_Afma6(NULL, NULL, NULL, NULL, NULL, axisInJoint, NULL));
2260 for (
unsigned int i = 0; i <
njoint; i++) {
2261 if (axisInJoint[i]) {
2262 std::cout <<
"\nWarning: Velocity control stopped: axis " << i + 1 <<
" on joint limit!" << std::endl;
2263 jointsStatus[i] = axisInJoint[i];
2266 jointsStatus[i] = 0;
2279 #elif !defined(VISP_BUILD_SHARED_LIBS) 2282 void dummy_vpRobotAfma6(){};
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
Modelisation of Irisa's gantry robot named Afma6.
static vpColVector inverse(const vpHomogeneousMatrix &M)
Implementation of a matrix and operations on matrices.
vpRxyzVector buildFrom(const vpRotationMatrix &R)
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.
void set_eMc(const vpHomogeneousMatrix &eMc)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setVerbose(bool verbose)
double getMaxTranslationVelocity(void) const
int getInverseKinematics(const vpHomogeneousMatrix &fMc, vpColVector &q, const bool &nearest=true, const bool &verbose=false) const
void setPosition(const vpRobot::vpControlFrameType frame, const vpPoseVector &pose)
Initialize the position controller.
vpAfma6ToolType
List of possible tools that can be attached to the robot end-effector.
vpHomogeneousMatrix inverse() const
Class that defines a generic virtual robot.
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Type * data
Address of the first element of the data array.
void get_cMe(vpHomogeneousMatrix &_cMe) const
vpCameraParameters::vpCameraParametersProjType projModel
double getMaxRotationVelocity(void) const
void extract(vpRotationMatrix &R) const
double getPositioningVelocity(void)
vpHomogeneousMatrix get_fMc(const vpColVector &q) 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.
Implementation of a rotation matrix and operations on such kind of matrices.
static const vpAfma6ToolType defaultTool
Default tool attached to the robot end effector.
void get_cVe(vpVelocityTwistMatrix &_cVe) const
static bool readPosFile(const std::string &filename, vpColVector &q)
static bool savePosFile(const std::string &filename, const vpColVector &q)
Initialize the velocity controller.
virtual vpRobotStateType getRobotState(void) const
void move(const std::string &filename)
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpRotationMatrix buildFrom(const vpHomogeneousMatrix &M)
vpCameraParametersProjType
void get_fJe(vpMatrix &_fJe)
void get_eJe(const vpColVector &q, vpMatrix &eJe) const
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
void get_fJe(const vpColVector &q, vpMatrix &fJe) const
static double rad(double deg)
virtual void set_eMc(const vpHomogeneousMatrix &eMc)
static double deg(double rad)
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
Implementation of column vector and the associated operations.
Implementation of a pose vector and operations on poses.
void get_cMe(vpHomogeneousMatrix &cMe) const
Implementation of a rotation vector as Euler angle minimal representation.
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity)
vpMatrix fJe
robot Jacobian expressed in the robot reference frame available
Class that consider the case of a translation vector.
Implementation of a rotation vector as axis-angle minimal representation.
static const double defaultPositioningVelocity
void getDisplacement(vpRobot::vpControlFrameType frame, vpColVector &displacement)
void resize(const unsigned int i, const bool flagNullify=true)