WPILibC++ 2023.4.3-108-ge5452e3
Twist3d.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <wpi/SymbolExports.h>
8
10#include "units/angle.h"
11#include "units/length.h"
12#include "units/math.h"
13
14namespace frc {
15/**
16 * A change in distance along a 3D arc since the last pose update. We can use
17 * ideas from differential calculus to create new Pose3ds from a Twist3d and
18 * vice versa.
19 *
20 * A Twist can be used to represent a difference between two poses.
21 */
23 /**
24 * Linear "dx" component
25 */
26 units::meter_t dx = 0_m;
27
28 /**
29 * Linear "dy" component
30 */
31 units::meter_t dy = 0_m;
32
33 /**
34 * Linear "dz" component
35 */
36 units::meter_t dz = 0_m;
37
38 /**
39 * Rotation vector x component.
40 */
41 units::radian_t rx = 0_rad;
42
43 /**
44 * Rotation vector y component.
45 */
46 units::radian_t ry = 0_rad;
47
48 /**
49 * Rotation vector z component.
50 */
51 units::radian_t rz = 0_rad;
52
53 /**
54 * Checks equality between this Twist3d and another object.
55 *
56 * @param other The other object.
57 * @return Whether the two objects are equal.
58 */
59 bool operator==(const Twist3d& other) const {
60 return units::math::abs(dx - other.dx) < 1E-9_m &&
61 units::math::abs(dy - other.dy) < 1E-9_m &&
62 units::math::abs(dz - other.dz) < 1E-9_m &&
63 units::math::abs(rx - other.rx) < 1E-9_rad &&
64 units::math::abs(ry - other.ry) < 1E-9_rad &&
65 units::math::abs(rz - other.rz) < 1E-9_rad;
66 }
67
68 /**
69 * Scale this by a given factor.
70 *
71 * @param factor The factor by which to scale.
72 * @return The scaled Twist3d.
73 */
74 constexpr Twist3d operator*(double factor) const {
75 return Twist3d{dx * factor, dy * factor, dz * factor,
76 rx * factor, ry * factor, rz * factor};
77 }
78};
79} // namespace frc
#define WPILIB_DLLEXPORT
Definition: SymbolExports.h:36
UnitType abs(const UnitType x) noexcept
Compute absolute value.
Definition: math.h:721
Definition: AprilTagPoseEstimator.h:15
A change in distance along a 3D arc since the last pose update.
Definition: Twist3d.h:22
constexpr Twist3d operator*(double factor) const
Scale this by a given factor.
Definition: Twist3d.h:74
units::meter_t dx
Linear "dx" component.
Definition: Twist3d.h:26
units::radian_t ry
Rotation vector y component.
Definition: Twist3d.h:46
bool operator==(const Twist3d &other) const
Checks equality between this Twist3d and another object.
Definition: Twist3d.h:59
units::meter_t dy
Linear "dy" component.
Definition: Twist3d.h:31
units::radian_t rz
Rotation vector z component.
Definition: Twist3d.h:51
units::meter_t dz
Linear "dz" component.
Definition: Twist3d.h:36
units::radian_t rx
Rotation vector x component.
Definition: Twist3d.h:41