Skip to content

Commit 26ff414

Browse files
Merge pull request #55 from Manchester-Central/FieldPoseUpdates
Field pose updates
2 parents 931d937 + 1a953a2 commit 26ff414

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

src/main/java/com/chaos131/poses/FieldPose.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
import edu.wpi.first.math.geometry.Pose3d;
55
import edu.wpi.first.math.geometry.Rotation2d;
66
import edu.wpi.first.math.geometry.Translation2d;
7+
import edu.wpi.first.units.measure.Distance;
78
import edu.wpi.first.wpilibj.DriverStation;
89
import edu.wpi.first.wpilibj.DriverStation.Alliance;
10+
11+
import static edu.wpi.first.units.Units.Meters;
12+
913
import java.util.ArrayList;
1014
import java.util.HashMap;
1115
import java.util.Map;
@@ -82,8 +86,20 @@ public String getName() {
8286
* @param robotpose to calculate from
8387
* @return the distance along the floor. Does not account for vertical component.
8488
*/
85-
public double getDistanceFromLocation(Pose2d robotpose) {
86-
return getCurrentAlliancePose().getTranslation().getDistance(robotpose.getTranslation());
89+
public Distance getDistanceFromLocation(Pose2d robotpose) {
90+
return getDistanceFromLocations(getCurrentAlliancePose(), robotpose);
91+
}
92+
93+
/**
94+
* Calculates the distance from a specific spot on the field. Typically this is the robot's
95+
* position.
96+
*
97+
* @param pose1
98+
* @param pose2
99+
* @return the distance along the floor. Does not account for vertical component. Returns absolute values.
100+
*/
101+
public static Distance getDistanceFromLocations(Pose2d pose1, Pose2d pose2) {
102+
return Meters.of(pose2.getTranslation().getDistance(pose1.getTranslation()));
87103
}
88104

89105
/**

src/main/java/com/chaos131/poses/FieldPose2026.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
import edu.wpi.first.apriltag.AprilTagFieldLayout;
66
import edu.wpi.first.apriltag.AprilTagFields;
7+
import edu.wpi.first.math.geometry.Pose2d;
78
import edu.wpi.first.math.geometry.Pose3d;
89
import edu.wpi.first.math.geometry.Rotation3d;
910
import edu.wpi.first.math.geometry.Translation2d;
1011
import edu.wpi.first.math.geometry.Translation3d;
11-
import edu.wpi.first.wpilibj.DriverStation;
1212
import edu.wpi.first.wpilibj.DriverStation.Alliance;
1313
import java.io.IOException;
1414

@@ -45,10 +45,14 @@ public class FieldPose2026 extends PivotedFieldPose {
4545
public static FieldPose2026 ClimbRightBar;
4646
public static FieldPose2026 ClimbFarRightBar;
4747

48-
private FieldPose2026(Alliance defaultAlliance, String name, Pose3d defaultPose) {
48+
public FieldPose2026(Alliance defaultAlliance, String name, Pose3d defaultPose) {
4949
super(Midpoint, defaultAlliance, name, defaultPose);
5050
}
5151

52+
public FieldPose2026(Alliance defaultAlliance, String name, Pose2d defaultPose) {
53+
super(Midpoint, defaultAlliance, name, new Pose3d(defaultPose));
54+
}
55+
5256
/**
5357
* Required function before using any field points. Necessary because Java's static function
5458
* initializers will fail to load any of it. Values will be null. Run this at runtime to load the
@@ -59,11 +63,6 @@ private FieldPose2026(Alliance defaultAlliance, String name, Pose3d defaultPose)
5963
* @throws IOException
6064
*/
6165
public static void initializeFieldPoses() throws IOException {
62-
var alliance = DriverStation.getAlliance();
63-
if (alliance.isEmpty()) {
64-
throw new IOException(
65-
"Failed to load file because Alliance is unknown. Try waiting next time.");
66-
}
6766
AprilTagLayout = new AprilTagFieldLayout(AprilTagField.m_resourceFile);
6867
Midpoint =
6968
new Translation2d(

src/main/java/com/chaos131/util/ChaosTalonFx.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
import com.ctre.phoenix6.controls.DynamicMotionMagicVoltage;
1515
import com.ctre.phoenix6.controls.MotionMagicVoltage;
1616
import com.ctre.phoenix6.controls.PositionVoltage;
17+
import com.ctre.phoenix6.controls.VelocityVoltage;
1718
import com.ctre.phoenix6.hardware.TalonFX;
1819
import com.ctre.phoenix6.sim.CANcoderSimState;
1920
import com.ctre.phoenix6.sim.ChassisReference;
2021
import com.ctre.phoenix6.sim.TalonFXSimState;
2122
import com.ctre.phoenix6.sim.TalonFXSimState.MotorType;
2223
import edu.wpi.first.units.measure.Angle;
24+
import edu.wpi.first.units.measure.AngularVelocity;
2325
import edu.wpi.first.units.measure.Mass;
26+
import edu.wpi.first.units.measure.Velocity;
2427
import edu.wpi.first.wpilibj.RobotController;
2528
import edu.wpi.first.wpilibj.simulation.DCMotorSim;
2629

@@ -31,6 +34,7 @@ public class ChaosTalonFx extends TalonFX {
3134
private boolean m_isMainSimMotor;
3235
private ChaosCanCoder m_attachedCanCoder;
3336
private final PositionVoltage m_positionVoltage = new PositionVoltage(0);
37+
private final VelocityVoltage m_velocityVoltage = new VelocityVoltage(0);
3438
private final MotionMagicVoltage m_positionMotionMagicVoltage = new MotionMagicVoltage(0);
3539
private final DynamicMotionMagicVoltage m_positionDynamicMotionMagicVoltage =
3640
new DynamicMotionMagicVoltage(0, 0, 0);
@@ -148,6 +152,11 @@ public void tuneMotionMagic(PIDFValue pidValue, double kg, double ks, double kv,
148152
applyConfig();
149153
}
150154

155+
public void moveAtVelocity(AngularVelocity velocity) {
156+
m_velocityVoltage.Slot = 0;
157+
setControl(m_velocityVoltage.withVelocity(velocity));
158+
}
159+
151160
/** Tells the motor controller to move to the target position. */
152161
public void moveToPosition(Angle position) {
153162
m_positionVoltage.Slot = 0;

0 commit comments

Comments
 (0)