Skip to content

Commit

Permalink
feat: mechanism visualiser
Browse files Browse the repository at this point in the history
  • Loading branch information
mimizh2418 committed Jan 19, 2024
1 parent 481ef54 commit 22f70db
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/team1540/robot2024/Constants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.team1540.robot2024;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.util.Units;

/**
Expand Down Expand Up @@ -43,6 +44,7 @@ public static class SwerveConfig {
public static final int BACK_LEFT = IS_COMPETITION_ROBOT ? 7 : 0;
public static final int BACK_RIGHT = IS_COMPETITION_ROBOT ? 1 : 0;
}

public static class Drivetrain {
public static final double DRIVE_GEAR_RATIO = (50.0 / 14.0) * (17.0 / 27.0) * (45.0 / 15.0);
public static final double TURN_GEAR_RATIO = 150.0 / 7.0;
Expand All @@ -55,4 +57,13 @@ public static class Drivetrain {
public static final double DRIVE_BASE_RADIUS = Math.hypot(TRACK_WIDTH_X / 2.0, TRACK_WIDTH_Y / 2.0);
public static final double MAX_ANGULAR_SPEED = MAX_LINEAR_SPEED / DRIVE_BASE_RADIUS;
}

public static class Elevator {
public static final double ELEVATOR_MAX_HEIGHT = Units.inchesToMeters(21.0);
}

public static class ShooterPivot {
public static final Rotation2d PIVOT_MIN_ANGLE = Rotation2d.fromDegrees(8.0);
public static final Rotation2d PIVOT_MAX_ANGLE = Rotation2d.fromDegrees(60.0);
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/team1540/robot2024/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.littletonrobotics.junction.networktables.NT4Publisher;
import org.littletonrobotics.junction.wpilog.WPILOGReader;
import org.littletonrobotics.junction.wpilog.WPILOGWriter;
import org.team1540.robot2024.util.MechanismVisualiser;

/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
Expand Down Expand Up @@ -89,6 +90,9 @@ public void robotPeriodic() {
// This must be called from the robot's periodic block in order for anything in
// the Command-based framework to work.
CommandScheduler.getInstance().run();

// Update mechanism visualiser in sim
if (Robot.isSimulation()) MechanismVisualiser.periodic();
}

/**
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/team1540/robot2024/util/MechanismVisualiser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.team1540.robot2024.util;

import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Rotation3d;
import org.littletonrobotics.junction.Logger;

public class MechanismVisualiser {
private static Pose3d shooterPivot = new Pose3d();
private static Pose3d elevator = new Pose3d();

public static void periodic() {
Logger.recordOutput("Mechanisms", shooterPivot, elevator);
}

public static void setElevatorPosition(double positionMeters) {
elevator = new Pose3d(0.0, 0.0, positionMeters, new Rotation3d());
}

public static void setShooterPivotRotation(Rotation2d rotation) {
shooterPivot = new Pose3d(0.0, 0.0, 0.0, new Rotation3d(0, rotation.getRadians(), 0));
}
}

0 comments on commit 22f70db

Please sign in to comment.