This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
372b847
commit 0dc9253
Showing
11 changed files
with
83 additions
and
1,270 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
.../java/frc/robot/odometry/GyroscopeIO.java → ...main/java/frc/lib/sensor/GyroscopeIO.java
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,36 @@ | ||
package frc.lib.sensor; | ||
|
||
import frc.robot.RobotConstants; | ||
import java.util.function.DoubleSupplier; | ||
|
||
/** Simulated gyroscope. */ | ||
public class GyroscopeIOSim implements GyroscopeIO { | ||
|
||
/** Yaw velocity supplier in rotations per second */ | ||
private final DoubleSupplier yawVelocityRotationsPerSecond; | ||
|
||
/** Yaw in rotations. */ | ||
private double yawRotations = 0.0; | ||
|
||
/** Creates a new simulated gyroscope. */ | ||
public GyroscopeIOSim(DoubleSupplier yawVelocityRotationsPerSecond) { | ||
this.yawVelocityRotationsPerSecond = yawVelocityRotationsPerSecond; | ||
} | ||
|
||
@Override | ||
public void configure() {} | ||
|
||
@Override | ||
public void update(GyroscopeIOValues values) { | ||
yawRotations += yawVelocityRotationsPerSecond.getAsDouble() * RobotConstants.PERIODIC_DURATION; | ||
|
||
values.yawRotations = yawRotations; | ||
|
||
values.yawVelocityRotations = yawVelocityRotationsPerSecond.getAsDouble(); | ||
} | ||
|
||
@Override | ||
public void setYaw(double yawRotations) { | ||
this.yawRotations = yawRotations; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,35 +1,25 @@ | ||
package frc.robot.odometry; | ||
|
||
import com.ctre.phoenix6.configs.Pigeon2Configuration; | ||
import edu.wpi.first.math.util.Units; | ||
import frc.lib.sensor.GyroscopeIO; | ||
import frc.lib.sensor.GyroscopeIOPigeon2; | ||
import frc.lib.sensor.GyroscopeIOSim; | ||
import frc.robot.Robot; | ||
import frc.robot.RobotConstants; | ||
import frc.robot.RobotConstants.Subsystem; | ||
|
||
/** Helper class for creating hardware for the odometry subsystem. */ | ||
/** Factory for creating odometry subsystem hardware. */ | ||
public class OdometryFactory { | ||
|
||
/** | ||
* Creates a gyroscope. | ||
* Creates the gyroscope. | ||
* | ||
* @return a gyroscope. | ||
* @return the gyroscope. | ||
*/ | ||
public static GyroscopeIO createGyroscope(Odometry odometry) { | ||
if (Robot.isReal() && RobotConstants.REAL_SUBSYSTEMS.contains(Subsystem.ODOMETRY)) | ||
return new GyroscopeIOPigeon2(); | ||
|
||
return new GyroscopeIOSim(odometry); | ||
} | ||
|
||
/** | ||
* Creates a gyroscope configuration. | ||
* | ||
* @return a gyroscope configuration. | ||
*/ | ||
public static Pigeon2Configuration createGyroscopeConfig() { | ||
Pigeon2Configuration gyroscopeConfig = new Pigeon2Configuration(); | ||
|
||
gyroscopeConfig.Pigeon2Features.EnableCompass = false; | ||
|
||
return gyroscopeConfig; | ||
return new GyroscopeIOSim(() -> Units.radiansToRotations(odometry.getVelocity().dtheta)); | ||
} | ||
} |