36 #include <visp3/core/vpConfig.h>
38 #if defined(VISP_HAVE_UR_RTDE)
40 #include <visp3/core/vpIoTools.h>
41 #include <visp3/robot/vpRobotUniversalRobots.h>
70 : m_rtde_receive(nullptr), m_rtde_control(nullptr), m_eMc()
85 m_rtde_receive = std::make_shared<ur_rtde::RTDEReceiveInterface>(ur_address);
88 m_rtde_control = std::make_shared<ur_rtde::RTDEControlInterface>(ur_address);
91 m_db_client = std::make_shared<ur_rtde::DashboardClient>(ur_address);
181 "Cannot get UR robot forward kinematics: joint position vector is not 6-dim (%d)", q.
size()));
190 std::vector<double> tcp_pose =
m_rtde_control->getForwardKinematics(q_std);
193 for (
size_t i = 0; i < 6; i++) {
194 f_P_e[i] = tcp_pose[i];
327 std::vector<double> tcp_pose =
m_rtde_receive->getActualTCPPose();
329 for (
size_t i = 0; i < tcp_pose.size(); i++) {
330 position[i] = tcp_pose[i];
336 std::vector<double> tcp_pose =
m_rtde_receive->getActualTCPPose();
338 for (
size_t i = 0; i < tcp_pose.size(); i++) {
339 fPe[i] = tcp_pose[i];
346 for (
size_t i = 0; i < 6; i++) {
347 position[i] = fPc[i];
380 for (
size_t i = 0; i < 6; i++) {
381 pose[i] = position[i];
470 if (position.
size() != 6) {
472 "Cannot set UR robot position: position vector is not a 6-dim vector (%d)", position.
size()));
476 std::cout <<
"Robot is not in position-based control. "
477 "Modification of the robot state"
484 std::vector<double> new_q = position.
toStdVector();
489 std::vector<double> new_pose = position.
toStdVector();
507 "Cannot move the robot to a cartesian position. Only joint positioning is implemented"));
606 "Cannot send a velocity to the robot: robot is not in velocity control state "
607 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
622 for (
unsigned int i = 0; i < 3; i++)
624 for (
unsigned int i = 3; i < 6; i++)
640 double dt = 1.0 / 1000;
641 double acceleration = 0.5;
645 double dt = 1.0 / 1000;
646 double acceleration = 0.25;
650 double dt = 1.0 / 1000;
651 double acceleration = 0.25;
653 m_rtde_control->speedL((fVe * vel_sat).toStdVector(), acceleration, dt);
656 double dt = 1.0 / 1000;
657 double acceleration = 0.25;
663 "Cannot move the robot in velocity in the specified frame: not implemented"));
740 std::ifstream fd(filename.c_str(), std::ios::in);
747 std::string key(
"R:");
748 std::string id(
"#UR - Joint position file");
749 bool pos_found =
false;
751 size_t njoints =
static_cast<size_t>(
nDof);
755 while (std::getline(fd, line)) {
758 if (!(line.compare(0,
id.size(),
id) == 0)) {
759 std::cout <<
"Error: this position file " << filename <<
" is not for Universal Robots" << std::endl;
763 if ((line.compare(0, 1,
"#") == 0)) {
766 if ((line.compare(0, key.size(), key) == 0)) {
769 if (chain.size() < njoints + 1)
771 if (chain.size() < njoints + 1)
774 std::istringstream ss(line);
777 for (
unsigned int i = 0; i < njoints; i++)
785 for (
unsigned int i = 0; i < njoints; i++) {
792 std::cout <<
"Error: unable to find a position for UR robot in " << filename << std::endl;
820 fd = fopen(filename.c_str(),
"w");
824 fprintf(fd,
"#UR - Joint position file\n"
826 "# R: q1 q2 q3 q4 q5 q6\n"
827 "# with joint positions q1 to q6 expressed in degrees\n"
870 std::cout <<
"Change the control mode from stop to velocity control.\n";
881 #elif !defined(VISP_BUILD_SHARED_LIBS)
883 void dummy_vpRobotUniversalRobots() { };
unsigned int size() const
Return the number of elements of the 2D array.
Implementation of column vector and the associated operations.
vpColVector extract(unsigned int r, unsigned int colsize) const
std::vector< double > toStdVector() const
void resize(unsigned int i, bool flagNullify=true)
error that can be emitted by ViSP classes.
@ functionNotImplementedError
Function not implemented.
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
static double rad(double deg)
static double deg(double rad)
Implementation of a pose vector and operations on poses.
std::vector< double > toStdVector() const
Error that can be emitted by the vpRobot class and its derivatives.
@ wrongStateError
Wrong robot state.
double m_max_joint_acceleration
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
vpHomogeneousMatrix get_eMc() const
vpHomogeneousMatrix m_eMc
double m_positioningVelocity
void setPositioningVelocity(double velocity)
std::string getRobotModel() const
vpHomogeneousMatrix get_fMc()
vpHomogeneousMatrix get_fMe()
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) VP_OVERRIDE
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
double m_max_linear_speed
void move(const std::string &filename, double velocity_percentage=10.)
virtual ~vpRobotUniversalRobots()
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) VP_OVERRIDE
void connect(const std::string &ur_address)
double m_max_linear_acceleration
bool savePosFile(const std::string &filename, const vpColVector &q)
void set_eMc(const vpHomogeneousMatrix &eMc)
std::shared_ptr< ur_rtde::DashboardClient > m_db_client
vpRobot::vpControlFrameType m_vel_control_frame
void getForceTorque(const vpRobot::vpControlFrameType frame, vpColVector &force)
std::shared_ptr< ur_rtde::RTDEReceiveInterface > m_rtde_receive
std::shared_ptr< ur_rtde::RTDEControlInterface > m_rtde_control
std::string getPolyScopeVersion()
bool readPosFile(const std::string &filename, vpColVector &q)
int nDof
number of degrees of freedom
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
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
double getMaxTranslationVelocity(void) const
Implementation of a rotation vector as axis-angle minimal representation.
Class that consider the case of a translation vector.