1 #include <visp3/ustk_gui/usViper850WrapperVelocityControl.h>
3 #if defined(USTK_HAVE_VTK_QT) && defined(VISP_HAVE_VIPER850) && defined(VISP_HAVE_MODULE_ROBOT)
9 velocityProbeContact = vpColVector(6, 0);
17 if (viper->getPowerState()) {
27 viper =
new vpRobotViper850();
29 std::cout <<
"Viper robot could not be initialized" << std::endl;
34 vpHomogeneousMatrix eMp;
50 void usViper850WrapperVelocityControl::startRobot(
void)
53 if (viper->getControlMode() == vpRobotViper850::MANUAL) {
57 viper->setRobotState(vpRobot::STATE_VELOCITY_CONTROL);
59 viper->setRobotState(vpRobot::STATE_STOP);
60 std::cout <<
"Viper robot could not be initialized" << std::endl;
64 std::cout <<
"For security reason, the Viper robot has to be used with the dead man switch)" << std::endl;
82 viper->setRobotState(vpRobot::STATE_STOP);
85 void usViper850WrapperVelocityControl::controlLoop()
89 ve = eVp * velocityProbeContact;
94 q_dot = eJe.pseudoInverse() * ve;
97 viper->setVelocity(vpRobot::ARTICULAR_FRAME, q_dot);
99 viper->setRobotState(vpRobot::STATE_STOP);
100 std::cout <<
"Viper robot could not be initialized" << std::endl;
106 qApp->processEvents();
110 void usViper850WrapperVelocityControl::controlLoopAutomatic()
115 vpHomogeneousMatrix eMs;
120 vpHomogeneousMatrix sMp;
123 vpHomogeneousMatrix sMe;
128 vpVelocityTwistMatrix sVe;
132 vpColVector pHp_star(6);
134 vpMatrix lambdaProportionnal(6, 6);
135 vpMatrix lambdaDerivate(6, 6);
136 vpMatrix lambdaIntegral(6, 6);
137 vpColVector sEs(6, 0);
138 vpColVector sEs_last(6, 0);
139 vpColVector sEs_sum(6, 0);
141 vpTranslationVector stg;
142 vpColVector sHs_bias(6);
150 lambdaProportionnal = 0;
151 for (
int i = 0; i < 3; i++)
152 lambdaProportionnal[i][i] = 0.015;
154 for (
int i = 3; i < 6; i++)
155 lambdaProportionnal[i][i] = 0;
158 for (
int i = 0; i < 3; i++)
159 lambdaDerivate[i][i] = 0.09;
161 for (
int i = 3; i < 6; i++)
162 lambdaDerivate[i][i] = 0;
165 for (
int i = 0; i < 3; i++)
166 lambdaIntegral[i][i] = 0;
168 for (
int i = 3; i < 6; i++)
169 lambdaIntegral[i][i] = 0;
185 gHg[2] = -(0.696 + 0.476) * 9.81;
192 vpRotationMatrix sRp;
194 vpTranslationVector stp;
197 vpHomogeneousMatrix eMp = eMs * sMp;
198 vpVelocityTwistMatrix eVp(eMp);
202 vpHomogeneousMatrix fMe;
203 vpHomogeneousMatrix fMs;
204 vpRotationMatrix sRf;
205 viper->getPosition(vpRobot::ARTICULAR_FRAME, q);
206 viper->get_fMe(q, fMe);
209 vpHomogeneousMatrix sMf;
215 vpForceTwistMatrix sFg(sMf);
217 for (
int i = 0; i < 3; i++)
218 for (
int j = 0; j < 3; j++)
219 sFg[i + 3][j] = (stg.skew() * sRf)[i][j];
223 vpForceTwistMatrix sFp(sMp);
226 viper->biasForceTorqueSensor();
229 viper->setRobotState(vpRobot::STATE_VELOCITY_CONTROL);
231 unsigned int iter = 0;
234 unsigned int bufferSize = 80;
235 double signalBuffer[bufferSize];
236 for (
unsigned int i = 0; i < bufferSize; i++)
239 double t0 = vpTime::measureTimeMs();
240 double deltaTmilliseconds = 1;
244 t0 = vpTime::measureTimeMs();
247 sHs = viper->getForceTorque();
254 viper->getPosition(vpRobot::ARTICULAR_FRAME, q);
255 viper->get_fMe(q, fMe);
265 for (
int i = 0; i < 3; i++)
266 for (
int j = 0; j < 3; j++)
267 sFg[i + 3][j] = (stg.skew() * sRf)[i][j];
270 sHs_bias = sHs - sFg * gHg;
277 sEs = sFp * pHp_star - (sHs - sFg * gHg - sHs_bias);
280 signalBuffer[iter % bufferSize] = sEs[2];
284 unsigned int realBufferSize = iter + 1 < bufferSize ? iter + 1 : bufferSize;
285 for (
unsigned int i = 0; i < realBufferSize; i++) {
286 sum += signalBuffer[i];
288 sEs[2] = sum / realBufferSize;
298 v_s = lambdaProportionnal * sEs + lambdaDerivate * (sEs - sEs_last) + lambdaIntegral * sEs_sum;
307 vpVelocityTwistMatrix eVs;
310 vpColVector v_e = velocityProbeContact;
313 ve = eVs * v_s + this->eVp * v_e;
319 q_dot = eJe.pseudoInverse() * ve;
322 viper->setVelocity(vpRobot::ARTICULAR_FRAME, q_dot);
326 viper->setRobotState(vpRobot::STATE_STOP);
327 std::cout <<
"Viper robot could not be initialized" << std::endl;
333 qApp->processEvents();
334 vpTime::wait(t0, deltaTmilliseconds);
344 velocityProbeContact[0] = (double)xVelocity / 1000.0;
353 velocityProbeContact[1] = (double)yVelocity / 1000.0;
362 velocityProbeContact[2] = (double)zVelocity / 1000.0;
371 velocityProbeContact[3] = vpMath::rad((
double)xAngularVelocity / 10.0);
380 velocityProbeContact[4] = vpMath::rad((
double)yAngularVelocity / 10.0);
389 velocityProbeContact[5] = vpMath::rad((
double)zAngularVelocity / 10.0);
398 for (
unsigned int i = 0; i < velocityProbeContact.size(); i++)
399 velocityProbeContact[i] = 0;
401 if (!viper->getPowerState())
413 for (
unsigned int i = 0; i < velocityProbeContact.size(); i++)
414 velocityProbeContact[i] = 0;
void setZVelocity(int zVelocity)
Set the linear velocity along z axis in 4DC7 probe contact frame.
void setXVelocity(int xVelocity)
Set the linear velocity along x axis in 4DC7 probe contact frame.
void setYVelocity(int yVelocity)
Set the linear velocity along y axis in 4DC7 probe contact frame.
void startControlLoopAutomatic()
void startAutomaticForceControl()
virtual ~usViper850WrapperVelocityControl()
void setXAngularVelocity(int xAngularVelocity)
Set the angular velocity around x axis in 4DC7 probe contact frame.
void setZAngularVelocity(int zAngularVelocity)
Set the angular velocity around z axis in 4DC7 probe contact frame.
void setYAngularVelocity(int yAngularVelocity)
Set the angular velocity around y axis in 4DC7 probe contact frame.
usViper850WrapperVelocityControl()
void stopAutomaticForceControl()