Brick
Loading...
Searching...
No Matches
chassis_accelerations.h
1#pragma once
2
3#include "core/math/geometry/rotation2d.h"
4#include "core/math/geometry/translation2d.h"
5#include "core/math/units.h"
6
7using namespace units::literals;
8
9/**
10 * @brief Represents robot chassis accelerations.
11 */
12struct ChassisAccelerations {
13 /** @brief Acceleration along the x-axis. (Forward is positive) */
14 units::Acceleration ax = 0_inps2;
15
16 /** @brief Acceleration along the y-axis. (Left is positive) */
17 units::Acceleration ay = 0_inps2;
18
19 /** @brief Angular acceleration of the robot frame. (Counter-Clockwise is positive) */
20 units::AngularAcceleration alpha = 0_radps2;
21
22 ChassisAccelerations() = default;
23
24 ChassisAccelerations(
25 units::Acceleration ax, units::Acceleration ay, units::AngularAcceleration alpha
26 )
27 : ax(ax), ay(ay), alpha(alpha) {}
28
29 /**
30 * @brief Converts this field-relative set of accelerations into a robot-relative
31 * ChassisAccelerations object.
32 * @param robotAngle The CCW-positive angle of the robot relative to the field.
33 * @return Robot-relative ChassisAccelerations.
34 */
35 ChassisAccelerations to_robot_relative(const Rotation2d& robotAngle) const {
36 Acceleration2d rotated = Acceleration2d(ax, ay).rotate_by(-robotAngle);
37 return ChassisAccelerations(rotated.x(), rotated.y(), alpha);
38 }
39
40 /**
41 * @brief Converts this robot-relative set of accelerations into a field-relative
42 * ChassisAccelerations object.
43 * @param robotAngle The CCW-positive angle of the robot relative to the field.
44 * @return Field-relative ChassisAccelerations.
45 */
46 ChassisAccelerations to_field_relative(const Rotation2d& robotAngle) const {
47 Acceleration2d rotated = Acceleration2d(ax, ay).rotate_by(robotAngle);
48 return ChassisAccelerations(rotated.x(), rotated.y(), alpha);
49 }
50
51 // Operator overloads
52 ChassisAccelerations operator+(const ChassisAccelerations& other) const {
53 return ChassisAccelerations(ax + other.ax, ay + other.ay, alpha + other.alpha);
54 }
55
56 ChassisAccelerations operator-(const ChassisAccelerations& other) const {
57 return ChassisAccelerations(ax - other.ax, ay - other.ay, alpha - other.alpha);
58 }
59
60 ChassisAccelerations operator-() const { return ChassisAccelerations(-ax, -ay, -alpha); }
61
62 ChassisAccelerations operator*(double scalar) const {
63 return ChassisAccelerations(ax * scalar, ay * scalar, alpha * scalar);
64 }
65
66 ChassisAccelerations operator/(double scalar) const {
67 return ChassisAccelerations(ax / scalar, ay / scalar, alpha / scalar);
68 }
69
70 bool operator==(const ChassisAccelerations& other) const {
71 return ax == other.ax && ay == other.ay && alpha == other.alpha;
72 }
73
74 bool operator!=(const ChassisAccelerations& other) const { return !(*this == other); }
75};
constexpr Q x() const
Gets the x component.
Definition translation2d.h:64
constexpr Q y() const
Gets the y component.
Definition translation2d.h:73
Definition rotation2d.h:16
Definition units.h:691
Represents robot chassis accelerations.
Definition chassis_accelerations.h:12
units::Acceleration ay
Acceleration along the y-axis. (Left is positive).
Definition chassis_accelerations.h:17
units::Acceleration ax
Acceleration along the x-axis. (Forward is positive).
Definition chassis_accelerations.h:14
ChassisAccelerations to_field_relative(const Rotation2d &robotAngle) const
Converts this robot-relative set of accelerations into a field-relative ChassisAccelerations object.
Definition chassis_accelerations.h:46
units::AngularAcceleration alpha
Angular acceleration of the robot frame. (Counter-Clockwise is positive).
Definition chassis_accelerations.h:20
ChassisAccelerations to_robot_relative(const Rotation2d &robotAngle) const
Converts this field-relative set of accelerations into a robot-relative ChassisAccelerations object.
Definition chassis_accelerations.h:35