Skip to content

Commit 86ab918

Browse files
committed
Move constants to class template
1 parent c879116 commit 86ab918

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+511
-393
lines changed

demos/rlAxisControllerDemo/rlAxisControllerDemo.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#include <rl/hal/Gnuplot.h>
3131
#include <rl/hal/MitsubishiH7.h>
3232
#include <rl/hal/UniversalRobotsRtde.h>
33+
#include <rl/math/Constants.h>
3334
#include <rl/math/Polynomial.h>
34-
#include <rl/math/Unit.h>
3535

3636
#define COACH
3737
//#define GNUPLOT
@@ -50,7 +50,7 @@ main(int argc, char** argv)
5050
rl::hal::Coach controller(6, std::chrono::microseconds(7110), 0, "localhost");
5151
#endif // COACH
5252
#ifdef GNUPLOT
53-
rl::hal::Gnuplot controller(6, std::chrono::microseconds(7110), -10 * rl::math::DEG2RAD, 10 * rl::math::DEG2RAD);
53+
rl::hal::Gnuplot controller(6, std::chrono::microseconds(7110), -10 * rl::math::constants::deg2rad, 10 * rl::math::constants::deg2rad);
5454
#endif // GNUPLOT
5555
#ifdef MITSUBISHI
5656
rl::hal::MitsubishiH7 controller(6, "left", "lefthost");
@@ -67,7 +67,7 @@ main(int argc, char** argv)
6767
controller.step();
6868

6969
rl::math::Vector q0 = controller.getJointPosition();
70-
rl::math::Vector q1 = q0 + rl::math::Vector::Constant(controller.getDof(), 5 * rl::math::DEG2RAD);
70+
rl::math::Vector q1 = q0 + rl::math::Vector::Constant(controller.getDof(), 5 * rl::math::constants::deg2rad);
7171

7272
rl::math::Real te = updateRate * 300.0f;
7373

demos/rlCoachKin/ConfigurationDelegate.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <QDoubleSpinBox>
2828
#include <QModelIndex>
29+
#include <rl/math/Constants.h>
2930

3031
#include "ConfigurationDelegate.h"
3132
#include "MainWindow.h"
@@ -57,8 +58,8 @@ ConfigurationDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem&
5758
if (rl::math::UNIT_RADIAN == qUnits(index.row()))
5859
{
5960
editor->setDecimals(2);
60-
editor->setMinimum(minimum(index.row()) * rl::math::RAD2DEG);
61-
editor->setMaximum(maximum(index.row()) * rl::math::RAD2DEG);
61+
editor->setMinimum(minimum(index.row()) * rl::math::constants::rad2deg);
62+
editor->setMaximum(maximum(index.row()) * rl::math::constants::rad2deg);
6263
editor->setSingleStep(1.0);
6364
}
6465
else

demos/rlCoachKin/ConfigurationModel.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// POSSIBILITY OF SUCH DAMAGE.
2525
//
2626

27+
#include <rl/math/Constants.h>
2728
#include <rl/sg/Body.h>
2829

