vel correction setup

This commit is contained in:
aarav18
2022-03-16 15:35:38 -06:00
parent 38459ba40c
commit 2f23aed7f1
5 changed files with 27 additions and 63 deletions
+12 -12
View File
@@ -1,12 +1,12 @@
Distance (in) ,Hood Ext. (u) ,Drum Velocity (u/ds) ,Duration (s),
0 ,-29.5 ,8000 ,0,
78.5 ,-29.5 ,8000 ,0,
99 ,-39.62 ,8500 ,0,
127.25 ,-49.12 ,9500 ,0,
150 ,-66.22 ,10000 ,0,
164.5 ,-75.52 ,10000 ,0,
186 ,-76.24 ,10000 ,0,
207 ,-104.07 ,11000 ,0,
227 ,-105.32 ,11500 ,0,
255.5 ,-105.8 ,13500 ,0,
999 ,-105.8 ,13500 ,0,
Distance (in) ,Hood Ext. (u) ,Drum Velocity (u/ds)
0 ,-29.5 ,8000
78.5 ,-29.5 ,8000
99 ,-39.62 ,8500
127.25 ,-49.12 ,9500
150 ,-66.22 ,10000
164.5 ,-75.52 ,10000
186 ,-76.24 ,10000
207 ,-104.07 ,11000
227 ,-105.32 ,11500
255.5 ,-105.8 ,13500
999 ,-105.8 ,13500
1 Distance (in) Hood Ext. (u) Drum Velocity (u/ds) Drum Velocity (u/ds) Duration (s)
2 0 -29.5 8000 8000 0
3 78.5 -29.5 8000 8000 0
4 99 -39.62 8500 8500 0
5 127.25 -49.12 9500 9500 0
6 150 -66.22 10000 10000 0
7 164.5 -75.52 10000 10000 0
8 186 -76.24 10000 10000 0
9 207 -104.07 11000 11000 0
10 227 -105.32 11500 11500 0
11 255.5 -105.8 13500 13500 0
12 999 -105.8 13500 13500 0
@@ -0,0 +1,12 @@
Distance (in) ,Duration (s)
0 ,0
78.5 ,0
99 ,0
127.25 ,0
150 ,0
164.5 ,0
186 ,0
207 ,0
227 ,0
255.5 ,0
999 ,0
1 Distance (in) Duration (s)
2 0 0
3 78.5 0
4 99 0
5 127.25 0
6 150 0
7 164.5 0
8 186 0
9 207 0
10 227 0
11 255.5 0
12 999 0
+1 -1
View File
@@ -210,7 +210,7 @@ public final class Constants {
public static final double TURRET_FORWARD_LIMIT = 0.0;
public static final double TURRET_REVERSE_LIMIT = -95.0; //Find
//Shooter gains for actual Drum
public static final Gains DRUM_SHOOTER_GAINS = new Gains(0.4, 0.0, 15.0, 0.05, 0, 0); // TODO: tune values
public static final Gains DRUM_SHOOTER_GAINS = new Gains(0.4, 0.0, 15.0, 0.05, 0, 0);
/* Hood Constants */
public static final int SHOOTER_ANGLE_ADJUST_ID = 20;
@@ -96,7 +96,7 @@ public class Shoot extends CommandBase {
* Updates error for custom PID.
*/
public void updateError() {
m_targetPoint = new Pose2d(hTargetDistanceFromHub(), vTargetDistanceFromHub(), SwerveDriveConstants.HUB_POSE.getRotation());
m_targetPoint = SwerveDriveConstants.HUB_POSE;
m_targetAngle = AimToCenter.angleToCenter(m_odoX, m_odoY, driveDummy.get());
// m_targetAngle = AimToCenter.angleToCenter(m_odoX, m_odoY, m_swerve.getRegGyro().getDegrees());
error = (m_targetAngle - turretDummy.get() + 360) % 360;
@@ -152,43 +152,6 @@ public class Shoot extends CommandBase {
output = kP * proportional + kI * integral + kD * derivative;
normOutput = output/360 * inverted;
}
// TODO: horizontal velocity correction
public double hTargetDistanceFromHub() {
double hVel = m_swerve.getChassisSpeeds()[0];
double velBeforeCorrection = m_boomBoom.getVelocity(m_distance);
double vDistanceFromHub = m_odoY;
double approxTravelTime = vDistanceFromHub / velBeforeCorrection;
double hTargetDistanceFromHub = hVel * approxTravelTime;
// return hTargetDistanceFromHub;
return 0.0; // this is for no velocity correction
}
public Pose2d findTargetPoint() {
// position vector and radius
Translation2d position = new Translation2d(m_odoX, m_odoY);
double radius = position.getNorm();
// equation of circle = x^2 + y^2 = m_distance^2
// derivative of circle = 2x + 2y * y' = 0 --> y' = -x/y
// velocity vector (x, y)
Translation2d cartesianVelocity = new Translation2d(m_swerve.getChassisSpeeds()[0], m_swerve.getChassisSpeeds()[1]);
// unit tangential vector
Translation2d tangential = new Translation2d(0, 0);
// velocity vector (tangential, radial)
Translation2d polarVelocity = new Translation2d(0, 0);
return SwerveDriveConstants.HUB_POSE;
}
// TODO: vertical velocity correction
public double vTargetDistanceFromHub() {
return 0.0; // this is for no velocity correction
}
// Called every time the scheduler runs while the command is scheduled.
@Override
@@ -48,7 +48,7 @@ public class BoomBoom extends SubsystemBase {
// SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(69, 42, 0); //get real values later
public static class ShooterTableEntry {
public Double distance, hoodExt, drumVelocity, duration;
public Double distance, hoodExt, drumVelocity;
}
private ShooterTableEntry[] m_shooterTable;
@@ -116,17 +116,6 @@ public class BoomBoom extends SubsystemBase {
return linearInterpolate(m_shooterTable, distance, e -> e.distance, e -> e.hoodExt).doubleValue();
}
/**
* This is a function that takes a value (distance) and returns a value (duration) that is a linear
* interpolation of the two values (duration) at the two closest points in the table (m_shooterTable)
* to the given value (distance).
* @param distance Distance in shooter table
* @return Shot duration in seconds
*/
public Double getDuration(final Double distance) {
return linearInterpolate(m_shooterTable, distance, e -> e.distance, e -> e.duration).doubleValue();
}
/**
* Using the given lookup value (x) and lookup getter function, locates the nearest entries in the
* given table to be used as the lower (x0) and upper (x1) bounds for interpolation. Returns the