WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
Twist2d.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
9#include "units/angle.h"
10#include "units/length.h"
11#include "units/math.h"
12
13namespace frc {
14
15/**
16 * A change in distance along a 2D arc since the last pose update. We can use
17 * ideas from differential calculus to create new Pose2ds from a Twist2d 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 * Angular "dtheta" component (radians)
35 */
36 units::radian_t dtheta = 0_rad;
37
38 /**
39 * Checks equality between this Twist2d and another object.
40 *
41 * @param other The other object.
42 * @return Whether the two objects are equal.
43 */
44 constexpr bool operator==(const Twist2d& other) const {
45 return units::math::abs(dx - other.dx) < 1E-9_m &&
46 units::math::abs(dy - other.dy) < 1E-9_m &&
47 units::math::abs(dtheta - other.dtheta) < 1E-9_rad;
48 }
49
50 /**
51 * Scale this by a given factor.
52 *
53 * @param factor The factor by which to scale.
54 * @return The scaled Twist2d.
55 */
56 constexpr Twist2d operator*(double factor) const {
57 return Twist2d{dx * factor, dy * factor, dtheta * factor};
58 }
59};
60
61} // namespace frc
62
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
constexpr UnitType abs(const UnitType x) noexcept
Compute absolute value.
Definition math.h:726
Definition CAN.h:11
A change in distance along a 2D arc since the last pose update.
Definition Twist2d.h:22
constexpr Twist2d operator*(double factor) const
Scale this by a given factor.
Definition Twist2d.h:56
constexpr bool operator==(const Twist2d &other) const
Checks equality between this Twist2d and another object.
Definition Twist2d.h:44