Package tagalong.math
Class AlgebraicUtils
java.lang.Object
tagalong.math.AlgebraicUtils
Algebraic functions
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncart2pol
(double x, double y) static double
clamp
(double target, double min, double max) Clamps a target value between the minimum and maximum values, ensuring the value is in the given range.static double
constrainAngleNegPiToPi
(double angle) Constrains an angle to be within [-pi, pi).static double
cppMod
(double num, double denom) Returns a modulo result that matches the C++ rather than Java implementationstatic Pose2d
Obtain a new Pose2d from a (constant curvature) velocity.static double
extractTFMatrixYRot
(Matrix<N4, N4> matrix) Returns double Y rotation form the 4*4 matrix.static double
extractTFMatrixZ
(Matrix<N4, N4> matrix) Returns double z component from the 4*4 matrix.Transforms a 3D point into a given frame of reference using matrix operations.static boolean
inTolerance
(double position, double lowerBound, double upperBound) Units must be consistent between all 3 valuesstatic Twist2d
Logical inverse of the above.makeYRotTFMatrix
(double x, double y, double z, double theta) Creates a matrix about with rotation about the y-axis.makeZRotTFMatrix
(double x, double y, double z, double theta) static double
placeInScopeDeg
(double referenceAngleDeg, double desiredAngleDeg) Scopes the angle to be at most 180 degrees away from the reference anglestatic double
placeInScopeRad
(double referenceAngleRad, double desiredAngleRad) Scopes the angle to be at most pi radians away from the reference anglestatic double
placeInScopeRot
(double referenceAngleRot, double desiredAngleRot) Returns the desired angle in the closest scope of the current anglepol2cart
(double r, double theta) Converts polar coordinates to Cartesian coordinates.pose2DToZRotTFMatrix
(Pose2d pose) Converts the 2D pose into a matrix with a rotation around the z-axis.rotateVector
(Matrix<N2, N1> vector, double theta) Rotates a vector by a given angle.static Pose2d
zRotTFMatrixToPose
(Matrix<N4, N4> zRotTFMatrix) Converts matrix back into 2D pose.
-
Constructor Details
-
AlgebraicUtils
public AlgebraicUtils()
-
-
Method Details
-
cart2pol
- Parameters:
x
- Cartesian x coordinatey
- Cartesian y coordinate- Returns:
- pair representing the polar coordinate radius and theta in radians
-
pol2cart
Converts polar coordinates to Cartesian coordinates.- Parameters:
r
- radius in polar coordinatestheta
- angle in radians- Returns:
- pair of Cartesian coordinates x and y
-
constrainAngleNegPiToPi
Constrains an angle to be within [-pi, pi).- Parameters:
angle
- angle in radians- Returns:
- angle in radians that is between [-pi,pi]
-
placeInScopeRad
Scopes the angle to be at most pi radians away from the reference angle- Parameters:
referenceAngleRad
- Base of the scope to place the angle indesiredAngleRad
- Angle that should be placed in radians- Returns:
- |angle| placed within within [-pi, pi) of |referenceAngle|.
-
placeInScopeDeg
Scopes the angle to be at most 180 degrees away from the reference angle- Parameters:
referenceAngleDeg
- Base of the scope to place the angle indesiredAngleDeg
- Angle that should be placed in degrees- Returns:
- |angle| placed within within [-180, 180) of |referenceAngle|.
-
placeInScopeRot
Returns the desired angle in the closest scope of the current angle- Parameters:
referenceAngleRot
- Current angle in rotationsdesiredAngleRot
- Target angle in rotations- Returns:
- Scoped angle in rotations
-
rotateVector
Rotates a vector by a given angle.- Parameters:
vector
- initial vectortheta
- desired angle rotation- Returns:
- rotated vector as a matrix
-
extractTFMatrixZ
Returns double z component from the 4*4 matrix.- Parameters:
matrix
- 4*4 Matrix- Returns:
- double Z component from the matrix
-
extractTFMatrixYRot
Returns double Y rotation form the 4*4 matrix.- Parameters:
matrix
- 4*4 matrix- Returns:
- double Y rotation from the matrix
-
pose2DToZRotTFMatrix
Converts the 2D pose into a matrix with a rotation around the z-axis.- Parameters:
pose
- 2D position of the robot on the field- Returns:
- Transformation matrix from Pose2d
-
zRotTFMatrixToPose
Converts matrix back into 2D pose.- Parameters:
zRotTFMatrix
- a 4x4 matrix representing a 2D affine transformation with translation and rotation- Returns:
- Pose2d
-
getPointInFrame
Transforms a 3D point into a given frame of reference using matrix operations.- Parameters:
point
- 3x1 column matrix representing the coordinates of a point. ---not sure if this is rightframe
- 4x4 matrix representing the pose- Returns:
- Transformed point as matrix
-
makeYRotTFMatrix
Creates a matrix about with rotation about the y-axis.- Parameters:
x
- translation along x-axisy
- translation along y-axisz
- translation along z-axistheta
- angle of rotation about y-axis- Returns:
- transformation matrix for Y rotation
-
makeZRotTFMatrix
- Parameters:
x
- translation along x-axisy
- translation along y-axisz
- translation along z-axistheta
- angle of rotation about Z-axis- Returns:
- Transformation matrix for Z rotation
-
exp
Obtain a new Pose2d from a (constant curvature) velocity. See: https://github.com/strasdat/Sophus/blob/master/sophus/se2.hpp. Borrowed from 254: https://github.com/Team254/FRC-2022-Public/blob/main/src/main/java/com/team254/lib/geometry/Pose2d.java- Parameters:
delta
- robot change- Returns:
- New Pose2d from velocity
-
log
Logical inverse of the above. Borrowed from 254: https://github.com/Team254/FRC-2022-Public/blob/main/src/main/java/com/team254/lib/geometry/Pose2d.java- Parameters:
transform
- Pose to derive velocity from- Returns:
- Twist2d representing transformation
-
cppMod
Returns a modulo result that matches the C++ rather than Java implementation- Parameters:
num
- Numeratordenom
- Denominator- Returns:
- modulo result
-
clamp
Clamps a target value between the minimum and maximum values, ensuring the value is in the given range.- Parameters:
target
- target valuemin
- min valuemax
- max value- Returns:
- the target value rounded to be in range (min, max)
-
inTolerance
Units must be consistent between all 3 values- Parameters:
position
- actual position of the mechanismlowerBound
- minimum position of the mechanismupperBound
- maximum position of the mechanism- Returns:
- True if position is greater than or equal to the lowerBound and less than or equal to the upperBound. False otherwise, meaning the position falls out of the range
-