Brick
Toggle main menu visibility
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
7
using namespace
units::literals
;
8
9
/**
10
* @brief Represents robot chassis accelerations.
11
*/
12
struct
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
};
LinearVector2d::x
constexpr Q x() const
Gets the x component.
Definition
translation2d.h:64
LinearVector2d::y
constexpr Q y() const
Gets the y component.
Definition
translation2d.h:73
Rotation2d
Definition
rotation2d.h:16
units::literals
Definition
units.h:691
ChassisAccelerations
Represents robot chassis accelerations.
Definition
chassis_accelerations.h:12
ChassisAccelerations::ay
units::Acceleration ay
Acceleration along the y-axis. (Left is positive).
Definition
chassis_accelerations.h:17
ChassisAccelerations::ax
units::Acceleration ax
Acceleration along the x-axis. (Forward is positive).
Definition
chassis_accelerations.h:14
ChassisAccelerations::to_field_relative
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
ChassisAccelerations::alpha
units::AngularAcceleration alpha
Angular acceleration of the robot frame. (Counter-Clockwise is positive).
Definition
chassis_accelerations.h:20
ChassisAccelerations::to_robot_relative
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
core
math
kinematics
chassis_accelerations.h
Generated by
1.18.0