Skip to content

Commit 02f4ff7

Browse files
Implement methods for matrices Q4 and Q8. (#56)
* Implement methods for matrices Q4 and Q8. * Implement methods for matrices Q4 and Q8. [DQ.h] Add member functions Q4 and Q8. [DQ.cpp] Add namespace functions Q4 and Q8. Implement class methods Q4 and Q8. * Add a more detailed description of the contributors. [DQ.h] Add description of what each contributor has done. * Add a more detailed contributors description. [DQ.cpp] -Add what each contributor has done. - Update the Copyright. - Update Q8 return description to match Q4. * Fix typo in the Q8 method. [DQ.cpp] Remove extra '@return' in the Q8 method. * Add missing consts in method Q4 and Q8 and check if quaternion is unit in method Q4. [DQ.cpp] - Check if rotation quaternion has unit norm in method Q4. - Add missing consts in method Q4. - Add missing consts in method Q8. * Fix description of Q4 and Q8 methods to comply with MATLAB implementation. * Check if the caller is a quaternion on the Q4 method.
1 parent 93d4a05 commit 02f4ff7

File tree

2 files changed

+137
-8
lines changed

2 files changed

+137
-8
lines changed

include/dqrobotics/DQ.h

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
(C) Copyright 2011-2022 DQ Robotics Developers
2+
(C) Copyright 2011-2023 DQ Robotics Developers
33
44
This file is part of DQ Robotics.
55
@@ -17,9 +17,28 @@ This file is part of DQ Robotics.
1717
along with DQ Robotics. If not, see <http://www.gnu.org/licenses/>.
1818
1919
Contributors:
20-
- Bruno Vilhena Adorno ([email protected])
21-
- Murilo M. Marinho ([email protected])
22-
- Mateus Rodrigues Martins ([email protected])
20+
1. Bruno Vilhena Adorno ([email protected])
21+
- Responsible for the original implementation.
22+
[bvadorno committed on Jul 20, 2012](7368f3e)
23+
(https://github.com/dqrobotics/cpp/commit/7368f3ea3d557834661d723adde981250db0b87f).
24+
25+
2. Mateus Rodrigues Martins ([email protected])
26+
- Added new methods, and support for Boost library.
27+
[mateusmartins committed on Jul 27, 2012]()
28+
(https://github.com/dqrobotics/cpp/commit/7d96efb354ffa07a093d5cb3f34af2c7ce8e2d39).
29+
30+
3. Murilo M. Marinho ([email protected])
31+
- Refactoring, and compliance with the new style.
32+
[murilomarinho committed on Dec 22, 2012](c7f4596)
33+
(https://github.com/dqrobotics/cpp/commit/c7f459612bb47ab2151b64ed6820c9f6fb242fa6).
34+
35+
- Added support for Eigen library
36+
[murilomarinho committed on Jan 31, 2013](1ec0bf0)
37+
(https://github.com/dqrobotics/cpp/commit/1ec0bf096ff7b9f3f73ee0513f0a6f07c2a58f01).
38+
39+
4. Marcos da Silva Pereira ([email protected])
40+
- Translated the Q4 and the Q8 methods from the MATLAB implementation in PR #56
41+
(https://github.com/dqrobotics/cpp/pull/56).
2342
*/
2443
#pragma once
2544

@@ -132,6 +151,10 @@ class DQ{
132151

133152
DQ Adsharp(const DQ& dq2) const;
134153

154+
Matrix<double,4,3> Q4() const;
155+
156+
Matrix<double,8,6> Q8() const;
157+
135158
std::string to_string() const;
136159

137160
//Operators
@@ -219,6 +242,10 @@ DQ Ad(const DQ& dq1, const DQ& dq2);
219242

220243
DQ Adsharp(const DQ& dq1, const DQ& dq2);
221244

245+
Matrix<double,4,3> Q4(const DQ& dq);
246+
247+
Matrix<double,8,6> Q8(const DQ& dq);
248+
222249
bool is_unit(const DQ& dq);
223250

224251
bool is_pure(const DQ& dq);

src/DQ.cpp

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
(C) Copyright 2011-2020 DQ Robotics Developers
2+
(C) Copyright 2011-2023 DQ Robotics Developers
33
44
This file is part of DQ Robotics.
55
@@ -17,9 +17,28 @@ This file is part of DQ Robotics.
1717
along with DQ Robotics. If not, see <http://www.gnu.org/licenses/>.
1818
1919
Contributors:
20-
- Bruno Vilhena Adorno ([email protected])
21-
- Murilo M. Marinho ([email protected])
22-
- Mateus Rodrigues Martins ([email protected])
20+
1. Bruno Vilhena Adorno ([email protected])
21+
- Responsible for the original implementation.
22+
[bvadorno committed on Jul 20, 2012](7368f3e)
23+
(https://github.com/dqrobotics/cpp/commit/7368f3ea3d557834661d723adde981250db0b87f).
24+
25+
2. Mateus Rodrigues Martins ([email protected])
26+
- Added new methods, and support for Boost library.
27+
[mateusmartins committed on Jul 27, 2012]()
28+
(https://github.com/dqrobotics/cpp/commit/7d96efb354ffa07a093d5cb3f34af2c7ce8e2d39).
29+
30+
3. Murilo M. Marinho ([email protected])
31+
- Refactoring, and compliance with the new style.
32+
[murilomarinho committed on Dec 22, 2012](c7f4596)
33+
(https://github.com/dqrobotics/cpp/commit/c7f459612bb47ab2151b64ed6820c9f6fb242fa6).
34+
35+
- Added support for Eigen library
36+
[murilomarinho committed on Jan 31, 2013](1ec0bf0)
37+
(https://github.com/dqrobotics/cpp/commit/1ec0bf096ff7b9f3f73ee0513f0a6f07c2a58f01).
38+
39+
4. Marcos da Silva Pereira ([email protected])
40+
- Translated the Q4 and the Q8 methods from the MATLAB implementation in PR #56
41+
(https://github.com/dqrobotics/cpp/pull/56).
2342
*/
2443

2544
#include <dqrobotics/DQ.h>
@@ -380,6 +399,16 @@ DQ Adsharp(const DQ& dq1, const DQ& dq2)
380399
return sharp(dq1)*dq2*conj(dq1);
381400
}
382401

402+
Matrix<double,4,3> Q4(const DQ& dq)
403+
{
404+
return dq.Q4();
405+
}
406+
407+
Matrix<double,8,6> Q8(const DQ& dq)
408+
{
409+
return dq.Q8();
410+
}
411+
383412
/****************************************************************
384413
**************DQ CLASS METHODS***********************************
385414
*****************************************************************/
@@ -1020,6 +1049,79 @@ DQ DQ::Adsharp(const DQ& dq2) const
10201049
return DQ_robotics::Adsharp(*this,dq2);
10211050
}
10221051

1052+
/**
1053+
* @brief Given the unit quaternion r, return the partial derivative of vec4(r) with respect to vec3(log(r)).
1054+
* Eq. (22) of Savino et al (2020). Pose consensus based on dual quaternion algebra with application
1055+
* to decentralized formation control of mobile manipulators.
1056+
* https://doi.org/10.1016/j.jfranklin.2019.09.045
1057+
* @returns A matrix representing the desired partial derivative.
1058+
*/
1059+
Matrix<double,4,3> DQ::Q4() const
1060+
{
1061+
if (!is_unit(*this) || !is_quaternion(*this))
1062+
{
1063+
throw(std::range_error("Bad Q4() call: Not a unit quaternion"));
1064+
}
1065+
1066+
const Vector4d r = this->vec4();
1067+
const double phi = double(this->rotation_angle());
1068+
const Vector3d n = this->rotation_axis().vec3();
1069+
const double nx = n(0);
1070+
const double ny = n(1);
1071+
const double nz = n(2);
1072+
1073+
double theta;
1074+
if (phi == 0)
1075+
{
1076+
theta = 1;
1077+
}
1078+
else
1079+
{
1080+
theta = sin(phi/2.0)/(phi/2.0);
1081+
}
1082+
1083+
double gamma = r(0) - theta;
1084+
1085+
Matrix<double,4,3> Q4(4,3);
1086+
Q4 << -r(1), -r(2), -r(3),
1087+
gamma*std::pow(nx,2)+theta, gamma*nx*ny, gamma*nx*nz,
1088+
gamma*nx*ny, gamma*std::pow(ny,2)+theta, gamma*ny*nz,
1089+
gamma*nz*nx, gamma*nz*ny, gamma*std::pow(nz,2)+theta;
1090+
1091+
return Q4;
1092+
}
1093+
1094+
/**
1095+
* @brief Given the unit dual quaternion x, Q8(x) returns the partial derivative of vec8(x) with respect to vec6(log(x)).
1096+
* Theorem 4 of Savino et al (2020). Pose consensus based on dual quaternion algebra with application
1097+
* to decentralized formation control of mobile manipulators.
1098+
* https://doi.org/10.1016/j.jfranklin.2019.09.045
1099+
* @returns A matrix representing the desired partial derivative.
1100+
*/
1101+
Matrix<double,8,6> DQ::Q8() const
1102+
{
1103+
if (!is_unit(*this))
1104+
{
1105+
throw(std::range_error("Bad Q8() call: Not a unit dual quaternion"));
1106+
}
1107+
1108+
const DQ r = this->rotation();
1109+
const DQ p = this->translation();
1110+
1111+
const MatrixXd Q = r.Q4();
1112+
MatrixXd Qp(4,3);
1113+
Qp << MatrixXd::Zero(1,3),
1114+
MatrixXd::Identity(3,3);
1115+
1116+
Matrix<double,8,6> Q8(8,6);
1117+
1118+
Q8 << Q, MatrixXd::Zero(4,3),
1119+
0.5*p.hamiplus4()*Q, r.haminus4()*Qp;
1120+
1121+
return Q8;
1122+
}
1123+
1124+
10231125
/**
10241126
* Unit Dual Quaternion constructor.
10251127
*

0 commit comments

Comments
 (0)