42 #include <visp3/core/vpTime.h>
43 #include <visp3/robot/vpVirtuose.h>
45 #if defined(VISP_HAVE_VIRTUOSE)
46 #ifdef ENABLE_VISP_NAMESPACE
50 void CallBackVirtuose(VirtContext VC,
void *ptr)
54 static bool firstIteration =
true;
62 int force_increase_rate = 500;
63 float cube_size = 0.05f;
71 double virtualStiffnessAng = 20;
72 double virtualDamperAng = 0.182;
73 double virtualDamperAng2 = 0.0456;
102 if (firstIteration) {
103 localPosition0 = localPosition;
104 firstIteration =
false;
117 yd = zd.skew(zd) * xd;
168 rotzYZ = zeed.skew(zeed) * zYZ.normalize();
169 vpColVector forceStiff1 = virtualStiffnessAng * rotzYZ;
172 for (
unsigned int i = 0; i < 3; i++)
173 torque1[i] = forceStiff1[i] - forceDamp1[i];
179 rotzXZ = zeed.skew(zeed) * zXZ.normalize();
180 vpColVector forceStiff2 = virtualStiffnessAng * rotzXZ;
183 for (
unsigned int i = 0; i < 3; i++)
184 torque2[i] = forceStiff2[i] - forceDamp2[i];
194 rotxXY = xdd.skew(xdd) * xXY.normalize();
195 alpha = asin(rotxXY[2]);
197 vpColVector forceStiff3 = virtualStiffnessAng * alpha * zdd;
198 vpColVector forceDamp3 = virtualDamperAng2 * (omegad * zdd) * zdd;
199 for (
unsigned int i = 0; i < 3; i++)
200 torque3[i] = forceStiff3[i] - forceDamp3[i];
202 for (
unsigned int j = 0; j < 3; j++)
203 forceEe[j + 3] = torque1[j] + torque2[j] + torque3[j];
205 forceEe = dFMb * forceEe;
211 for (
unsigned int i = 0; i < 3; i++) {
212 p_min[i] = localPosition0[i] - cube_size / 2;
213 p_max[i] = localPosition0[i] + cube_size / 2;
216 for (
int i = 0; i < 3; i++) {
217 if ((p_min[i] >= localPosition[i])) {
218 forceFeedback[i] = (p_min[i] - localPosition[i]) * force_increase_rate;
219 if (forceFeedback[i] >= force_limit)
220 forceFeedback[i] = force_limit;
222 else if ((p_max[i] <= localPosition[i])) {
223 forceFeedback[i] = (p_max[i] - localPosition[i]) * force_increase_rate;
224 if (forceFeedback[i] <= -force_limit)
225 forceFeedback[i] = -force_limit;
228 forceFeedback[i] = 0;
231 for (
unsigned int j = 0; j < 6; j++)
232 finalForce[j] = forceFeedback[j] + forceEe[j];
240 int main(
int argc,
char **argv)
242 std::string opt_ip =
"localhost";
244 for (
int i = 0; i < argc; i++) {
245 if (std::string(argv[i]) ==
"--ip")
246 opt_ip = std::string(argv[i + 1]);
247 else if (std::string(argv[i]) ==
"--port")
248 opt_port = std::atoi(argv[i + 1]);
249 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
250 std::cout <<
"\nUsage: " << argv[0]
251 <<
" [--ip <localhost>] [--port <port>]"
254 <<
"Description: " << std::endl
255 <<
" --ip <localhost>" << std::endl
256 <<
"\tHost IP address. Default value: \"localhost\"." << std::endl
258 <<
" --port <port>" << std::endl
259 <<
"\tCommunication port. Default value: 5000." << std::endl
260 <<
"\tSuggested values: " << std::endl
261 <<
"\t- 5000 to communicate with the Virtuose." << std::endl
262 <<
"\t- 53210 to communicate with the Virtuose equipped with the Glove." << std::endl
270 std::cout <<
"Try to connect to " << opt_ip <<
" port " << opt_port << std::endl;
289 std::cout <<
"The end" << std::endl;
301 std::cout <<
"You should install pthread and/or Virtuose API to use this "
Implementation of column vector and the associated operations.
vpColVector & normalize()
error that can be emitted by ViSP classes.
const std::string & getStringMessage() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a pose vector and operations on poses.
void extract(vpRotationMatrix &R) const
Implementation of a rotation matrix and operations on such kind of matrices.
vpColVector getCol(unsigned int j) const
vpRotationMatrix inverse() const
Class that consider the case of a translation vector.
void setIpAddressAndPort(const std::string &ip, int port)
void setForce(const vpColVector &force)
vpPoseVector getPhysicalPosition() const
void setPeriodicFunction(VirtPeriodicFunction CallBackVirt)
void stopPeriodicFunction()
void setVerbose(bool mode)
void startPeriodicFunction()
vpColVector getPhysicalVelocity() const
VISP_EXPORT void sleepMs(double t)