|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
17 #include <Eigen/Eigenvalues>
44 for(
size_t i=0; i<l; i++)
59 for (
size_t k=0; k<s;k++)
75 for (
size_t r=0; r<m;r++)
76 for (
size_t c=0; c<n;c++)
91 for(
size_t i=0; i<l; i++)
99 for(
size_t i=0; i<l; i++)
114 for (
size_t k=0; k<s;k++)
131 for (
size_t r=0; r<m;r++)
132 for (
size_t c=0; c<n;c++)
150 size_t size=a.
size();
151 for (
size_t i = 0; i < size; i++)
221 for (
size_t r=0; r<M.
rows(); r++)
222 for (
size_t c=0; c<M.
cols(); c++)
237 for (
size_t i=0; i<n; i++)
245 a.
w()*b.
y() + a.
y()*b.
w() + a.
z()*b.
x() - a.
x()*b.
z(),
246 a.
w()*b.
z() + a.
z()*b.
w() + a.
x()*b.
y() - a.
y()*b.
x(),
247 a.
w()*b.
w() - a.
x()*b.
x() - a.
y()*b.
y() - a.
z()*b.
z());
260 for (
size_t i=0; i<n; i++)
275 for (
size_t i = 0; i < n; i++)
291 for (
int r=0; r<rows; r++)
292 for (
int c=0; c<cols; c++)
299 size_t c = m1.
cols();
301 size_t r1 = m1.
rows();
302 size_t r2 = m2.
rows();
339 size_t n = v1.
size();
351 size_t r = m1.
rows();
353 size_t c1 = m1.
cols();
354 size_t c2 = m2.
cols();
391 size_t n1 = v1.
size();
392 size_t n2 = v2.
size();
474 for(
size_t i=0;i<s;i++)
475 for(
size_t j=0;j<s;j++)
476 res(i,j) = a(i) * b(j);
485 v[0]=a[1]*b[2]-a[2]*b[1];
486 v[1]=a[2]*b[0]-a[0]*b[2];
487 v[2]=a[0]*b[1]-a[1]*b[0];
510 res(0,0) = res(1,1) = res(2,2) = 0.0;
535 for (
size_t i=1; i<v.
size(); i++)
546 for (
size_t i=1; i<v.
length(); i++)
585 return toEigen(in).determinant();
611 Eigen::EigenSolver< Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> > es(
toEigen(in));
613 for(
int i=0; i < n; i++)
615 std::complex<double> lambda = es.eigenvalues()[i];
616 real(i) = lambda.real();
617 img(i) = lambda.imag();
634 return ((v==0.0)?0.0:((v>0.0)?1.0:-1.0));
641 for (
size_t i=0; i<v.
length(); i++)
657 double theta=atan2(0.5*r,0.5*(R(0,0)+R(1,1)+R(2,2)-1));
731 bool singularity=
false;
736 v[0]=atan2(R(1,2),R(0,2));
738 v[2]=atan2(R(2,1),-R(2,0));
744 v[0]=-atan2(R(1,0),R(1,1));
753 v[0]=atan2(R(1,0),R(1,1));
759 yCWarning(MATH,
"dcm2euler() in singularity: choosing one solution among multiple");
769 double alpha=v[0];
double ca=cos(alpha);
double sa=sin(alpha);
770 double beta=v[1];
double cb=cos(beta);
double sb=sin(beta);
771 double gamma=v[2];
double cg=cos(gamma);
double sg=sin(gamma);
773 Rza(0,0)=ca; Rza(1,1)=ca; Rza(1,0)= sa; Rza(0,1)=-sa;
774 Rzg(0,0)=cg; Rzg(1,1)=cg; Rzg(1,0)= sg; Rzg(0,1)=-sg;
775 Ryb(0,0)=cb; Ryb(2,2)=cb; Ryb(2,0)=-sb; Ryb(0,2)= sb;
785 bool singularity=
false;
790 v[0]=atan2(R(2,1),R(2,2));
792 v[2]=atan2(R(1,0),R(0,0));
800 v[2]=-atan2(-R(1,2),R(1,1));
809 v[2]=atan2(-R(1,2),R(1,1));
813 yCWarning(MATH,
"dcm2rpy() in singularity: choosing one solution among multiple");
823 double roll=v[0];
double cr=cos(roll);
double sr=sin(roll);
824 double pitch=v[1];
double cp=cos(pitch);
double sp=sin(pitch);
825 double yaw=v[2];
double cy=cos(yaw);
double sy=sin(yaw);
827 Rz(0,0)=cy; Rz(1,1)=cy; Rz(0,1)=-sy; Rz(1,0)= sy;
828 Ry(0,0)=cp; Ry(2,2)=cp; Ry(0,2)= sp; Ry(2,0)=-sp;
829 Rx(1,1)=cr; Rx(2,2)=cr; Rx(1,2)=-sr; Rx(2,1)= sr;
844 v[0] = atan2(-R(0, 1), R(0, 0));
845 v[1] = asin(R(0, 2));
846 v[2] = atan2(-R(1, 2), R(2, 2));
853 v[2] = -atan2(R(1, 0), R(1, 1));
861 v[2] = atan2(R(1, 0), R(1, 1));
872 double roll = v[2];
double cr = cos(roll);
double sr = sin(roll);
873 double pitch = v[1];
double cp = cos(pitch);
double sp = sin(pitch);
874 double yaw = v[0];
double cy = cos(yaw);
double sy = sin(yaw);
876 Rz(0, 0) = cy; Rz(1, 1) = cy; Rz(0, 1) = -sy; Rz(1, 0) = sy;
877 Ry(0, 0) = cp; Ry(2, 2) = cp; Ry(0, 2) = sp; Ry(2, 0) = -sp;
878 Rx(1, 1) = cr; Rx(2, 2) = cr; Rx(1, 2) = -sr; Rx(2, 1) = sr;
899 invH(3,0)=invH(3,1)=invH(3,2)=0.0;
910 S(0,0)= 0.0; S(0,1)=-H(2,3); S(0,2)= H(1,3);
911 S(1,0)= H(2,3); S(1,1)= 0.0; S(1,2)=-H(0,3);
912 S(2,0)=-H(1,3); S(2,1)= H(0,3); S(2,2)= 0.0;
917 for (
int i=0; i<3; i++)
919 for (
int j=0; j<3; j++)
940 S(0,0)= 0.0; S(0,1)=-Rtp(2); S(0,2)= Rtp(1);
941 S(1,0)= Rtp(2); S(1,1)= 0.0; S(1,2)=-Rtp(0);
942 S(2,0)=-Rtp(1); S(2,1)= Rtp(0); S(2,2)= 0.0;
947 for (
int i=0; i<3; i++)
949 for (
int j=0; j<3; j++)
952 A(i+3,j+3) = Rt(i,j);
void resize(size_t size) override
Resize the vector.
yarp::sig::Matrix outerProduct(const yarp::sig::Vector &a, const yarp::sig::Vector &b)
Outer product between vectors (defined in Math.h).
#define yCWarning(component,...)
yarp::sig::Vector zeros(int s)
Creates a vector of zeros (defined in Math.h).
yarp::sig::Vector dcm2rpy(const yarp::sig::Matrix &R)
Converts a dcm (direction cosine matrix) rotation matrix to roll-pitch-yaw angles (defined in Math....
Matrix transposed() const
Return the transposed of the matrix.
#define YARP_LOG_COMPONENT(name,...)
size_t rows() const
Return number of rows.
Matrix submatrix(size_t r1, size_t r2, size_t c1, size_t c2) const
Extract a submatrix from (r1,c1) to (r2,c2) (extremes included), as in Matlab B=A(r1:r2,...
yarp::sig::Matrix eye(int r, int c)
Build an identity matrix (defined in Math.h).
yarp::sig::Matrix cat(const yarp::sig::Matrix &m1, const yarp::sig::Matrix &m2)
Matrix-Matrix concatenation by row (defined in Math.h).
yarp::sig::Vector ones(int s)
Creates a vector of ones (defined in Math.h).
Vector & operator*=(Vector &a, double k)
Vector-scalar product operator (defined in Math.h).
double findMin(const yarp::sig::Vector &v)
Returns the minimum of the elements of a real vector (defined in Math.h).
Vector & operator+=(Vector &a, const double &s)
Addition operator between a scalar and a vector (defined in Math.h).
double norm(const yarp::sig::Vector &v)
Returns the Euclidean norm of the vector (defined in Math.h).
yarp::sig::Matrix luinv(const yarp::sig::Matrix &in)
Invert a square matrix using LU-decomposition (defined in Math.h).
double norm2(const yarp::sig::Vector &v)
Returns the Euclidean squared norm of the vector (defined in Math.h).
yarp::sig::Matrix rpy2dcm(const yarp::sig::Vector &rpy)
Converts roll-pitch-yaw angles in the corresponding dcm (direction cosine matrix) rotation matrix (de...
yarp::sig::Matrix ypr2dcm(const yarp::sig::Vector &ypr)
Converts yaw-pitch-roll angles in the corresponding dcm (direction cosine matrix) rotation matrix (de...
double dot(const yarp::sig::Vector &a, const yarp::sig::Vector &b)
Scalar product between vectors (defined in Math.h).
void SVD(const yarp::sig::Matrix &in, yarp::sig::Matrix &U, yarp::sig::Vector &S, yarp::sig::Matrix &V)
Factorize the M-by-N matrix 'in' into the singular value decomposition in = U S V^T (defined in SVD....
yarp::sig::Matrix pile(const yarp::sig::Matrix &m1, const yarp::sig::Matrix &m2)
Matrix-Matrix concatenation by column (defined in Math.h).
double sign(const double &v)
Invert a symmetric and positive definite matrix using Cholesky decomposition (defined in Math....
yarp::sig::Vector cross(const yarp::sig::Vector &a, const yarp::sig::Vector &b)
Compute the cross product between two vectors (defined in Math.h).
Vector operator/(const Vector &a, const Vector &b)
Vector-vector element-wise division operator (defined in Math.h).
size_t length() const
Get the length of the vector.
double det(const yarp::sig::Matrix &in)
Computes the determinant of a matrix (defined in Math.h).
size_t cols() const
Return number of columns.
yarp::sig::Matrix adjointInv(const yarp::sig::Matrix &H)
Returns the inverse of the adjoint matrix of a given roto-translational matrix (defined in Math....
yarp::sig::Matrix axis2dcm(const yarp::sig::Vector &v)
Returns a dcm (direction cosine matrix) rotation matrix R from axis/angle representation (defined in ...
void resize(size_t r, size_t c)
Resize the matrix, if matrix is not empty preserve old content.
#define yCAssert(component, x)
Vector operator+(const Vector &a, const double &s)
Mathematical operations.
Vector & operator/=(Vector &a, const Vector &b)
Vector-vector element-wise division operator (defined in Math.h).
yarp::sig::Vector dcm2euler(const yarp::sig::Matrix &R)
Converts a dcm (direction cosine matrix) rotation matrix to euler angles (ZYZ) (defined in Math....
VectorOf< double > Vector
yarp::sig::Matrix adjoint(const yarp::sig::Matrix &H)
Returns the adjoint matrix of a given roto-translational matrix (defined in Math.h).
Vector operator*(double k, const Vector &b)
Scalar-vector product operator (defined in Math.h).
Vector getCol(size_t c) const
Get a columns of the matrix as a vector.
Vector & operator-=(Vector &a, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
Vector operator-(const Vector &a, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
yarp::rosmsg::geometry_msgs::Quaternion Quaternion
void zero()
Zero the matrix.
yarp::sig::Matrix euler2dcm(const yarp::sig::Vector &euler)
Converts euler angles (ZYZ) vector in the corresponding dcm (direction cosine matrix) rotation matrix...
yarp::sig::Matrix crossProductMatrix(const yarp::sig::Vector &v)
Compute the cross product matrix, that is a 3-by-3 skew-symmetric matrix (defined in Math....
yarp::sig::Vector dcm2axis(const yarp::sig::Matrix &R)
Converts a dcm (direction cosine matrix) rotation matrix R to axis/angle representation (defined in M...
yarp::sig::Vector dcm2ypr(const yarp::sig::Matrix &R)
Converts a dcm (direction cosine matrix) rotation matrix to yaw-roll-pitch angles (defined in Math....
Eigen::Map< Eigen::VectorXd > toEigen(yarp::sig::Vector &yarpVector)
Convert a yarp::sig::Vector to a Eigen::Map<Eigen::VectorXd> object.
bool eigenValues(const yarp::sig::Matrix &in, yarp::sig::Vector &real, yarp::sig::Vector &img)
Computes eigenvalues of the n-by-n real nonsymmetric matrix (defined in Math.h).
yarp::sig::Matrix SE3inv(const yarp::sig::Matrix &H)
Returns the inverse of a 4 by 4 rototranslational matrix (defined in Math.h).
VectorOf< T > subVector(unsigned int first, unsigned int last) const
Creates and returns a new vector, being the portion of the original vector defined by the first and l...
double findMax(const yarp::sig::Vector &v)
Returns the maximum of the elements of a real vector (defined in Math.h).