2930
#include "ConfigurationModel.h"
@@ -72,7 +73,7 @@ ConfigurationModel::data(const QModelIndex& index, int role) const
7273
return QString::number(q(index.row()), 'f', 4) + QString(" m");
7374
break;
7475
case rl::math::UNIT_RADIAN:
75-
return QString::number(q(index.row()) * rl::math::RAD2DEG, 'f', 2) + QChar(176);
76+
return QString::number(q(index.row()) * rl::math::constants::rad2deg, 'f', 2) + QChar(176);
7677
break;
7778
default:
7879
return q(index.row());
@@ -82,7 +83,7 @@ ConfigurationModel::data(const QModelIndex& index, int role) const
8283
case Qt::EditRole:
8384
if (rl::math::UNIT_RADIAN == qUnits(index.row()))
8485
{
85-
return q(index.row()) * rl::math::RAD2DEG;
86+
return q(index.row()) * rl::math::constants::rad2deg;
8687
}
8788
else
8889
{
@@ -156,7 +157,7 @@ ConfigurationModel::setData(const QModelIndex& index, const QVariant& value, int
156157

157158
if (rl::math::UNIT_RADIAN == qUnits(index.row()))
158159
{
159-
q(index.row()) = value.value<rl::math::Real>() * rl::math::DEG2RAD;
160+
q(index.row()) = value.value<rl::math::Real>() * rl::math::constants::deg2rad;
160161
}
161162
else
162163
{

demos/rlCoachKin/OperationalModel.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
// POSSIBILITY OF SUCH DAMAGE.
2525
//
2626

27+
#include <rl/math/Constants.h>
2728
#include <rl/math/Rotation.h>
28-
#include <rl/math/Unit.h>
2929
#include <rl/sg/Body.h>
3030

3131
#include "ConfigurationModel.h"
@@ -85,7 +85,7 @@ OperationalModel::data(const QModelIndex& index, int role) const
8585
case 3:
8686
case 4:
8787
case 5:
88-
return QString::number(orientation(index.column() - 3) * rl::math::RAD2DEG, 'f', 2) + QChar(176);
88+
return QString::number(orientation(index.column() - 3) * rl::math::constants::rad2deg, 'f', 2) + QChar(176);
8989
break;
9090
default:
9191
break;
@@ -102,7 +102,7 @@ OperationalModel::data(const QModelIndex& index, int role) const
102102
case 3:
103103
case 4:
104104
case 5:
105-
return orientation(index.column() - 3) * rl::math::RAD2DEG;
105+
return orientation(index.column() - 3) * rl::math::constants::rad2deg;
106106
break;
107107
default:
108108
break;
@@ -207,19 +207,19 @@ OperationalModel::setData(const QModelIndex& index, const QVariant& value, int r
207207
transform.linear() = (
208208
rl::math::AngleAxis(orientation.z(), rl::math::Vector3::UnitZ()) *
209209
rl::math::AngleAxis(orientation.y(), rl::math::Vector3::UnitY()) *
210-
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::DEG2RAD, rl::math::Vector3::UnitX())
210+
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::constants::deg2rad, rl::math::Vector3::UnitX())
211211
).toRotationMatrix();
212212
break;
213213
case 4:
214214
transform.linear() = (
215215
rl::math::AngleAxis(orientation.z(), rl::math::Vector3::UnitZ()) *
216-
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::DEG2RAD, rl::math::Vector3::UnitY()) *
216+
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::constants::deg2rad, rl::math::Vector3::UnitY()) *
217217
rl::math::AngleAxis(orientation.x(), rl::math::Vector3::UnitX())
218218
).toRotationMatrix();
219219
break;
220220
case 5:
221221
transform.linear() = (
222-
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::DEG2RAD, rl::math::Vector3::UnitZ()) *
222+
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::constants::deg2rad, rl::math::Vector3::UnitZ()) *
223223
rl::math::AngleAxis(orientation.y(), rl::math::Vector3::UnitY()) *
224224
rl::math::AngleAxis(orientation.x(), rl::math::Vector3::UnitX())
225225
).toRotationMatrix();

demos/rlCoachMdl/ConfigurationDelegate.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include <QDoubleSpinBox>
2828
#include <QModelIndex>
29-
#include <rl/math/Unit.h>
29+
#include <rl/math/Constants.h>
3030
#include <rl/mdl/Kinematic.h>
3131
#include <rl/mdl/Revolute.h>
3232

@@ -56,8 +56,8 @@ ConfigurationDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem&
5656
if (rl::math::UNIT_RADIAN == qUnits(index.row()))
5757
{
5858
editor->setDecimals(2);
59-
editor->setMinimum(minimum(index.row()) * rl::math::RAD2DEG);
60-
editor->setMaximum(maximum(index.row()) * rl::math::RAD2DEG);
59+
editor->setMinimum(minimum(index.row()) * rl::math::constants::rad2deg);
60+
editor->setMaximum(maximum(index.row()) * rl::math::constants::rad2deg);
6161
editor->setSingleStep(1.0);
6262
}
6363
else

demos/rlCoachMdl/ConfigurationModel.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// POSSIBILITY OF SUCH DAMAGE.
2525
//
2626

