Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpForceTwistMatrix.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See https://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * Twist transformation matrix that allows to transform forces from one
33 * frame to an other.
34 *
35*****************************************************************************/
36
37#include <assert.h>
38#include <sstream>
39
40#include <visp3/core/vpDebug.h>
41#include <visp3/core/vpException.h>
42#include <visp3/core/vpForceTwistMatrix.h>
43
58{
59 for (int i = 0; i < 6; i++) {
60 for (int j = 0; j < 6; j++) {
61 rowPtrs[i][j] = M.rowPtrs[i][j];
62 }
63 }
64
65 return *this;
66}
67
72{
73 for (unsigned int i = 0; i < 6; i++) {
74 for (unsigned int j = 0; j < 6; j++) {
75 if (i == j)
76 (*this)[i][j] = 1.0;
77 else
78 (*this)[i][j] = 0.0;
79 }
80 }
81}
82
87
96
127{
128 if (full)
129 buildFrom(M);
130 else
132}
133
154 : vpArray2D<double>(6, 6)
155{
156 buildFrom(t, thetau);
157}
158
177
198 : vpArray2D<double>(6, 6)
199{
200 buildFrom(t, R);
201}
202
221
242vpForceTwistMatrix::vpForceTwistMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz)
243 : vpArray2D<double>(6, 6)
244{
245 vpTranslationVector T(tx, ty, tz);
246 vpThetaUVector tu(tux, tuy, tuz);
247 buildFrom(T, tu);
248}
249
269{
271
272 for (unsigned int i = 0; i < 6; i++) {
273 for (unsigned int j = 0; j < 6; j++) {
274 double s = 0;
275 for (unsigned int k = 0; k < 6; k++)
276 s += rowPtrs[i][k] * F.rowPtrs[k][j];
277 Fout[i][j] = s;
278 }
279 }
280 return Fout;
281}
282
291{
292
293 if (6 != M.getRows()) {
295 "Cannot multiply (6x6) force/torque twist matrix by a (%dx%d) matrix", M.getRows(), M.getCols()));
296 }
297
298 vpMatrix p(6, M.getCols());
299 for (unsigned int i = 0; i < 6; i++) {
300 for (unsigned int j = 0; j < M.getCols(); j++) {
301 double s = 0;
302 for (unsigned int k = 0; k < 6; k++)
303 s += rowPtrs[i][k] * M[k][j];
304 p[i][j] = s;
305 }
306 }
307 return p;
308}
309
355{
356 vpColVector Hout(6);
357
358 if (6 != H.getRows()) {
360 "Cannot multiply a (6x6) force/torque twist matrix by "
361 "a %d dimension column vector",
362 H.getRows()));
363 }
364
365 Hout = 0.0;
366
367 for (unsigned int i = 0; i < 6; i++) {
368 for (unsigned int j = 0; j < 6; j++) {
369 Hout[i] += rowPtrs[i][j] * H[j];
370 }
371 }
372
373 return Hout;
374}
375
396{
397 vpMatrix skewaR = t.skew(t) * R;
398
399 for (unsigned int i = 0; i < 3; i++) {
400 for (unsigned int j = 0; j < 3; j++) {
401 (*this)[i][j] = R[i][j];
402 (*this)[i + 3][j + 3] = R[i][j];
403 (*this)[i + 3][j] = skewaR[i][j];
404 }
405 }
406 return (*this);
407}
408
427{
428 for (unsigned int i = 0; i < 3; i++) {
429 for (unsigned int j = 0; j < 3; j++) {
430 (*this)[i][j] = R[i][j];
431 (*this)[i + 3][j + 3] = R[i][j];
432 (*this)[i + 3][j] = 0;
433 }
434 }
435 return (*this);
436}
437
459{
460 buildFrom(tv, vpRotationMatrix(thetau));
461 return (*this);
462}
463
483{
485 return (*this);
486}
487
517{
518 if (full)
520 else
522
523 return (*this);
524}
525
545int vpForceTwistMatrix::print(std::ostream &s, unsigned int length, char const *intro) const
546{
547 typedef std::string::size_type size_type;
548
549 unsigned int m = getRows();
550 unsigned int n = getCols();
551
552 std::vector<std::string> values(m * n);
553 std::ostringstream oss;
554 std::ostringstream ossFixed;
555 std::ios_base::fmtflags original_flags = oss.flags();
556
557 // ossFixed <<std::fixed;
558 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
559
560 size_type maxBefore = 0; // the length of the integral part
561 size_type maxAfter = 0; // number of decimals plus
562 // one place for the decimal point
563 for (unsigned int i = 0; i < m; ++i) {
564 for (unsigned int j = 0; j < n; ++j) {
565 oss.str("");
566 oss << (*this)[i][j];
567 if (oss.str().find("e") != std::string::npos) {
568 ossFixed.str("");
569 ossFixed << (*this)[i][j];
570 oss.str(ossFixed.str());
571 }
572
573 values[i * n + j] = oss.str();
574 size_type thislen = values[i * n + j].size();
575 size_type p = values[i * n + j].find('.');
576
577 if (p == std::string::npos) {
578 maxBefore = vpMath::maximum(maxBefore, thislen);
579 // maxAfter remains the same
580 } else {
581 maxBefore = vpMath::maximum(maxBefore, p);
582 maxAfter = vpMath::maximum(maxAfter, thislen - p - 1);
583 }
584 }
585 }
586
587 size_type totalLength = length;
588 // increase totalLength according to maxBefore
589 totalLength = vpMath::maximum(totalLength, maxBefore);
590 // decrease maxAfter according to totalLength
591 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
592 if (maxAfter == 1)
593 maxAfter = 0;
594
595 // the following line is useful for debugging
596 // std::cerr <<totalLength <<" " <<maxBefore <<" " <<maxAfter <<"\n";
597
598 if (intro)
599 s << intro;
600 s << "[" << m << "," << n << "]=\n";
601
602 for (unsigned int i = 0; i < m; i++) {
603 s << " ";
604 for (unsigned int j = 0; j < n; j++) {
605 size_type p = values[i * n + j].find('.');
606 s.setf(std::ios::right, std::ios::adjustfield);
607 s.width((std::streamsize)maxBefore);
608 s << values[i * n + j].substr(0, p).c_str();
609
610 if (maxAfter > 0) {
611 s.setf(std::ios::left, std::ios::adjustfield);
612 if (p != std::string::npos) {
613 s.width((std::streamsize)maxAfter);
614 s << values[i * n + j].substr(p, maxAfter).c_str();
615 } else {
616 assert(maxAfter > 1);
617 s.width((std::streamsize)maxAfter);
618 s << ".0";
619 }
620 }
621
622 s << ' ';
623 }
624 s << std::endl;
625 }
626
627 s.flags(original_flags); // restore s to standard state
628
629 return (int)(maxBefore + maxAfter);
630}
631
632#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
633
641
642#endif //#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition vpArray2D.h:131
unsigned int getCols() const
Definition vpArray2D.h:280
double ** rowPtrs
Address of the first element of each rows.
Definition vpArray2D.h:138
vpArray2D< double > t() const
Compute the transpose of the array.
Definition vpArray2D.h:1059
unsigned int getRows() const
Definition vpArray2D.h:290
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:59
@ dimensionError
Bad dimension.
Definition vpException.h:83
vpForceTwistMatrix & operator=(const vpForceTwistMatrix &H)
vpForceTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpForceTwistMatrix operator*(const vpForceTwistMatrix &F) const
int print(std::ostream &s, unsigned int length, char const *intro=0) const
vp_deprecated void setIdentity()
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpRotationMatrix getRotationMatrix() const
vpTranslationVector getTranslationVector() const
static Type maximum(const Type &a, const Type &b)
Definition vpMath.h:172
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:152
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as axis-angle minimal representation.
Class that consider the case of a translation vector.