34#include <visp3/core/vpConfig.h>
43#include <visp3/core/vpDebug.h>
44#include <visp3/core/vpExponentialMap.h>
45#include <visp3/core/vpIoTools.h>
46#include <visp3/core/vpRotationMatrix.h>
47#include <visp3/core/vpThetaUVector.h>
48#include <visp3/core/vpVelocityTwistMatrix.h>
49#include <visp3/robot/vpRobotAfma6.h>
50#include <visp3/robot/vpRobotException.h>
57bool vpRobotAfma6::robotAlreadyCreated =
false;
79void emergencyStopAfma6(
int signo)
81 std::cout <<
"Stop the Afma6 application by signal (" << signo <<
"): " <<
static_cast<char>(7);
84 std::cout <<
"SIGINT (stop by ^C) " << std::endl;
87 std::cout <<
"SIGBUS (stop due to a bus error) " << std::endl;
90 std::cout <<
"SIGSEGV (stop due to a segmentation fault) " << std::endl;
93 std::cout <<
"SIGKILL (stop by CTRL \\) " << std::endl;
96 std::cout <<
"SIGQUIT " << std::endl;
99 std::cout << signo << std::endl;
103 PrimitiveSTOP_Afma6();
104 std::cout <<
"Robot was stopped\n";
109 fprintf(stdout,
"Application ");
111 kill(getpid(), SIGKILL);
177 signal(SIGINT, emergencyStopAfma6);
178 signal(SIGBUS, emergencyStopAfma6);
179 signal(SIGSEGV, emergencyStopAfma6);
180 signal(SIGKILL, emergencyStopAfma6);
181 signal(SIGQUIT, emergencyStopAfma6);
185 std::cout <<
"Open communication with MotionBlox.\n";
196 vpRobotAfma6::robotAlreadyCreated =
true;
229 q_prev_getvel.resize(6);
231 time_prev_getvel = 0;
232 first_time_getvel =
true;
235 q_prev_getdis.resize(6);
237 first_time_getdis =
true;
240 Try(InitializeConnection(
verbose_));
243 Try(InitializeNode_Afma6());
245 Try(PrimitiveRESET_Afma6());
251 UInt32 HIPowerStatus;
253 Try(PrimitiveSTATUS_Afma6(
nullptr,
nullptr, &EStopStatus,
nullptr,
nullptr,
nullptr, &HIPowerStatus));
258 std::cout <<
"Robot status: ";
259 switch (EStopStatus) {
262 if (HIPowerStatus == 0)
263 std::cout <<
"Power is OFF" << std::endl;
265 std::cout <<
"Power is ON" << std::endl;
267 case ESTOP_ACTIVATED:
268 std::cout <<
"Emergency stop is activated" << std::endl;
271 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
272 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
275 std::cout << std::endl;
289 if (TryStt == -20001)
290 printf(
"No connection detected. Check if the robot is powered on \n"
291 "and if the firewire link exist between the MotionBlox and this "
293 else if (TryStt == -675)
294 printf(
" Timeout enabling power...\n");
298 PrimitivePOWEROFF_Afma6();
300 ShutDownConnection();
302 std::cout <<
"Cannot open connection with the motionblox..." << std::endl;
357 for (
unsigned int i = 0; i < 3; i++) {
358 eMc_pose[i] =
_etc[i];
359 eMc_pose[i + 3] =
_erc[i];
362 Try(PrimitiveCAMERA_CONST_Afma6(eMc_pose));
396 for (
unsigned int i = 0; i < 3; i++) {
397 eMc_pose[i] =
_etc[i];
398 eMc_pose[i + 3] =
_erc[i];
401 Try(PrimitiveCAMERA_CONST_Afma6(eMc_pose));
458 for (
unsigned int i = 0; i < 3; i++) {
459 eMc_pose[i] =
_etc[i];
460 eMc_pose[i + 3] =
_erc[i];
463 Try(PrimitiveCAMERA_CONST_Afma6(eMc_pose));
540 for (
unsigned int i = 0; i < 3; i++) {
541 eMc_pose[i] =
_etc[i];
542 eMc_pose[i + 3] =
_erc[i];
545 Try(PrimitiveCAMERA_CONST_Afma6(eMc_pose));
572 UInt32 HIPowerStatus;
573 Try(PrimitiveSTATUS_Afma6(
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, &HIPowerStatus));
584 ShutDownConnection();
586 vpRobotAfma6::robotAlreadyCreated =
false;
605 Try(PrimitiveSTOP_Afma6());
611 std::cout <<
"Change the control mode from velocity to position control.\n";
612 Try(PrimitiveSTOP_Afma6());
623 std::cout <<
"Change the control mode from stop to velocity control.\n";
651 Try(PrimitiveSTOP_Afma6());
675 UInt32 HIPowerStatus;
677 bool firsttime =
true;
678 unsigned int nitermax = 10;
680 for (
unsigned int i = 0; i < nitermax; i++) {
681 Try(PrimitiveSTATUS_Afma6(
nullptr,
nullptr, &EStopStatus,
nullptr,
nullptr,
nullptr, &HIPowerStatus));
682 if (EStopStatus == ESTOP_AUTO) {
685 else if (EStopStatus == ESTOP_MANUAL) {
688 else if (EStopStatus == ESTOP_ACTIVATED) {
690 std::cout <<
"Emergency stop is activated! \n"
691 <<
"Check the emergency stop button and push the yellow "
692 "button before continuing."
696 fprintf(stdout,
"Remaining time %us \r", nitermax - i);
701 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
702 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
704 ShutDownConnection();
709 if (EStopStatus == ESTOP_ACTIVATED)
710 std::cout << std::endl;
712 if (EStopStatus == ESTOP_ACTIVATED) {
713 std::cout <<
"Sorry, cannot power on the robot." << std::endl;
717 if (HIPowerStatus == 0) {
718 fprintf(stdout,
"Power ON the Afma6 robot\n");
721 Try(PrimitivePOWERON_Afma6());
745 UInt32 HIPowerStatus;
746 Try(PrimitiveSTATUS_Afma6(
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, &HIPowerStatus));
749 if (HIPowerStatus == 1) {
750 fprintf(stdout,
"Power OFF the Afma6 robot\n");
753 Try(PrimitivePOWEROFF_Afma6());
779 UInt32 HIPowerStatus;
780 Try(PrimitiveSTATUS_Afma6(
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, &HIPowerStatus));
783 if (HIPowerStatus == 1) {
841 Try(PrimitiveACQ_POS_Afma6(position, ×tamp));
845 for (
unsigned int i = 0; i <
njoint; i++)
886 Try(PrimitiveACQ_POS_Afma6(position, ×tamp));
890 for (
unsigned int i = 0; i <
njoint; i++)
1023 R.buildFrom(pose[3], pose[4], pose[5]);
1026 for (
unsigned int i = 0; i < 3; i++) {
1027 position[i] = pose[i];
1028 position[i + 3] = rxyz[i];
1032 "Joint frame not implemented for pose positioning.");
1127 "Modification of the robot state");
1131 double _destination[6];
1139 Try(PrimitiveACQ_POS_Afma6(_q, ×tamp));
1142 for (
unsigned int i = 0; i <
njoint; i++)
1152 for (
unsigned int i = 0; i < 3; i++) {
1153 txyz[i] = position[i];
1154 rxyz[i] = position[i + 3];
1165 bool nearest =
true;
1168 for (
unsigned int i = 0; i <
njoint; i++) {
1169 _destination[i] = q[i];
1171 Try(PrimitiveMOVE_Afma6(_destination, positioningVelocity));
1172 Try(WaitState_Afma6(ETAT_ATTENTE_AFMA6, 1000));
1182 for (
unsigned int i = 0; i <
njoint; i++) {
1183 _destination[i] = position[i];
1185 Try(PrimitiveMOVE_Afma6(_destination, positioningVelocity));
1186 Try(WaitState_Afma6(ETAT_ATTENTE_AFMA6, 1000));
1193 for (
unsigned int i = 0; i < 3; i++) {
1194 txyz[i] = position[i];
1195 rxyz[i] = position[i + 3];
1203 bool nearest =
true;
1206 for (
unsigned int i = 0; i <
njoint; i++) {
1207 _destination[i] = q[i];
1209 Try(PrimitiveMOVE_Afma6(_destination, positioningVelocity));
1210 Try(WaitState_Afma6(ETAT_ATTENTE_AFMA6, 1000));
1221 "Mixt frame not implemented.");
1225 "end-effector frame not implemented.");
1230 if (TryStt == InvalidPosition || TryStt == -1023)
1231 std::cout <<
" : Position out of range.\n";
1232 else if (TryStt < 0)
1233 std::cout <<
" : Unknown error (see Fabien).\n";
1234 else if (error == -1)
1235 std::cout <<
"Position out of range.\n";
1237 if (TryStt < 0 || error < 0) {
1315 double pos4,
double pos5,
double pos6)
1461 Try(PrimitiveACQ_POS_Afma6(_q, ×tamp));
1462 for (
unsigned int i = 0; i <
njoint; i++) {
1463 position[i] = _q[i];
1470 Try(PrimitiveACQ_POS_Afma6(_q, ×tamp));
1473 for (
unsigned int i = 0; i <
njoint; i++)
1486 for (
unsigned int i = 0; i < 3; i++) {
1487 position[i] = fMc[i][3];
1488 position[i + 3] = rxyz[i];
1517 PrimitiveACQ_TIME_Afma6(×tamp);
1552 for (
unsigned int j = 0; j < 3; j++)
1553 RxyzVect[j] = posRxyz[j + 3];
1558 for (
unsigned int j = 0; j < 3; j++) {
1559 position[j] = posRxyz[j];
1560 position[j + 3] = RtuVect[j];
1647 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1649 "Cannot send a velocity to the robot "
1650 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1655 for (
unsigned int i = 0; i < 3; i++)
1657 for (
unsigned int i = 3; i < 6; i++)
1666 Try(PrimitiveMOVESPEED_CART_Afma6(vel_sat.
data, REPCAM_AFMA6));
1676 Try(PrimitiveMOVESPEED_CART_Afma6(v_c.
data, REPCAM_AFMA6));
1681 Try(PrimitiveMOVESPEED_Afma6(vel_sat.
data));
1685 Try(PrimitiveMOVESPEED_CART_Afma6(vel_sat.
data, REPFIX_AFMA6));
1689 Try(PrimitiveMOVESPEED_CART_Afma6(vel_sat.
data, REPMIX_AFMA6));
1694 "Case not taken in account.");
1701 if (TryStt == VelStopOnJoint) {
1702 Int32 axisInJoint[
njoint];
1703 PrimitiveSTATUS_Afma6(
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, axisInJoint,
nullptr);
1704 for (
unsigned int i = 0; i <
njoint; i++) {
1706 std::cout <<
"\nWarning: Velocity control stopped: axis " << i + 1 <<
" on joint limit!" << std::endl;
1710 printf(
"\n%s(%d): Error %d", __FUNCTION__, TryLine, TryStt);
1711 if (TryString !=
nullptr) {
1713 printf(
" Error sentence %s\n", TryString);
1791 Try(PrimitiveACQ_POS_Afma6(q, ×tamp));
1792 time_cur = timestamp;
1793 for (
unsigned int i = 0; i <
njoint; i++) {
1800 if (!first_time_getvel) {
1805 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1814 velocity = (q_cur - q_prev_getvel) / (time_cur - time_prev_getvel);
1820 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1835 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1843 for (
unsigned int i = 0; i < 3; i++) {
1845 velocity[i] = fMc_prev_getvel[i][3] - fMc_cur[i][3];
1847 velocity[i + 3] = thetaU[i];
1851 velocity /= (time_cur - time_prev_getvel);
1856 "vpRobotAfma6::getVelocity() not implemented in end-effector"));
1861 first_time_getvel =
false;
1865 fMc_prev_getvel = fMc_cur;
1868 q_prev_getvel = q_cur;
1871 time_prev_getvel = time_cur;
2011 std::ifstream fd(filename.c_str(), std::ios::in);
2013 if (!fd.is_open()) {
2018 std::string key(
"R:");
2019 std::string id(
"#AFMA6 - Position");
2020 bool pos_found =
false;
2025 while (std::getline(fd, line)) {
2028 if (!(line.compare(0,
id.size(),
id) == 0)) {
2029 std::cout <<
"Error: this position file " << filename <<
" is not for Afma6 robot" << std::endl;
2033 if ((line.compare(0, 1,
"#") == 0)) {
2036 if ((line.compare(0, key.size(), key) == 0)) {
2039 if (chain.size() <
njoint + 1)
2041 if (chain.size() <
njoint + 1)
2044 std::istringstream ss(line);
2047 for (
unsigned int i = 0; i <
njoint; i++)
2062 std::cout <<
"Error: unable to find a position for Afma6 robot in " << filename << std::endl;
2097 fd = fopen(filename.c_str(),
"w");
2102#AFMA6 - Position - Version 2.01\n\
2105# Joint position: X, Y, Z: translations in meters\n\
2106# A, B, C: rotations in degrees\n\
2169 Try(PrimitiveGripper_Afma6(1));
2170 std::cout <<
"Open the gripper..." << std::endl;
2188 Try(PrimitiveGripper_Afma6(0));
2189 std::cout <<
"Close the gripper..." << std::endl;
2228 Try(PrimitiveACQ_POS_Afma6(q, ×tamp));
2229 for (
unsigned int i = 0; i <
njoint; i++) {
2236 if (!first_time_getdis) {
2240 c_prevMc_cur = fMc_prev_getdis.
inverse() * fMc_cur;
2250 for (
unsigned int i = 0; i < 3; i++) {
2251 displacement[i] = t[i];
2252 displacement[i + 3] = rxyz[i];
2258 displacement = q_cur - q_prev_getdis;
2263 std::cout <<
"getDisplacement() REFERENCE_FRAME not implemented\n";
2268 std::cout <<
"getDisplacement() MIXT_FRAME not implemented\n";
2272 std::cout <<
"getDisplacement() END_EFFECTOR_FRAME not implemented\n";
2278 first_time_getdis =
false;
2282 q_prev_getdis = q_cur;
2285 fMc_prev_getdis = fMc_cur;
2306 Int32 axisInJoint[
njoint];
2311 Try(PrimitiveSTATUS_Afma6(
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, axisInJoint,
nullptr));
2312 for (
unsigned int i = 0; i <
njoint; i++) {
2313 if (axisInJoint[i]) {
2314 std::cout <<
"\nWarning: Velocity control stopped: axis " << i + 1 <<
" on joint limit!" << std::endl;
2315 jointsStatus[i] = axisInJoint[i];
2319 jointsStatus[i] = 0;
2332#elif !defined(VISP_BUILD_SHARED_LIBS)
2334void dummy_vpRobotAfma6() { }
virtual void set_eMc(const vpHomogeneousMatrix &eMc)
static const unsigned int njoint
Number of joint.
int getInverseKinematics(const vpHomogeneousMatrix &fMc, vpColVector &q, const bool &nearest=true, const bool &verbose=false) const
void get_cMe(vpHomogeneousMatrix &cMe) const
void setToolType(vpAfma6::vpAfma6ToolType tool)
Set the current tool type.
static const vpAfma6ToolType defaultTool
Default tool attached to the robot end effector.
vpHomogeneousMatrix get_fMc(const vpColVector &q) const
vpCameraParameters::vpCameraParametersProjType projModel
void get_eJe(const vpColVector &q, vpMatrix &eJe) const
void get_fJe(const vpColVector &q, vpMatrix &fJe) const
vpAfma6ToolType
List of possible tools that can be attached to the robot end-effector.
Type * data
Address of the first element of the data array.
vpCameraParametersProjType
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
error that can be emitted by ViSP classes.
@ functionNotImplementedError
Function not implemented.
static vpColVector inverse(const vpHomogeneousMatrix &M)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
void extract(vpRotationMatrix &R) const
static double rad(double deg)
static double deg(double rad)
Implementation of a matrix and operations on matrices.
Implementation of a pose vector and operations on poses.
void get_cVe(vpVelocityTwistMatrix &_cVe) const
bool checkJointLimits(vpColVector &jointsStatus)
void get_eJe(vpMatrix &_eJe) VP_OVERRIDE
static bool savePosFile(const std::string &filename, const vpColVector &q)
void setPosition(const vpRobot::vpControlFrameType frame, const vpPoseVector &pose)
void get_fJe(vpMatrix &_fJe) VP_OVERRIDE
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
static const double defaultPositioningVelocity
void get_cMe(vpHomogeneousMatrix &_cMe) const
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) VP_OVERRIDE
void getDisplacement(vpRobot::vpControlFrameType frame, vpColVector &displacement)
double getPositioningVelocity(void)
void set_eMc(const vpHomogeneousMatrix &eMc)
virtual ~vpRobotAfma6(void)
void move(const std::string &filename)
void setPositioningVelocity(double velocity)
static bool readPosFile(const std::string &filename, vpColVector &q)
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) VP_OVERRIDE
Error that can be emitted by the vpRobot class and its derivatives.
@ wrongStateError
Wrong robot state.
@ constructionError
Error from constructor.
@ positionOutOfRangeError
Position is out of range.
@ lowLevelError
Error thrown by the low level sdk.
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
void setVerbose(bool verbose)
virtual vpRobotStateType getRobotState(void) const
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
@ STATE_POSITION_CONTROL
Initialize the position controller.
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
@ STATE_STOP
Stops robot motion especially in velocity and acceleration control.
double getMaxRotationVelocity(void) const
vpMatrix fJe
robot Jacobian expressed in the robot reference frame available
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
double getMaxTranslationVelocity(void) const
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as Euler angle minimal representation.
vpRxyzVector & buildFrom(const vpRotationMatrix &R)
Implementation of a rotation vector as axis-angle minimal representation.
vpThetaUVector & buildFrom(const vpHomogeneousMatrix &M)
Class that consider the case of a translation vector.
vpVelocityTwistMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)