-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d09e7f4
commit e4da026
Showing
6 changed files
with
139 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package lib.utils; | ||
|
||
public class FieldRelativeAccel { | ||
public double ax; | ||
public double ay; | ||
public double alpha; | ||
|
||
public FieldRelativeAccel(double ax, double ay, double alpha) { | ||
this.ax = ax; | ||
this.ay = ay; | ||
this.alpha = alpha; | ||
} | ||
|
||
public FieldRelativeAccel(FieldRelativeSpeed newSpeed, FieldRelativeSpeed oldSpeed, double time) { | ||
this.ax = (newSpeed.vx - oldSpeed.vx) / time; | ||
this.ay = (newSpeed.vy - oldSpeed.vy) / time; | ||
this.alpha = (newSpeed.omega - oldSpeed.omega) / time; | ||
|
||
if (Math.abs(this.ax) > 6.0) { | ||
this.ax = 6.0 * Math.signum(this.ax); | ||
} | ||
if (Math.abs(this.ay) > 6.0) { | ||
this.ay = 6.0 * Math.signum(this.ay); | ||
} | ||
if (Math.abs(this.alpha) > 4 * Math.PI) { | ||
this.alpha = 4 * Math.PI * Math.signum(this.alpha); | ||
} | ||
} | ||
|
||
public FieldRelativeAccel() { | ||
this.ax = 0.0; | ||
this.ay = 0.0; | ||
this.alpha = 0.0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package lib.utils; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.kinematics.ChassisSpeeds; | ||
|
||
public class FieldRelativeSpeed { | ||
public double vx; | ||
public double vy; | ||
public double omega; | ||
|
||
public FieldRelativeSpeed(double vx, double vy, double omega) { | ||
this.vx = vx; | ||
this.vy = vy; | ||
this.omega = omega; | ||
} | ||
|
||
public FieldRelativeSpeed(ChassisSpeeds chassisSpeed, Rotation2d gyro) { | ||
this(chassisSpeed.vxMetersPerSecond * gyro.getCos() - chassisSpeed.vyMetersPerSecond * gyro.getSin(), | ||
chassisSpeed.vyMetersPerSecond * gyro.getCos() + chassisSpeed.vxMetersPerSecond * gyro.getSin(), | ||
chassisSpeed.omegaRadiansPerSecond); | ||
} | ||
|
||
public FieldRelativeSpeed() { | ||
this.vx = 0.0; | ||
this.vy = 0.0; | ||
this.omega = 0.0; | ||
} | ||
} |