Skip to content

Commit

Permalink
[Robot] Lob short in wing
Browse files Browse the repository at this point in the history
  • Loading branch information
mvog2501 committed Mar 23, 2024
1 parent 90e46f1 commit 062b66e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.swrobotics.robot.commands;

import org.littletonrobotics.junction.AutoLogOutput;

import com.swrobotics.lib.net.NTUtil;
import com.swrobotics.mathlib.MathUtil;
import com.swrobotics.robot.config.NTData;
Expand All @@ -12,10 +10,7 @@
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.geometry.Twist2d;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.kinematics.proto.ChassisSpeedsProto;
import edu.wpi.first.math.kinematics.struct.ChassisSpeedsStruct;
import edu.wpi.first.wpilibj2.command.Command;

public final class AimTowardsLobCommand extends Command {
Expand Down
3 changes: 2 additions & 1 deletion Robot/src/main/java/com/swrobotics/robot/config/NTData.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public final class NTData {
public static final NTEntry<Double> SHOOTER_PIVOT_REVERSE_ANGLE = new NTDouble("Shooter/Pivot/Reverse Angle (deg)", 35).setPersistent();

public static final NTEntry<Double> SHOOTER_LOB_POWER_COEFFICIENT = new NTDouble("Shooter/Lob/Power Coefficient", 1.25).setPersistent(); // To go from real velocity to flywheel velocity
public static final NTEntry<Double> SHOOTER_LOB_HEIGHT_METERS = new NTDouble("Shooter/Lob/Lob Height (m)", 3).setPersistent();
public static final NTEntry<Double> SHOOTER_LOB_TALL_HEIGHT_METERS = new NTDouble("Shooter/Lob/Tall Lob Height (m)", 4).setPersistent();
public static final NTEntry<Double> SHOOTER_LOB_SHORT_HEIGHT_METERS = new NTDouble("Shooter/Lob/Short Lob Height (m)", 1).setPersistent();
public static final NTEntry<Double> SHOOTER_FLY_TIME = new NTDouble("Shooter/Fly Time (s)", 0.25);

private NTData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@ public class LobCalculator implements AimCalculator {
public static final LobCalculator INSTANCE = new LobCalculator();

private static final double twoG = 9.8 * 2;
private double sqrt2gh;
private double tallSqrt2gh;
private double shortSqrt2gh;

public LobCalculator() {
NTData.SHOOTER_LOB_HEIGHT_METERS.onChange((a) -> this.updateHeight());
sqrt2gh = Math.sqrt(twoG * NTData.SHOOTER_LOB_HEIGHT_METERS.get());
NTData.SHOOTER_LOB_TALL_HEIGHT_METERS.onChange((a) -> this.updateHeight());
NTData.SHOOTER_LOB_SHORT_HEIGHT_METERS.onChange((a) -> this.updateHeight());
tallSqrt2gh = Math.sqrt(twoG * NTData.SHOOTER_LOB_TALL_HEIGHT_METERS.get());
shortSqrt2gh = Math.sqrt(twoG * NTData.SHOOTER_LOB_SHORT_HEIGHT_METERS.get());
}

public Aim calculateAim(double distanceToSpeaker, double velocityTowardsGoal) {
double angleRad = Math.atan2(4 * NTData.SHOOTER_LOB_HEIGHT_METERS.get(), distanceToSpeaker);
boolean inWing = distanceToSpeaker > 5;
double angleRad = 0;

if (inWing) {
angleRad = Math.atan2(4 * NTData.SHOOTER_LOB_TALL_HEIGHT_METERS.get(), distanceToSpeaker);
}

double sqrt2gh = (inWing) ? tallSqrt2gh : shortSqrt2gh;

double velocity = sqrt2gh / Math.sin(angleRad);

Translation2d velocityVector = new Translation2d(velocity, new Rotation2d(angleRad));
Expand All @@ -37,7 +48,8 @@ public Aim calculateAim(double distanceToSpeaker) {
}

private void updateHeight() {
sqrt2gh = Math.sqrt(twoG * NTData.SHOOTER_LOB_HEIGHT_METERS.get());
tallSqrt2gh = Math.sqrt(twoG * NTData.SHOOTER_LOB_TALL_HEIGHT_METERS.get());
shortSqrt2gh = Math.sqrt(twoG * NTData.SHOOTER_LOB_SHORT_HEIGHT_METERS.get());
}

}

0 comments on commit 062b66e

Please sign in to comment.