39 #include <visp3/core/vpConfig.h> 41 #ifdef VISP_HAVE_VIPER650 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/vpThetaUVector.h> 52 #include <visp3/core/vpVelocityTwistMatrix.h> 53 #include <visp3/robot/vpRobot.h> 54 #include <visp3/robot/vpRobotException.h> 55 #include <visp3/robot/vpRobotViper650.h> 61 bool vpRobotViper650::m_robotAlreadyCreated =
false;
83 void emergencyStopViper650(
int signo)
85 std::cout <<
"Stop the Viper650 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_Viper650();
108 std::cout <<
"Robot was stopped\n";
113 fprintf(stdout,
"Application ");
115 kill(getpid(), SIGKILL);
199 signal(SIGINT, emergencyStopViper650);
200 signal(SIGBUS, emergencyStopViper650);
201 signal(SIGSEGV, emergencyStopViper650);
202 signal(SIGKILL, emergencyStopViper650);
203 signal(SIGQUIT, emergencyStopViper650);
207 std::cout <<
"Open communication with MotionBlox.\n";
219 vpRobotViper650::m_robotAlreadyCreated =
true;
255 m_q_prev_getvel.
resize(6);
257 m_time_prev_getvel = 0;
258 m_first_time_getvel =
true;
261 m_q_prev_getdis.
resize(6);
263 m_first_time_getdis =
true;
266 Try(InitializeConnection(
verbose_));
269 Try(InitializeNode_Viper650());
271 Try(PrimitiveRESET_Viper650());
274 Try(PrimitiveREMOVE_JOINT6_LIMITS_Viper650(0));
280 UInt32 HIPowerStatus;
282 Try(PrimitiveSTATUS_Viper650(NULL, NULL, &EStopStatus, NULL, NULL, NULL, &HIPowerStatus));
287 std::cout <<
"Robot status: ";
288 switch (EStopStatus) {
290 m_controlMode =
AUTO;
291 if (HIPowerStatus == 0)
292 std::cout <<
"Power is OFF" << std::endl;
294 std::cout <<
"Power is ON" << std::endl;
299 if (HIPowerStatus == 0)
300 std::cout <<
"Power is OFF" << std::endl;
302 std::cout <<
"Power is ON" << std::endl;
304 case ESTOP_ACTIVATED:
305 m_controlMode =
ESTOP;
306 std::cout <<
"Emergency stop is activated" << std::endl;
309 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
310 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
313 std::cout << std::endl;
331 if (TryStt == -20001)
332 printf(
"No connection detected. Check if the robot is powered on \n" 333 "and if the firewire link exist between the MotionBlox and this " 335 else if (TryStt == -675)
336 printf(
" Timeout enabling power...\n");
340 PrimitivePOWEROFF_Viper650();
342 ShutDownConnection();
344 std::cout <<
"Cannot open connection with the motionblox..." << std::endl;
428 for (
unsigned int i = 0; i < 3; i++) {
429 eMc_pose[i] =
etc[i];
430 eMc_pose[i + 3] =
erc[i];
433 Try(PrimitiveCONST_Viper650(eMc_pose));
508 for (
unsigned int i = 0; i < 3; i++) {
509 eMc_pose[i] =
etc[i];
510 eMc_pose[i + 3] =
erc[i];
513 Try(PrimitiveCONST_Viper650(eMc_pose));
574 for (
unsigned int i = 0; i < 3; i++) {
575 eMc_pose[i] =
etc[i];
576 eMc_pose[i + 3] =
erc[i];
579 Try(PrimitiveCONST_Viper650(eMc_pose));
604 for (
unsigned int i = 0; i < 3; i++) {
605 eMc_pose[i] =
etc[i];
606 eMc_pose[i + 3] =
erc[i];
609 Try(PrimitiveCONST_Viper650(eMc_pose));
636 for (
unsigned int i = 0; i < 3; i++) {
637 eMc_pose[i] =
etc[i];
638 eMc_pose[i + 3] =
erc[i];
641 Try(PrimitiveCONST_Viper650(eMc_pose));
665 UInt32 HIPowerStatus;
666 Try(PrimitiveSTATUS_Viper650(NULL, NULL, NULL, NULL, NULL, NULL, &HIPowerStatus));
677 ShutDownConnection();
679 vpRobotViper650::m_robotAlreadyCreated =
false;
699 Try(PrimitiveSTOP_Viper650());
706 std::cout <<
"Change the control mode from velocity to position control.\n";
707 Try(PrimitiveSTOP_Viper650());
717 std::cout <<
"Change the control mode from stop to velocity control.\n";
748 Try(PrimitiveSTOP_Viper650());
772 UInt32 HIPowerStatus;
774 bool firsttime =
true;
775 unsigned int nitermax = 10;
777 for (
unsigned int i = 0; i < nitermax; i++) {
778 Try(PrimitiveSTATUS_Viper650(NULL, NULL, &EStopStatus, NULL, NULL, NULL, &HIPowerStatus));
779 if (EStopStatus == ESTOP_AUTO) {
780 m_controlMode =
AUTO;
782 }
else if (EStopStatus == ESTOP_MANUAL) {
785 }
else if (EStopStatus == ESTOP_ACTIVATED) {
786 m_controlMode =
ESTOP;
788 std::cout <<
"Emergency stop is activated! \n" 789 <<
"Check the emergency stop button and push the yellow " 790 "button before continuing." 794 fprintf(stdout,
"Remaining time %us \r", nitermax - i);
798 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
799 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
801 ShutDownConnection();
806 if (EStopStatus == ESTOP_ACTIVATED)
807 std::cout << std::endl;
809 if (EStopStatus == ESTOP_ACTIVATED) {
810 std::cout <<
"Sorry, cannot power on the robot." << std::endl;
814 if (HIPowerStatus == 0) {
815 fprintf(stdout,
"Power ON the Viper650 robot\n");
818 Try(PrimitivePOWERON_Viper650());
842 UInt32 HIPowerStatus;
843 Try(PrimitiveSTATUS_Viper650(NULL, NULL, NULL, NULL, NULL, NULL, &HIPowerStatus));
846 if (HIPowerStatus == 1) {
847 fprintf(stdout,
"Power OFF the Viper650 robot\n");
850 Try(PrimitivePOWEROFF_Viper650());
876 UInt32 HIPowerStatus;
877 Try(PrimitiveSTATUS_Viper650(NULL, NULL, NULL, NULL, NULL, NULL, &HIPowerStatus));
880 if (HIPowerStatus == 1) {
940 Try(PrimitiveACQ_POS_J_Viper650(position, ×tamp));
944 for (
unsigned int i = 0; i <
njoint; i++)
973 Try(PrimitiveACQ_POS_Viper650(position, ×tamp));
977 for (
unsigned int i = 0; i <
njoint; i++)
1115 "Modification of the robot state");
1127 Try(PrimitiveACQ_POS_Viper650(q.
data, ×tamp));
1139 for (
unsigned int i = 0; i < 3; i++) {
1140 txyz[i] = position[i];
1141 rxyz[i] = position[i + 3];
1157 Try(PrimitiveMOVE_J_Viper650(destination.
data, m_positioningVelocity));
1158 Try(WaitState_Viper650(ETAT_ATTENTE_VIPER650, 1000));
1167 destination = position;
1173 Try(PrimitiveMOVE_J_Viper650(destination.
data, m_positioningVelocity));
1174 Try(WaitState_Viper650(ETAT_ATTENTE_VIPER650, 1000));
1179 vpRxyzVector rxyz(position[3], position[4], position[5]);
1183 for (
unsigned int i = 0; i < 3; i++) {
1184 destination[i] = position[i];
1187 int configuration = 0;
1191 Try(PrimitiveMOVE_C_Viper650(destination.
data, configuration, m_positioningVelocity));
1192 Try(WaitState_Viper650(ETAT_ATTENTE_VIPER650, 1000));
1198 "Mixt frame not implemented.");
1202 "Mixt frame not implemented.");
1207 if (TryStt == InvalidPosition || TryStt == -1023)
1208 std::cout <<
" : Position out of range.\n";
1210 else if (TryStt == -3019) {
1212 std::cout <<
" : Joint position out of range.\n";
1214 std::cout <<
" : Cartesian position leads to a joint position out of " 1216 }
else if (TryStt < 0)
1217 std::cout <<
" : Unknown error (see Fabien).\n";
1218 else if (error == -1)
1219 std::cout <<
"Position out of range.\n";
1221 if (TryStt < 0 || error < 0) {
1294 double pos3,
double pos4,
double pos5,
double pos6)
1445 Try(PrimitiveACQ_POS_J_Viper650(position.
data, ×tamp));
1453 Try(PrimitiveACQ_POS_J_Viper650(q.
data, ×tamp));
1464 for (
unsigned int i = 0; i < 3; i++) {
1465 position[i] = fMc[i][3];
1466 position[i + 3] = rxyz[i];
1525 for (
unsigned int j = 0; j < 3; j++)
1526 RxyzVect[j] = posRxyz[j + 3];
1531 for (
unsigned int j = 0; j < 3; j++) {
1532 position[j] = posRxyz[j];
1533 position[j + 3] = RtuVect[j];
1560 PrimitiveACQ_TIME_Viper650(×tamp);
1645 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1647 "Cannot send a velocity to the robot " 1648 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1662 for (
unsigned int i = 0; i < 3; i++)
1664 for (
unsigned int i = 3; i < 6; i++)
1677 for (
unsigned int i = 0; i < 6; i++)
1680 for (
unsigned int i = 0; i < 5; i++)
1695 Try(PrimitiveMOVESPEED_CART_Viper650(vel_sat.
data, REPCAM_VIPER650));
1705 Try(PrimitiveMOVESPEED_CART_Viper650(v_c.
data, REPCAM_VIPER650));
1713 Try(PrimitiveMOVESPEED_Viper650(vel_sat.
data));
1719 Try(PrimitiveMOVESPEED_CART_Viper650(vel_sat.
data, REPFIX_VIPER650));
1728 "Case not taken in account.");
1735 if (TryStt == VelStopOnJoint) {
1736 UInt32 axisInJoint[
njoint];
1737 PrimitiveSTATUS_Viper650(NULL, NULL, NULL, NULL, NULL, axisInJoint, NULL);
1738 for (
unsigned int i = 0; i <
njoint; i++) {
1740 std::cout <<
"\nWarning: Velocity control stopped: axis " << i + 1 <<
" on joint limit!" << std::endl;
1743 printf(
"\n%s(%d): Error %d", __FUNCTION__, TryLine, TryStt);
1744 if (TryString != NULL) {
1746 printf(
" Error sentence %s\n", TryString);
1829 Try(PrimitiveACQ_POS_J_Viper650(q_cur.
data, ×tamp));
1830 time_cur = timestamp;
1838 if (!m_first_time_getvel) {
1843 eMe = m_fMe_prev_getvel.
inverse() * fMe_cur;
1853 cMc = m_fMc_prev_getvel.
inverse() * fMc_cur;
1862 velocity = (q_cur - m_q_prev_getvel) / (time_cur - m_time_prev_getvel);
1868 cMc = m_fMc_prev_getvel.
inverse() * fMc_cur;
1883 cMc = m_fMc_prev_getvel.
inverse() * fMc_cur;
1891 for (
unsigned int i = 0; i < 3; i++) {
1893 velocity[i] = m_fMc_prev_getvel[i][3] - fMc_cur[i][3];
1895 velocity[i + 3] = thetaU[i];
1899 velocity /= (time_cur - m_time_prev_getvel);
1904 "vpRobotViper650::getVelocity() not implemented in end-effector"));
1908 m_first_time_getvel =
false;
1912 m_fMe_prev_getvel = fMe_cur;
1914 m_fMc_prev_getvel = fMc_cur;
1917 m_q_prev_getvel = q_cur;
1920 m_time_prev_getvel = time_cur;
2084 std::ifstream fd(filename.c_str(), std::ios::in);
2086 if (!fd.is_open()) {
2091 std::string key(
"R:");
2092 std::string id(
"#Viper650 - Position");
2093 bool pos_found =
false;
2098 while (std::getline(fd, line)) {
2101 if (!(line.compare(0,
id.size(), id) == 0)) {
2102 std::cout <<
"Error: this position file " << filename <<
" is not for Viper650 robot" << std::endl;
2106 if ((line.compare(0, 1,
"#") == 0)) {
2109 if ((line.compare(0, key.size(), key) == 0)) {
2112 if (chain.size() <
njoint + 1)
2114 if (chain.size() <
njoint + 1)
2117 std::istringstream ss(line);
2120 for (
unsigned int i = 0; i <
njoint; i++)
2133 std::cout <<
"Error: unable to find a position for Viper650 robot in " << filename << std::endl;
2167 fd = fopen(filename.c_str(),
"w");
2172 #Viper650 - Position - Version 1.00\n\ 2175 # Joint position in degrees\n\ 2241 Try(PrimitiveACQ_POS_Viper650(q, ×tamp));
2242 for (
unsigned int i = 0; i <
njoint; i++) {
2246 if (!m_first_time_getdis) {
2249 std::cout <<
"getDisplacement() CAMERA_FRAME not implemented\n";
2254 displacement = q_cur - m_q_prev_getdis;
2259 std::cout <<
"getDisplacement() REFERENCE_FRAME not implemented\n";
2264 std::cout <<
"getDisplacement() MIXT_FRAME not implemented\n";
2268 std::cout <<
"getDisplacement() END_EFFECTOR_FRAME not implemented\n";
2273 m_first_time_getdis =
false;
2277 m_q_prev_getdis = q_cur;
2303 Try(PrimitiveTFS_BIAS_Viper650());
2360 Try(PrimitiveTFS_ACQ_Viper650(H.
data));
2412 Try(PrimitiveTFS_ACQ_Viper650(H.
data));
2432 Try(PrimitiveREMOVE_JOINT6_LIMITS_Viper650(0));
2433 std::cout <<
"Enable joint limits on axis 6..." << std::endl;
2454 Try(PrimitiveREMOVE_JOINT6_LIMITS_Viper650(1));
2455 std::cout <<
"Warning: Disable joint limits on axis 6..." << std::endl;
2500 m_maxRotationVelocity_joint6 = w6_max;
2522 Try(PrimitivePneumaticGripper_Viper650(1));
2523 std::cout <<
"Open the pneumatic gripper..." << std::endl;
2540 Try(PrimitivePneumaticGripper_Viper650(0));
2541 std::cout <<
"Close the pneumatic gripper..." << std::endl;
2548 #elif !defined(VISP_BUILD_SHARED_LIBS) 2551 void dummy_vpRobotViper650(){};
static vpColVector inverse(const vpHomogeneousMatrix &M)
Implementation of a matrix and operations on matrices.
vpRxyzVector buildFrom(const vpRotationMatrix &R)
VISP_EXPORT int wait(double t0, double t)
Error that can be emited by the vpRobot class and its derivates.
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity)
void get_fJe(const vpColVector &q, vpMatrix &fJe) const
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
virtual ~vpRobotViper650(void)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setVerbose(bool verbose)
double getMaxTranslationVelocity(void) const
vpCameraParameters::vpCameraParametersProjType projModel
double maxRotationVelocity
void setMaxRotationVelocityJoint6(double w6_max)
Initialize the position controller.
error that can be emited by ViSP classes.
vpHomogeneousMatrix inverse() const
Class that defines a generic virtual robot.
Automatic control mode (default).
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 setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position)
double getMaxRotationVelocity(void) const
void extract(vpRotationMatrix &R) const
static bool savePosFile(const std::string &filename, const vpColVector &q)
vpThetaUVector buildFrom(const vpHomogeneousMatrix &M)
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
void setMaxRotationVelocity(double maxVr)
Implementation of a rotation matrix and operations on such kind of matrices.
vpHomogeneousMatrix get_fMc(const vpColVector &q) const
void biasForceTorqueSensor() const
static const double m_defaultPositioningVelocity
static const vpToolType defaultTool
Default tool attached to the robot end effector.
void setPositioningVelocity(double velocity)
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
Initialize the velocity controller.
Emergency stop activated.
virtual vpRobotStateType getRobotState(void) const
bool getPowerState() const
virtual void set_eMc(const vpHomogeneousMatrix &eMc_)
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpCameraParametersProjType
VISP_EXPORT void sleepMs(double t)
Modelisation of the ADEPT Viper 650 robot.
unsigned int getInverseKinematics(const vpHomogeneousMatrix &fMc, vpColVector &q, const bool &verbose=false) const
void get_cMe(vpHomogeneousMatrix &cMe) const
vpToolType
List of possible tools that can be attached to the robot end-effector.
static double rad(double deg)
void enableJoint6Limits() const
void get_fJe(vpMatrix &fJe)
Stops robot motion especially in velocity and acceleration control.
double getPositioningVelocity(void) const
void resize(unsigned int i, bool flagNullify=true)
void get_fMe(const vpColVector &q, vpHomogeneousMatrix &fMe) const
static double deg(double rad)
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
vpColVector getForceTorque() const
Implementation of column vector and the associated operations.
Implementation of a pose vector and operations on poses.
void move(const std::string &filename)
Implementation of a rotation vector as Euler angle minimal representation.
void disableJoint6Limits() const
void setMaxRotationVelocity(double w_max)
static bool readPosFile(const std::string &filename, vpColVector &q)
void get_cMe(vpHomogeneousMatrix &cMe) const
Implementation of a rotation vector as Euler angle minimal representation.
void get_cVe(vpVelocityTwistMatrix &cVe) const
double getMaxRotationVelocityJoint6() const
void closeGripper() const
void getDisplacement(vpRobot::vpControlFrameType frame, vpColVector &displacement)
Function not implemented.
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 unsigned int njoint
Number of joint.
void get_eJe(const vpColVector &q, vpMatrix &eJe) const
void get_eJe(vpMatrix &eJe)
void set_eMc(const vpHomogeneousMatrix &eMc_)
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)