Skip to content

Commit

Permalink
feat: mechanism visualiser (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mimizh2418 authored and Brandon-Harad committed Jan 30, 2024
1 parent f8c4b9e commit 076fc09
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/team1540/robot2024/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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 @@ -58,6 +59,10 @@ public static class Drivetrain {
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 Shooter {
public static class Flywheels {
// TODO: determine ids
Expand Down
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 076fc09

Please sign in to comment.