Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id "java-library"
id "maven-publish"
id "edu.wpi.first.GradleRIO" version "2025.1.1-beta-1"
id "edu.wpi.first.GradleRIO" version "2025.1.1-beta-2"
id "edu.wpi.first.WpilibTools" version "2.1.0"
}

Expand All @@ -22,9 +22,6 @@ repositories {
}
}

// Get AdvantageKit version from vendordep file
def AdvantageKitJSON = new groovy.json.JsonSlurper().parseText(new File(projectDir.getAbsolutePath() + "/vendordeps/AdvantageKit.json").text)

dependencies {
implementation wpi.java.deps.wpilib()
implementation wpi.java.vendor.java()
Expand All @@ -38,7 +35,9 @@ dependencies {
simulationRelease wpi.sim.enableRelease()

implementation 'com.google.code.gson:gson:2.10.1'
annotationProcessor "org.littletonrobotics.akit.junction:junction-autolog:$AdvantageKitJSON.version"

def akitJson = new groovy.json.JsonSlurper().parseText(new File(projectDir.getAbsolutePath() + "/vendordeps/AdvantageKit.json").text)
annotationProcessor "org.littletonrobotics.akit:akit-autolog:$akitJson.version"
}

// Simulation configuration (e.g. environment variables).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package org.trigon.utilities.mechanisms;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj.util.Color8Bit;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.mechanism.LoggedMechanism2d;
import org.littletonrobotics.junction.mechanism.LoggedMechanismLigament2d;
import org.littletonrobotics.junction.mechanism.LoggedMechanismRoot2d;

/**
* A Mechanism2d object to display the current angle and target angle, and the current position and target position of an arm elevator.
*/
public class ArmElevatorMechanism2d {
private final String key;
private final Mechanism2d mechanism;
private final MechanismLigament2d
private final LoggedMechanism2d mechanism;
private final LoggedMechanismLigament2d
currentPositionLigament,
targetPositionLigament;
private final double minimumLength;
Expand All @@ -30,10 +30,10 @@ public class ArmElevatorMechanism2d {
public ArmElevatorMechanism2d(String name, double maximumLength, double minimumLength, Color mechanismColor) {
this.key = "Mechanisms/" + name;
this.minimumLength = minimumLength;
this.mechanism = new Mechanism2d(2 * maximumLength, 2 * maximumLength);
final MechanismRoot2d root = mechanism.getRoot("Root", maximumLength, maximumLength);
this.currentPositionLigament = root.append(new MechanismLigament2d("ZCurrentPositionLigament", 0, 0, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor)));
this.targetPositionLigament = root.append(new MechanismLigament2d("TargetPositionLigament", 0, 0, MechanismConstants.TARGET_ELEVATOR_POSITION_LIGAMENT_WIDTH, MechanismConstants.GRAY));
this.mechanism = new LoggedMechanism2d(2 * maximumLength, 2 * maximumLength);
final LoggedMechanismRoot2d root = mechanism.getRoot("Root", maximumLength, maximumLength);
this.currentPositionLigament = root.append(new LoggedMechanismLigament2d("ZCurrentPositionLigament", 0, 0, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor)));
this.targetPositionLigament = root.append(new LoggedMechanismLigament2d("TargetPositionLigament", 0, 0, MechanismConstants.TARGET_ELEVATOR_POSITION_LIGAMENT_WIDTH, MechanismConstants.GRAY));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package org.trigon.utilities.mechanisms;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj.util.Color8Bit;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.mechanism.LoggedMechanism2d;
import org.littletonrobotics.junction.mechanism.LoggedMechanismLigament2d;
import org.littletonrobotics.junction.mechanism.LoggedMechanismRoot2d;

/**
* A Mechanism2d object to display the current angle and the target angle of a double-jointed arm.
*/
public class DoubleJointedArmMechanism2d {
private final String key;
private final Mechanism2d mechanism;
private final MechanismLigament2d
private final LoggedMechanism2d mechanism;
private final LoggedMechanismLigament2d
currentPositionFirstLigament,
currentPositionSecondLigament,
targetPositionFirstLigament,
Expand All @@ -41,13 +41,13 @@ public DoubleJointedArmMechanism2d(String key, Color mechanismColor) {
public DoubleJointedArmMechanism2d(String name, double firstJointLength, double secondJointLength, Color mechanismColor) {
this.key = "Mechanisms/" + name;
final double mechanismMiddle = MechanismConstants.LIGAMENT_END_TO_EDGE_RATIO * (firstJointLength + secondJointLength);
this.mechanism = new Mechanism2d(2 * mechanismMiddle, 2 * mechanismMiddle);
final MechanismRoot2d root = mechanism.getRoot("Root", mechanismMiddle, mechanismMiddle);
this.mechanism = new LoggedMechanism2d(2 * mechanismMiddle, 2 * mechanismMiddle);
final LoggedMechanismRoot2d root = mechanism.getRoot("Root", mechanismMiddle, mechanismMiddle);

this.currentPositionFirstLigament = root.append(new MechanismLigament2d("ZCurrentPositionFirstLigament", firstJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor)));
this.currentPositionSecondLigament = currentPositionFirstLigament.append(new MechanismLigament2d("ZCurrentPositionSecondLigament", secondJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor)));
this.targetPositionFirstLigament = root.append(new MechanismLigament2d("TargetPositionFirstLigament", firstJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY));
this.targetPositionSecondLigament = targetPositionFirstLigament.append(new MechanismLigament2d("TargetPositionSecondLigament", secondJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY));
this.currentPositionFirstLigament = root.append(new LoggedMechanismLigament2d("ZCurrentPositionFirstLigament", firstJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor)));
this.currentPositionSecondLigament = currentPositionFirstLigament.append(new LoggedMechanismLigament2d("ZCurrentPositionSecondLigament", secondJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor)));
this.targetPositionFirstLigament = root.append(new LoggedMechanismLigament2d("TargetPositionFirstLigament", firstJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY));
this.targetPositionSecondLigament = targetPositionFirstLigament.append(new LoggedMechanismLigament2d("TargetPositionSecondLigament", secondJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package org.trigon.utilities.mechanisms;

import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj.util.Color8Bit;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.mechanism.LoggedMechanism2d;
import org.littletonrobotics.junction.mechanism.LoggedMechanismLigament2d;
import org.littletonrobotics.junction.mechanism.LoggedMechanismRoot2d;

/**
* A Mechanism2d object to display the current position and target position of an elevator.
*/
public class ElevatorMechanism2d {
private final String key;
private final Mechanism2d mechanism;
private final MechanismLigament2d
private final LoggedMechanism2d mechanism;
private final LoggedMechanismLigament2d
currentPositionLigament,
targetPositionLigament;
private final double minimumLength;
Expand All @@ -29,11 +29,11 @@ public class ElevatorMechanism2d {
public ElevatorMechanism2d(String name, double maximumLength, double minimumLength, Color mechanismColor) {
this.key = "Mechanisms/" + name;
this.minimumLength = minimumLength;
this.mechanism = new Mechanism2d(maximumLength, maximumLength);
this.mechanism = new LoggedMechanism2d(maximumLength, maximumLength);

final MechanismRoot2d currentPositionRoot = mechanism.getRoot("Root", 0.5 * maximumLength, 0);
this.currentPositionLigament = currentPositionRoot.append(new MechanismLigament2d("ZCurrentPositionLigament", minimumLength, MechanismConstants.ELEVATOR_MECHANISM_STARTING_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor)));
this.targetPositionLigament = currentPositionRoot.append(new MechanismLigament2d("TargetPositionLigament", minimumLength, MechanismConstants.ELEVATOR_MECHANISM_STARTING_ANGLE, MechanismConstants.TARGET_ELEVATOR_POSITION_LIGAMENT_WIDTH, MechanismConstants.GRAY));
final LoggedMechanismRoot2d currentPositionRoot = mechanism.getRoot("Root", 0.5 * maximumLength, 0);
this.currentPositionLigament = currentPositionRoot.append(new LoggedMechanismLigament2d("ZCurrentPositionLigament", minimumLength, MechanismConstants.ELEVATOR_MECHANISM_STARTING_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor)));
this.targetPositionLigament = currentPositionRoot.append(new LoggedMechanismLigament2d("TargetPositionLigament", minimumLength, MechanismConstants.ELEVATOR_MECHANISM_STARTING_ANGLE, MechanismConstants.TARGET_ELEVATOR_POSITION_LIGAMENT_WIDTH, MechanismConstants.GRAY));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package org.trigon.utilities.mechanisms;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj.util.Color8Bit;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.mechanism.LoggedMechanism2d;
import org.littletonrobotics.junction.mechanism.LoggedMechanismLigament2d;
import org.littletonrobotics.junction.mechanism.LoggedMechanismRoot2d;

/**
* A Mechanism2d object to display the current angle and the target angle of a single jointed arm.
*/
public class SingleJointedArmMechanism2d {
private final String key;
private final Mechanism2d mechanism;
private final MechanismLigament2d
private final LoggedMechanism2d mechanism;
private final LoggedMechanismLigament2d
currentPositionLigament,
targetPositionLigament;

Expand All @@ -38,10 +38,10 @@ public SingleJointedArmMechanism2d(String key, Color mechanismColor) {
public SingleJointedArmMechanism2d(String name, double armLength, Color mechanismColor) {
this.key = "Mechanisms/" + name;
final double mechanismMiddle = MechanismConstants.LIGAMENT_END_TO_EDGE_RATIO * armLength;
this.mechanism = new Mechanism2d(2 * mechanismMiddle, 2 * mechanismMiddle);
final MechanismRoot2d root = mechanism.getRoot("Root", mechanismMiddle, mechanismMiddle);
this.currentPositionLigament = root.append(new MechanismLigament2d("ZCurrentPositionLigament", armLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor)));
this.targetPositionLigament = root.append(new MechanismLigament2d("TargetPositionLigament", armLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY));
this.mechanism = new LoggedMechanism2d(2 * mechanismMiddle, 2 * mechanismMiddle);
final LoggedMechanismRoot2d root = mechanism.getRoot("Root", mechanismMiddle, mechanismMiddle);
this.currentPositionLigament = root.append(new LoggedMechanismLigament2d("ZCurrentPositionLigament", armLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor)));
this.targetPositionLigament = root.append(new LoggedMechanismLigament2d("TargetPositionLigament", armLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY));
}

/**
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/org/trigon/utilities/mechanisms/SpeedMechanism2d.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package org.trigon.utilities.mechanisms;

import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d;
import edu.wpi.first.wpilibj.util.Color8Bit;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.mechanism.LoggedMechanism2d;
import org.littletonrobotics.junction.mechanism.LoggedMechanismLigament2d;
import org.littletonrobotics.junction.mechanism.LoggedMechanismRoot2d;

/**
* A Mechanism2d object to display the current velocity and target velocity of a mechanism.
*/
public class SpeedMechanism2d {
private final String key;
private final Mechanism2d mechanism;
private final MechanismLigament2d
private final LoggedMechanism2d mechanism;
private final LoggedMechanismLigament2d
currentVelocityLigament,
currentVelocityTopArrowLigament,
currentVelocityBottomArrowLigament,
Expand Down Expand Up @@ -40,15 +40,15 @@ public SpeedMechanism2d(String key, double maximumDisplayableVelocity) {
public SpeedMechanism2d(String name, double maximumDisplayableVelocity, double deadband) {
this.deadband = deadband;
this.key = "Mechanisms/" + name;
this.mechanism = new Mechanism2d(2 * maximumDisplayableVelocity, 2 * maximumDisplayableVelocity);
final MechanismRoot2d root = mechanism.getRoot("Root", maximumDisplayableVelocity, maximumDisplayableVelocity);
this.currentVelocityLigament = root.append(new MechanismLigament2d("ZCurrentVelocityLigament", 0, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.BLUE));
this.currentVelocityTopArrowLigament = currentVelocityLigament.append(new MechanismLigament2d("ZCurrentVelocityTopArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_TOP_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.BLUE));
this.currentVelocityBottomArrowLigament = currentVelocityLigament.append(new MechanismLigament2d("ZCurrentVelocityBottomArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_BOTTOM_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.BLUE));
this.mechanism = new LoggedMechanism2d(2 * maximumDisplayableVelocity, 2 * maximumDisplayableVelocity);
final LoggedMechanismRoot2d root = mechanism.getRoot("Root", maximumDisplayableVelocity, maximumDisplayableVelocity);
this.currentVelocityLigament = root.append(new LoggedMechanismLigament2d("ZCurrentVelocityLigament", 0, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.BLUE));
this.currentVelocityTopArrowLigament = currentVelocityLigament.append(new LoggedMechanismLigament2d("ZCurrentVelocityTopArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_TOP_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.BLUE));
this.currentVelocityBottomArrowLigament = currentVelocityLigament.append(new LoggedMechanismLigament2d("ZCurrentVelocityBottomArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_BOTTOM_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.BLUE));

this.targetVelocityLigament = root.append(new MechanismLigament2d("TargetVelocityLigament", 0, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY));
this.targetVelocityTopArrowLigament = targetVelocityLigament.append(new MechanismLigament2d("TargetVelocityTopArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_TOP_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY));
this.targetVelocityBottomArrowLigament = targetVelocityLigament.append(new MechanismLigament2d("TargetVelocityBottomArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_BOTTOM_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY));
this.targetVelocityLigament = root.append(new LoggedMechanismLigament2d("TargetVelocityLigament", 0, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY));
this.targetVelocityTopArrowLigament = targetVelocityLigament.append(new LoggedMechanismLigament2d("TargetVelocityTopArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_TOP_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY));
this.targetVelocityBottomArrowLigament = targetVelocityLigament.append(new LoggedMechanismLigament2d("TargetVelocityBottomArrowLigament", MechanismConstants.ARROW_LENGTH_SCALE * maximumDisplayableVelocity, MechanismConstants.ZERO_BOTTOM_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY));
}

/**
Expand Down Expand Up @@ -114,7 +114,7 @@ else if (velocity < -deadband)
return MechanismConstants.BLUE;
}

private void setArrowAngle(double velocity, MechanismLigament2d topLigament, MechanismLigament2d bottomLigament) {
private void setArrowAngle(double velocity, LoggedMechanismLigament2d topLigament, LoggedMechanismLigament2d bottomLigament) {
if (velocity > deadband) {
topLigament.setAngle(MechanismConstants.POSITIVE_TOP_ANGLE);
bottomLigament.setAngle(MechanismConstants.POSITIVE_BOTTOM_ANGLE);
Expand Down
Loading
Loading