41 #include <visp3/core/vpException.h>
42 #include <visp3/robot/vpVirtuose.h>
44 #ifdef VISP_HAVE_VIRTUOSE
52 : m_virtContext(nullptr), m_ip_port(
"localhost#5000"), m_verbose(false), m_apiMajorVersion(0), m_apiMinorVersion(0),
53 m_ctrlMajorVersion(0), m_ctrlMinorVersion(0), m_typeCommand(COMMAND_TYPE_IMPEDANCE), m_indexType(INDEXING_ALL),
54 m_is_init(false), m_period(0.001f), m_njoints(6)
84 ss << ip <<
"#" << port;
98 if (force.
size() != 6) {
100 "Cannot apply a force feedback (dim %d) to the haptic "
101 "device that is not 6-dimension",
108 for (
unsigned int i = 0; i < 6; i++)
109 virtforce[i] = (
float)force[i];
140 float articular_position_[20] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
142 if (virtGetArticularPosition(
m_virtContext, articular_position_)) {
148 for (
unsigned int i = 0; i <
m_njoints; i++)
149 articularPosition[i] = articular_position_[i];
151 return articularPosition;
163 float articular_velocity_[20] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
165 if (virtGetArticularSpeed(
m_virtContext, articular_velocity_)) {
172 for (
unsigned int i = 0; i <
m_njoints; i++)
173 articularVelocity[i] = articular_velocity_[i];
175 return articularVelocity;
201 for (
int i = 0; i < 3; i++)
202 translation[i] = position_[i];
203 for (
int i = 0; i < 4; i++)
204 quaternion[i] = position_[3 + i];
236 for (
int i = 0; i < 3; i++)
237 translation[i] = position_[i];
238 for (
int i = 0; i < 4; i++)
239 quaternion[i] = position_[3 + i];
258 VirtCommandType type;
282 return (deadman ?
true :
false);
301 return (emergencyStop ?
true :
false);
321 for (
unsigned int i = 0; i < 6; i++)
322 force[i] = force_[i];
400 for (
int i = 0; i < 3; i++)
401 translation[i] = position_[i];
402 for (
int i = 0; i < 4; i++)
403 quaternion[i] = position_[3 + i];
434 for (
int i = 0; i < 3; i++)
435 translation[i] = position_[i];
436 for (
int i = 0; i < 4; i++)
437 quaternion[i] = position_[3 + i];
463 virtGetErrorMessage(err)));
465 for (
unsigned int i = 0; i < 6; i++)
491 for (
int i = 0; i < 3; i++)
492 translation[i] = position_[i];
493 for (
int i = 0; i < 4; i++)
494 quaternion[i] = position_[3 + i];
514 return (power ?
true :
false);
535 for (
unsigned int i = 0; i < 6; i++)
553 "Cannot open communication with haptic device using %s: %s. Check ip and port values",
554 m_ip_port.c_str(), virtGetErrorMessage(err)));
560 virtGetErrorMessage(err)));
579 float articular_position_[20] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
581 if (virtGetArticularPosition(
m_virtContext, articular_position_)) {
588 for (
unsigned int i =
m_njoints; i < 20; i++) {
590 if (std::fabs(articular_position_[i]) <= std::numeric_limits<float>::epsilon()) {
612 "Cannot apply an articular force feedback (dim %d) to "
613 "the haptic device that is not 6-dimension",
614 articularForce.
size()));
617 float *articular_force =
new float[
m_njoints];
618 for (
unsigned int i = 0; i <
m_njoints; i++)
619 articular_force[i] = (
float)articularForce[i];
622 delete[] articular_force;
627 delete[] articular_force;
643 "Cannot send an articular position command (dim %d) to "
644 "the haptic device that is not %d-dimension",
648 float *articular_position =
new float[
m_njoints];
649 for (
unsigned int i = 0; i <
m_njoints; i++)
650 articular_position[i] = (
float)articularPosition[i];
652 if (virtSetArticularPosition(
m_virtContext, articular_position)) {
654 delete[] articular_position;
657 delete[] articular_position;
673 "Cannot send an articular velocity command (dim %d) to "
674 "the haptic device that is not %d-dimension",
678 float *articular_velocity =
new float[
m_njoints];
679 for (
unsigned int i = 0; i <
m_njoints; i++)
680 articular_velocity[i] = (
float)articularVelocity[i];
682 if (virtSetArticularSpeed(
m_virtContext, articular_velocity)) {
684 delete[] articular_velocity;
687 delete[] articular_velocity;
708 for (
int i = 0; i < 3; i++)
709 position_[i] = (
float)translation[i];
710 for (
int i = 0; i < 4; i++)
711 position_[3 + i] = (
float)quaternion[i];
753 if (force.
size() != 6) {
755 "Cannot apply a force feedback (dim %d) to the haptic "
756 "device that is not 6-dimension",
761 for (
unsigned int i = 0; i < 6; i++)
762 virtforce[i] = (
float)force[i];
831 for (
int i = 0; i < 3; i++)
832 position_[i] = (
float)translation[i];
833 for (
int i = 0; i < 4; i++)
834 position_[3 + i] = (
float)quaternion[i];
911 for (
int i = 0; i < 3; i++)
912 position_[i] = (
float)translation[i];
913 for (
int i = 0; i < 4; i++)
914 position_[3 + i] = (
float)quaternion[i];
957 if (virtSaturateTorque(
m_virtContext, forceLimit, torqueLimit)) {
991 if (velocity.
size() != 6) {
997 for (
unsigned int i = 0; i < 6; i++)
998 speed[i] = (
float)velocity[i];
1035 std::cout <<
"Haptic loop open." << std::endl;
1052 std::cout <<
"Haptic loop closed." << std::endl;
1057 void dummy_vpVirtuose() { }
unsigned int size() const
Return the number of elements of the 2D array.
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
Implementation of a pose vector and operations on poses.
void extract(vpRotationMatrix &R) const
vpPoseVector & buildFrom(const double &tx, const double &ty, const double &tz, const double &tux, const double &tuy, const double &tuz)
Implementation of a rotation vector as quaternion angle minimal representation.
Implementation of a rotation vector as axis-angle minimal representation.
Class that consider the case of a translation vector.
vpColVector getVelocity() const
vpColVector getArticularPosition() const
VirtCommandType getCommandType() const
void setIpAddressAndPort(const std::string &ip, int port)
void setTimeStep(const float &timeStep)
void setForceFactor(const float &forceFactor)
void setArticularVelocity(const vpColVector &articularVelocity)
void setObservationFrame(const vpPoseVector &position)
void enableForceFeedback(int enable)
vpPoseVector getPosition() const
vpPoseVector getBaseFrame() const
void setForce(const vpColVector &force)
void setIndexingMode(const VirtIndexingType &type)
unsigned int getJointsNumber() const
vpPoseVector getPhysicalPosition() const
void setBaseFrame(const vpPoseVector &position)
VirtContext m_virtContext
vpPoseVector getObservationFrame() const
bool getEmergencyStop() const
void setCommandType(const VirtCommandType &type)
void setPeriodicFunction(VirtPeriodicFunction CallBackVirt)
vpColVector getArticularVelocity() const
void stopPeriodicFunction()
vpPoseVector getAvatarPosition() const
void addForce(vpColVector &force)
void setArticularForce(const vpColVector &articularForce)
void setPosition(vpPoseVector &position)
void setVelocity(vpColVector &velocity)
VirtCommandType m_typeCommand
void startPeriodicFunction()
void setVelocityFactor(const float &velocityFactor)
void setSaturation(const float &forceLimit, const float &torqueLimit)
vpColVector getPhysicalVelocity() const
void setArticularPosition(const vpColVector &articularPosition)
VirtIndexingType m_indexType
vpColVector getForce() const