27-
#include <rl/math/Unit.h>
27+
#include <rl/math/Constants.h>
2828
#include <rl/mdl/Kinematic.h>
2929
#include <rl/mdl/Revolute.h>
3030
#include <rl/sg/Body.h>
@@ -75,7 +75,7 @@ ConfigurationModel::data(const QModelIndex& index, int role) const
7575
return QString::number(q(index.row()), 'f', 4) + QString(" m");
7676
break;
7777
case rl::math::UNIT_RADIAN:
78-
return QString::number(q(index.row()) * rl::math::RAD2DEG, 'f', 2) + QChar(176);
78+
return QString::number(q(index.row()) * rl::math::constants::rad2deg, 'f', 2) + QChar(176);
7979
break;
8080
default:
8181
return q(index.row());
@@ -85,7 +85,7 @@ ConfigurationModel::data(const QModelIndex& index, int role) const
8585
case Qt::EditRole:
8686
if (rl::math::UNIT_RADIAN == qUnits(index.row()))
8787
{
88-
return q(index.row()) * rl::math::RAD2DEG;
88+
return q(index.row()) * rl::math::constants::rad2deg;
8989
}
9090
else
9191
{
@@ -184,7 +184,7 @@ ConfigurationModel::setData(const QModelIndex& index, const QVariant& value, int
184184

185185
if (rl::math::UNIT_RADIAN == qUnits(index.row()))
186186
{
187-
q(index.row()) = value.value<rl::math::Real>() * rl::math::DEG2RAD;
187+
q(index.row()) = value.value<rl::math::Real>() * rl::math::constants::deg2rad;
188188
}
189189
else
190190
{

demos/rlCoachMdl/OperationalModel.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
//
2626

2727
#include <QStatusBar>
28+
#include <rl/math/Constants.h>
2829
#include <rl/math/Rotation.h>
29-
#include <rl/math/Unit.h>
3030
#include <rl/mdl/Exception.h>
3131
#include <rl/mdl/Kinematic.h>
3232
#include <rl/mdl/JacobianInverseKinematics.h>
@@ -93,7 +93,7 @@ OperationalModel::data(const QModelIndex& index, int role) const
9393
case 3:
9494
case 4:
9595
case 5:
96-
return QString::number(orientation(index.column() - 3) * rl::math::RAD2DEG, 'f', 2) + QChar(176);
96+
return QString::number(orientation(index.column() - 3) * rl::math::constants::rad2deg, 'f', 2) + QChar(176);
9797
break;
9898
default:
9999
break;
@@ -110,7 +110,7 @@ OperationalModel::data(const QModelIndex& index, int role) const
110110
case 3:
111111
case 4:
112112
case 5:
113-
return orientation(index.column() - 3) * rl::math::RAD2DEG;
113+
return orientation(index.column() - 3) * rl::math::constants::rad2deg;
114114
break;
115115
default:
116116
break;
@@ -217,19 +217,19 @@ OperationalModel::setData(const QModelIndex& index, const QVariant& value, int r
217217
transform.linear() = (
218218
rl::math::AngleAxis(orientation.z(), rl::math::Vector3::UnitZ()) *
219219
rl::math::AngleAxis(orientation.y(), rl::math::Vector3::UnitY()) *
220-
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::DEG2RAD, rl::math::Vector3::UnitX())
220+
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::constants::deg2rad, rl::math::Vector3::UnitX())
221221
).toRotationMatrix();
222222
break;
223223
case 4:
224224
transform.linear() = (
225225
rl::math::AngleAxis(orientation.z(), rl::math::Vector3::UnitZ()) *
226-
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::DEG2RAD, rl::math::Vector3::UnitY()) *
226+
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::constants::deg2rad, rl::math::Vector3::UnitY()) *
227227
rl::math::AngleAxis(orientation.x(), rl::math::Vector3::UnitX())
228228
).toRotationMatrix();
229229
break;
230230
case 5:
231231
transform.linear() = (
232-
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::DEG2RAD, rl::math::Vector3::UnitZ()) *
232+
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::constants::deg2rad, rl::math::Vector3::UnitZ()) *
233233
rl::math::AngleAxis(orientation.y(), rl::math::Vector3::UnitY()) *
234234
rl::math::AngleAxis(orientation.x(), rl::math::Vector3::UnitX())
235235
).toRotationMatrix();
@@ -287,7 +287,7 @@ OperationalModel::setData(const QModelIndex& index, const QVariant& value, int r
287287

288288
if (solved)
289289
{
290-
MainWindow::instance()->statusBar()->showMessage("IK solved in " + QString::number(std::chrono::duration<double>(stop - start).count() * rl::math::UNIT2MILLI) + " ms", 2000);
290+
MainWindow::instance()->statusBar()->showMessage("IK solved in " + QString::number(std::chrono::duration<double>(stop - start).count() * rl::math::constants::unit2milli) + " ms", 2000);
291291

292292
kinematic->forwardPosition();
293293

demos/rlCollisionDemo/BodyModel.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
// POSSIBILITY OF SUCH DAMAGE.
2525
//
2626

27+
#include <rl/math/Constants.h>
2728
#include <rl/math/Rotation.h>
28-
#include <rl/math/Unit.h>
2929

3030
#include "BodyModel.h"
3131
#include "MainWindow.h"
@@ -77,7 +77,7 @@ BodyModel::data(const QModelIndex& index, int role) const
7777
case 3:
7878
case 4:
7979
case 5:
80-
return QString::number(orientation(index.row() - 3) * rl::math::RAD2DEG, 'f', 2) + QChar(176);
80+
return QString::number(orientation(index.row() - 3) * rl::math::constants::rad2deg, 'f', 2) + QChar(176);
8181
break;
8282
default:
8383
break;
@@ -94,7 +94,7 @@ BodyModel::data(const QModelIndex& index, int role) const
9494
case 3:
9595
case 4:
9696
case 5:
97-
return orientation(index.row() - 3) * rl::math::RAD2DEG;
97+
return orientation(index.row() - 3) * rl::math::constants::rad2deg;
9898
break;
9999
default:
100100
break;
@@ -204,19 +204,19 @@ BodyModel::setData(const QModelIndex& index, const QVariant& value, int role)
204204
transform.linear() = (
205205
rl::math::AngleAxis(orientation.z(), rl::math::Vector3::UnitZ()) *
206206
rl::math::AngleAxis(orientation.y(), rl::math::Vector3::UnitY()) *
207-
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::DEG2RAD, rl::math::Vector3::UnitX())
207+
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::constants::deg2rad, rl::math::Vector3::UnitX())
208208
).toRotationMatrix();
209209
break;
210210
case 4:
211211
transform.linear() = (
212212
rl::math::AngleAxis(orientation.z(), rl::math::Vector3::UnitZ()) *
213-
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::DEG2RAD, rl::math::Vector3::UnitY()) *
213+
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::constants::deg2rad, rl::math::Vector3::UnitY()) *
214214
rl::math::AngleAxis(orientation.x(), rl::math::Vector3::UnitX())
215215
).toRotationMatrix();
216216
break;
217217
case 5:
218218
transform.linear() = (
219-
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::DEG2RAD, rl::math::Vector3::UnitZ()) *
219+
rl::math::AngleAxis(value.value<rl::math::Real>() * rl::math::constants::deg2rad, rl::math::Vector3::UnitZ()) *
220220
rl::math::AngleAxis(orientation.y(), rl::math::Vector3::UnitY()) *
221221
rl::math::AngleAxis(orientation.x(), rl::math::Vector3::UnitX())
222222
).toRotationMatrix();

