Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
transform.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2022-2024 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_TRANSFORM_HPP_
25#define TAPROOT_TRANSFORM_HPP_
26
29
30#include "angular_velocity.hpp"
32#include "dynamic_position.hpp"
33#include "orientation.hpp"
34#include "position.hpp"
35#include "vector.hpp"
36
38{
60{
61public:
66 Transform(const Position& translation, const Orientation& rotation);
67 Transform(Position&& translation, Orientation&& rotation);
68
73 Transform(const CMSISMat<3, 1>& translation, const CMSISMat<3, 3>& rotation);
74 Transform(CMSISMat<3, 1>&& translation, CMSISMat<3, 3>&& rotation);
75
89 Transform(float x, float y, float z, float rx, float ry, float rz);
90
99 const Position& translation,
100 const Orientation& rotation,
101 const Vector& velocity,
102 const Vector& acceleration,
103 const Vector& angularVelocity);
104
112 Transform(
113 Position&& translation,
114 Orientation&& rotation,
115 Vector&& velocity,
116 Vector&& acceleration,
117 Vector&& angularVelocity);
118
123 Transform(const DynamicPosition& dynamicPosition, const DynamicOrientation& dynamicOrientation);
124 Transform(DynamicPosition&& dynamicPosition, DynamicOrientation&& dynamicOrientation);
125
133 Transform(
134 const CMSISMat<3, 1>& translation,
135 const CMSISMat<3, 3>& rotation,
136 const CMSISMat<3, 1>& velocity,
137 const CMSISMat<3, 1>& acceleration,
138 const CMSISMat<3, 3>& angularVelocity);
139
147 Transform(
148 CMSISMat<3, 1>&& translation,
149 CMSISMat<3, 3>&& rotation,
150 CMSISMat<3, 1>&& velocity,
151 CMSISMat<3, 1>&& acceleration,
152 CMSISMat<3, 3>&& angularVelocity);
153
174 Transform(
175 float x,
176 float y,
177 float z,
178 float vx,
179 float vy,
180 float vz,
181 float ax,
182 float ay,
183 float az,
184 float rx,
185 float ry,
186 float rz,
187 float wx,
188 float wy,
189 float wz);
190
194 static inline Transform identity() { return Transform(0., 0., 0., 0., 0., 0.); }
195
202 Position apply(const Position& position) const;
203
216 Vector apply(const Vector& vector) const;
217
221 DynamicPosition apply(const DynamicPosition& dynamicPosition) const;
222
226 Orientation apply(const Orientation& orientation) const;
227
231 DynamicOrientation apply(const DynamicOrientation& dynamicOrientation) const;
232
238 inline void updateTranslation(const Position& newTranslation)
239 {
240 this->translation = newTranslation.coordinates();
241 }
242
248 inline void updateTranslation(Position&& newTranslation)
249 {
250 this->translation = std::move(newTranslation.coordinates());
251 }
252
260 inline void updateTranslation(float x, float y, float z)
261 {
262 this->translation = CMSISMat<3, 1>({x, y, z});
263 }
264
270 inline void updateTranslation(const DynamicPosition& newTranslation)
271 {
272 this->translation = newTranslation.position;
273 this->transVel = newTranslation.velocity;
274 this->transAcc = newTranslation.acceleration;
275 }
276
282 inline void updateTranslation(DynamicPosition&& newTranslation)
283 {
284 this->translation = std::move(newTranslation.position);
285 this->transVel = std::move(newTranslation.velocity);
286 this->transAcc = std::move(newTranslation.acceleration);
287 }
288
294 inline void updateRotation(const Orientation& newRotation)
295 {
296 this->rotation = newRotation.matrix();
297 this->tRotation = this->rotation.transpose();
298 }
299
305 inline void updateRotation(Orientation&& newRotation)
306 {
307 this->rotation = std::move(newRotation.matrix());
308 this->tRotation = this->rotation.transpose();
309 }
310
319 void updateRotation(float roll, float pitch, float yaw)
320 {
321 this->rotation = Orientation(roll, pitch, yaw).matrix();
322 this->tRotation = this->rotation.transpose();
323 }
324
330 inline void updateRotation(const DynamicOrientation& newRotation)
331 {
332 this->rotation = newRotation.orientation;
333 this->tRotation = this->rotation.transpose();
334 this->angVel = newRotation.angularVelocity;
335 }
336
342 inline void updateRotation(DynamicOrientation&& newRotation)
343 {
344 this->rotation = std::move(newRotation.orientation);
345 this->tRotation = this->rotation.transpose();
346 this->angVel = std::move(newRotation.angularVelocity);
347 }
348
354 inline void updateVelocity(const Vector& newVelocity)
355 {
356 this->transVel = newVelocity.coordinates();
357 checkDynamic();
358 }
359
365 inline void updateVelocity(Vector&& newVelocity)
366 {
367 this->transVel = std::move(newVelocity.coordinates());
368 checkDynamic();
369 }
370
378 inline void updateVelocity(float vx, float vy, float vz)
379 {
380 this->transVel = CMSISMat<3, 1>({vx, vy, vz});
381 checkDynamic();
382 }
383
389 inline void updateAcceleration(const Vector& newAcceleration)
390 {
391 this->transVel = newAcceleration.coordinates();
392 checkDynamic();
393 }
394
400 inline void updateAcceleration(Vector&& newAcceleration)
401 {
402 this->transVel = std::move(newAcceleration.coordinates());
403 checkDynamic();
404 }
405
413 inline void updateAcceleration(float ax, float ay, float az)
414 {
415 this->transAcc = CMSISMat<3, 1>({ax, ay, az});
416 checkDynamic();
417 }
418
424 inline void updateAngularVelocity(const Vector& newAngularVelocity)
425 {
427 newAngularVelocity.x(),
428 newAngularVelocity.y(),
429 newAngularVelocity.z());
430 checkDynamic();
431 }
432
438 inline void updateAngularVelocity(Position&& newAngularVelocity)
439 {
441 newAngularVelocity.x(),
442 newAngularVelocity.y(),
443 newAngularVelocity.z());
444 checkDynamic();
445 }
446
454 inline void updateAngularVelocity(float vr, float vp, float vy)
455 {
456 this->angVel = AngularVelocity::skewMatFromAngVel(vr, vp, vy);
457 checkDynamic();
458 }
459
473 Transform getInverse() const;
474
480 Transform compose(const Transform& second) const;
481
489 Transform composeStatic(const Transform& second) const;
490
498 Transform projectForward(float dt) const;
499
500 /* Getters */
501 inline Position getTranslation() const { return Position(translation); };
502
503 inline Vector getVelocity() const { return Vector(transVel); };
504
505 inline Vector getAcceleration() const { return Vector(transAcc); };
506
508 {
509 return DynamicPosition(translation, transVel, transAcc);
510 };
511
512 inline Orientation getRotation() const { return Orientation(rotation); }
513
514 inline Vector getAngularVel() const
515 {
517 }
518
520 {
521 return DynamicOrientation(rotation, angVel);
522 };
523
527 float getRoll() const;
528
532 float getPitch() const;
533
537 float getYaw() const;
538
542 float getRollVelocity() const;
543
547 float getPitchVelocity() const;
548
552 float getYawVelocity() const;
553
557 inline float getX() const { return this->translation.data[0]; }
558
562 inline float getY() const { return this->translation.data[1]; }
563
567 inline float getZ() const { return this->translation.data[2]; }
568
572 inline float getXVel() const { return this->transVel.data[0]; }
573
577 inline float getYVel() const { return this->transVel.data[1]; }
578
582 inline float getZVel() const { return this->transVel.data[2]; }
583
587 inline float getXAcc() const { return this->transAcc.data[0]; }
588
592 inline float getYAcc() const { return this->transAcc.data[1]; }
593
597 inline float getZAcc() const { return this->transAcc.data[2]; }
598
602 inline bool isDynamic() const { return dynamic; }
603
604private:
605 bool dynamic{true};
606
610 CMSISMat<3, 1> translation;
611
615 CMSISMat<3, 1> transVel;
616
620 CMSISMat<3, 1> transAcc;
621
625 CMSISMat<3, 3> rotation;
626
633 CMSISMat<3, 3> tRotation;
634
638 CMSISMat<3, 3> angVel;
639
640 inline void checkDynamic()
641 {
642 dynamic = false;
643
644 dynamic |=
645 !(compareFloatClose(getXVel(), 0, 1e-5) && compareFloatClose(getYVel(), 0, 1e-5) &&
646 compareFloatClose(getZVel(), 0, 1e-5));
647
648 dynamic |=
649 !(compareFloatClose(getXAcc(), 0, 1e-5) && compareFloatClose(getYAcc(), 0, 1e-5) &&
650 compareFloatClose(getZAcc(), 0, 1e-5));
651
652 dynamic |=
653 !(compareFloatClose(getRollVelocity(), 0, 1e-5) &&
656 }
657}; // class Transform
658} // namespace tap::algorithms::transforms
659
660#endif // TAPROOT_TRANSFORM_HPP_
static CMSISMat< 3, 3 > skewMatFromAngVel(const float wx, const float wy, const float wz)
Definition angular_velocity.hpp:70
Definition dynamic_orientation.hpp:34
Definition dynamic_position.hpp:35
Definition orientation.hpp:33
const CMSISMat< 3, 3 > & matrix() const
Definition orientation.hpp:68
Definition position.hpp:35
CMSISMat< 3, 1 > coordinates() const
Definition position.hpp:72
Definition transform.hpp:60
void updateTranslation(const Position &newTranslation)
Updates the translation of the current transformation matrix.
Definition transform.hpp:238
Position getTranslation() const
Definition transform.hpp:501
float getX() const
Get the x-component of this transform's translation.
Definition transform.hpp:557
void updateVelocity(const Vector &newVelocity)
Updates the velocity of the current transform.
Definition transform.hpp:354
Orientation getRotation() const
Definition transform.hpp:512
Transform composeStatic(const Transform &second) const
Returns the composed transformation of the given transformations, ignoring any time derivatives.
Definition transform.cpp:293
float getZVel() const
Get the z-component of this transform's linear velocity.
Definition transform.hpp:582
Vector getVelocity() const
Definition transform.hpp:503
void updateTranslation(float x, float y, float z)
Updates the translation of the current transformation matrix.
Definition transform.hpp:260
void updateAcceleration(Vector &&newAcceleration)
Updates the acceleration of the current transform.
Definition transform.hpp:400
static Transform identity()
Constructs an identity transform.
Definition transform.hpp:194
Position apply(const Position &position) const
Apply this transform to a position.
Definition transform.cpp:205
Vector getAcceleration() const
Definition transform.hpp:505
void updateRotation(DynamicOrientation &&newRotation)
Updates the rotation of the current transformation matrix.
Definition transform.hpp:342
float getPitch() const
Get the pitch of this transformation.
Definition transform.cpp:344
void updateTranslation(Position &&newTranslation)
Updates the translation of the current transformation matrix.
Definition transform.hpp:248
void updateAngularVelocity(float vr, float vp, float vy)
Updates the angular velocity of the current transform.
Definition transform.hpp:454
float getXVel() const
Get the x-component of this transform's linear velocity.
Definition transform.hpp:572
void updateRotation(const DynamicOrientation &newRotation)
Updates the rotation of the current transformation matrix.
Definition transform.hpp:330
float getYaw() const
Get the yaw of this transformation.
Definition transform.cpp:352
void updateAngularVelocity(Position &&newAngularVelocity)
Updates the angular velocity of the current transform.
Definition transform.hpp:438
float getRollVelocity() const
Get the roll velocity of this transformation.
Definition transform.cpp:342
void updateRotation(Orientation &&newRotation)
Updates the rotation of the current transformation matrix.
Definition transform.hpp:305
DynamicOrientation getDynamicOrientation() const
Definition transform.hpp:519
float getYAcc() const
Get the y-component of this transform's linear acceleration.
Definition transform.hpp:592
float getXAcc() const
Get the x-component of this transform's linear acceleration.
Definition transform.hpp:587
float getYawVelocity() const
Get the yaw velocity of this transformation.
Definition transform.cpp:359
Transform getInverse() const
Definition transform.cpp:237
Vector getAngularVel() const
Definition transform.hpp:514
Transform projectForward(float dt) const
Projects this transform forward in time according to its translational velocity/acceleration and angu...
Definition transform.cpp:300
void updateVelocity(float vx, float vy, float vz)
Updates the velocity of the current transform.
Definition transform.hpp:378
void updateRotation(const Orientation &newRotation)
Updates the rotation of the current transformation matrix.
Definition transform.hpp:294
DynamicPosition getDynamicTranslation() const
Definition transform.hpp:507
void updateTranslation(const DynamicPosition &newTranslation)
Updates the translation of the current transformation matrix.
Definition transform.hpp:270
void updateRotation(float roll, float pitch, float yaw)
Updates the rotation of the current transformation matrix. Takes rotation angles in the order of roll...
Definition transform.hpp:319
void updateAngularVelocity(const Vector &newAngularVelocity)
Updates the angular velocity of the current transform.
Definition transform.hpp:424
float getY() const
Get the y-component of this transform's translation.
Definition transform.hpp:562
float getZAcc() const
Get the z-component of this transform's linear acceleration.
Definition transform.hpp:597
float getRoll() const
Get the roll of this transformation.
Definition transform.cpp:335
void updateVelocity(Vector &&newVelocity)
Updates the velocity of the current transform.
Definition transform.hpp:365
float getPitchVelocity() const
Get the pitch velocity of this transformation.
Definition transform.cpp:350
bool isDynamic() const
Whether there are any non-zero derivatives.
Definition transform.hpp:602
float getYVel() const
Get the y-component of this transform's linear velocity.
Definition transform.hpp:577
float getZ() const
Get the z-component of this transform's translation.
Definition transform.hpp:567
Transform compose(const Transform &second) const
Returns the composed transformation of the given transformations.
Definition transform.cpp:255
void updateAcceleration(const Vector &newAcceleration)
Updates the acceleration of the current transform.
Definition transform.hpp:389
void updateAcceleration(float ax, float ay, float az)
Updates the acceleration of the current transform.
Definition transform.hpp:413
void updateTranslation(DynamicPosition &&newTranslation)
Updates the translation of the current transformation matrix.
Definition transform.hpp:282
Definition vector.hpp:35
float y() const
Definition vector.hpp:52
float x() const
Definition vector.hpp:50
const CMSISMat< 3, 1 > & coordinates() const
Definition vector.hpp:85
float z() const
Definition vector.hpp:54
Definition angular_velocity.hpp:30
bool compareFloatClose(float val1, float val2, float epsilon)
Definition math_user_utils.hpp:57
Definition cmsis_mat.hpp:45
std::array< float, ROWS *COLS > data
Definition cmsis_mat.hpp:46