RIT VEXU Core API
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
12struct ChassisAccelerations {
14 units::Acceleration ax = 0_inps2;
15
17 units::Acceleration ay = 0_inps2;
18
20 units::AngularAcceleration alpha = 0_radps2;
21
22 ChassisAccelerations() = default;
23
24 ChassisAccelerations(units::Acceleration ax, units::Acceleration ay,
25 units::AngularAcceleration alpha)
26 : ax(ax), ay(ay), alpha(alpha) {}
27
34 ChassisAccelerations to_robot_relative(const Rotation2d& robotAngle) const {
35 Acceleration2d rotated = Acceleration2d(ax, ay).rotate_by(-robotAngle);
36 return ChassisAccelerations(rotated.x(), rotated.y(), alpha);
37 }
38
45 ChassisAccelerations to_field_relative(const Rotation2d& robotAngle) const {
46 Acceleration2d rotated = Acceleration2d(ax, ay).rotate_by(robotAngle);
47 return ChassisAccelerations(rotated.x(), rotated.y(), alpha);
48 }
49
50 // Operator overloads
51 ChassisAccelerations operator+(const ChassisAccelerations& other) const {
52 return ChassisAccelerations(ax + other.ax, ay + other.ay, alpha + other.alpha);
53 }
54
55 ChassisAccelerations operator-(const ChassisAccelerations& other) const {
56 return ChassisAccelerations(ax - other.ax, ay - other.ay, alpha - other.alpha);
57 }
58
59 ChassisAccelerations operator-() const { return ChassisAccelerations(-ax, -ay, -alpha); }
60
61 ChassisAccelerations operator*(double scalar) const {
62 return ChassisAccelerations(ax * scalar, ay * scalar, alpha * scalar);
63 }
64
65 ChassisAccelerations operator/(double scalar) const {
66 return ChassisAccelerations(ax / scalar, ay / scalar, alpha / scalar);
67 }
68
69 bool operator==(const ChassisAccelerations& other) const {
70 return ax == other.ax && ay == other.ay && alpha == other.alpha;
71 }
72
73 bool operator!=(const ChassisAccelerations& other) const { return !(*this == other); }
74};
constexpr Q x() const
Gets the x component.
Definition translation2d.h:65
constexpr Q y() const
Gets the y component.
Definition translation2d.h:74
Definition rotation2d.h:16
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:45
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:34