demos/rlDenavitHartenbergDemo/rlDenavitHartenbergDemo.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@
2525
//
2626

2727
#include <iostream>
28+
#include <rl/math/Constants.h>
2829
#include <rl/math/Matrix.h>
2930
#include <rl/math/Rotation.h>
3031
#include <rl/math/Transform.h>
31-
#include <rl/math/Unit.h>
3232
#include <rl/math/Vector.h>
3333

3434
int
3535
main(int argc, char** argv)
3636
{
3737
rl::math::Real a = 31;
38-
rl::math::Real alpha = 271 * rl::math::DEG2RAD;
38+
rl::math::Real alpha = 271 * rl::math::constants::deg2rad;
3939
rl::math::Real d = 101;
40-
rl::math::Real theta = 181 * rl::math::DEG2RAD;
40+
rl::math::Real theta = 181 * rl::math::constants::deg2rad;
4141

4242
rl::math::Transform t_d(rl::math::Translation(0, 0, d));
4343

@@ -75,9 +75,9 @@ main(int argc, char** argv)
7575
dh.toDenavitHartenbergPaul(d, theta, a, alpha);
7676

7777
std::cout << "a = " << a << std::endl;
78-
std::cout << "alpha = " << alpha * rl::math::RAD2DEG << std::endl;
78+
std::cout << "alpha = " << alpha * rl::math::constants::rad2deg << std::endl;
7979
std::cout << "d = " << d << std::endl;
80-
std::cout << "theta = " << theta * rl::math::RAD2DEG << std::endl;
80+
std::cout << "theta = " << theta * rl::math::constants::rad2deg << std::endl;
8181

8282
return EXIT_SUCCESS;
8383
}

demos/rlDynamics2Demo/rlDynamics2Demo.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <memory>
2929
#include <stdexcept>
3030
#include <boost/lexical_cast.hpp>
31-
#include <rl/math/Unit.h>
31+
#include <rl/math/Constants.h>
3232
#include <rl/mdl/Dynamic.h>
3333
#include <rl/mdl/UrdfFactory.h>
3434
#include <rl/mdl/XmlFactory.h>
@@ -81,7 +81,7 @@ main(int argc, char** argv)
8181
dynamic->forwardPosition();
8282
const rl::math::Transform::ConstTranslationPart& position = dynamic->getOperationalPosition(0).translation();
8383
rl::math::Vector3 orientation = dynamic->getOperationalPosition(0).rotation().eulerAngles(2, 1, 0).reverse();
84-
std::cout << "x = " << position.x() << " m, y = " << position.y() << " m, z = " << position.z() << " m, a = " << orientation.x() * rl::math::RAD2DEG << " deg, b = " << orientation.y() * rl::math::RAD2DEG << " deg, c = " << orientation.z() * rl::math::RAD2DEG << " deg" << std::endl;
84+
std::cout << "x = " << position.x() << " m, y = " << position.y() << " m, z = " << position.z() << " m, a = " << orientation.x() * rl::math::constants::rad2deg << " deg, b = " << orientation.y() * rl::math::constants::rad2deg << " deg, c = " << orientation.z() * rl::math::constants::rad2deg << " deg" << std::endl;
8585

8686
std::cout << "===============================================================================" << std::endl;
8787

demos/rlEulerAnglesDemo/rlEulerAnglesDemo.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
#include <iostream>
2828
#include <boost/lexical_cast.hpp>
29+
#include <rl/math/Constants.h>
2930
#include <rl/math/Quaternion.h>
3031
#include <rl/math/Rotation.h>
31-
#include <rl/math/Unit.h>
3232
#include <rl/math/Vector.h>
3333

3434
int
@@ -44,7 +44,7 @@ main(int argc, char** argv)
4444

4545
for (std::size_t i = 0; i < 3; ++i)
4646
{
47-
rl::math::Real angle = boost::lexical_cast<rl::math::Real>(argv[i + 4]) * rl::math::DEG2RAD;
47+
rl::math::Real angle = boost::lexical_cast<rl::math::Real>(argv[i + 4]) * rl::math::constants::deg2rad;
4848

4949
rl::math::Vector3 axis(
5050
0 == boost::lexical_cast<int>(argv[i + 1]) ? 1 : 0,
@@ -65,7 +65,7 @@ main(int argc, char** argv)
6565
std::cout << "angle: " << angleAxis.angle() << " rad - axis: " << angleAxis.axis().transpose() << std::endl;
6666

6767
rl::math::Vector3 orientation = rotation.eulerAngles(2, 1, 0).reverse();
68-
std::cout << "x: " << orientation.x() * rl::math::RAD2DEG << " deg - y: " << orientation.y() * rl::math::RAD2DEG << " deg - z: " << orientation.z() * rl::math::RAD2DEG << " deg" << std::endl;
68+
std::cout << "x: " << orientation.x() * rl::math::constants::rad2deg << " deg - y: " << orientation.y() * rl::math::constants::rad2deg << " deg - z: " << orientation.z() * rl::math::constants::rad2deg << " deg" << std::endl;
6969

7070
return EXIT_SUCCESS;
7171
}

0 commit comments

Comments
 (0)