Skip to content

Commit

Permalink
Update to 2025.0.8
Browse files Browse the repository at this point in the history
Added Examples of Arm2d, Elevator2d, and Flywheel2d from porting over 2024 code
  • Loading branch information
jonathandao0 committed Jan 27, 2025
1 parent acb6dbf commit 8539f59
Show file tree
Hide file tree
Showing 37 changed files with 748 additions and 87 deletions.
2 changes: 1 addition & 1 deletion publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'maven-publish'

ext.licenseFile = files("$rootDir/LICENSE.txt")

def pubVersion = '2025.0.7'
def pubVersion = '2025.0.8'

def releasesRepoUrl = "$buildDir/../releases/repos"

Expand Down
4 changes: 2 additions & 2 deletions releases/frc4201Codex.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"fileName": "frc4201Codex.json",
"name": "Codex-java",
"version": "2025.0.7",
"version": "2025.0.8",
"frcYear": "2025",
"uuid": "5db6a80c-246e-48c6-b629-798597b993e1",
"mavenUrls": [
Expand All @@ -12,7 +12,7 @@
{
"groupId": "org.team4201",
"artifactId": "Codex-java",
"version": "2025.0.7"
"version": "2025.0.8"
}
],
"requires": [
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6d11fcc0c9505a91a71f8a423956d7e9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ff2d3bfe1d47200847b571f4d2eab003fe20e2d4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c85109c1d1603514fb072f511f4e83b44b524c07db3d8f741e4e7cd879160685
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3c57c1232fc5a4a249fc0df65f7ee56998a0cf2570f9dc9ac4aa58e50681964b2c69f022295ec0c6666cbe897c73098c733b9cde4c4ef014e3fa6c1d58987fee
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15ebc82253229d71dac7d6dc099c4ca2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
90547d72e1f532f3097e667650360981fe0fc76d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4708e8e8a939530d04155b324133c63679e636514c9669d50f0f5f2da889e638
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
50b86ac6e18a5c055494a9dd866c1c6756e4ab3b6957f7b4668bfd54ecfd1f15ba5aab8747771c51bb27a7ab32a88e5f8e95c1cb7183620b6b76554e2f78136f
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dd0d5897faecea3067ff6502c6e41925
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
40f79aa79e8272be5f46b598c73f214eb70d8804
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cc509e2dfb9a1b4949cf9b466d42eb636b609a3fde8473d53d1a21fa204cd337
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
214fd63f2543793f06056d64b6b241328e60953f1011ec5804bf5aeb4ae099f155e7dc154dac6cf24549a589355c092c3a7ce345d03c57807cd6cff3f4f9cc3c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.team4201</groupId>
<artifactId>Codex-java</artifactId>
<version>2025.0.8</version>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8d259f1a73931d69e48ece2262a7c9eb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8a86d64eae0462c6af1ac5d9067b4c22b07b0a49
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
83cb8df8dd0d0decdc30b77eabb71a65711ee365d18e59ae6940f06ca6090bec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f79a12d1df3a0388d05fd5ced3c323619aa3bec1df67eed0bc286bf3401382cb2bcb58477bc69a4d9416ce2824e8751b921cc7d1e4a7a48d1a1b5afd96e23570
7 changes: 4 additions & 3 deletions releases/repos/org/team4201/Codex-java/maven-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<groupId>org.team4201</groupId>
<artifactId>Codex-java</artifactId>
<versioning>
<latest>2025.0.7</latest>
<release>2025.0.7</release>
<latest>2025.0.8</latest>
<release>2025.0.8</release>
<versions>
<version>2025.0.1</version>
<version>2025.0.2</version>
Expand All @@ -13,7 +13,8 @@
<version>2025.0.5</version>
<version>2025.0.6</version>
<version>2025.0.7</version>
<version>2025.0.8</version>
</versions>
<lastUpdated>20250121072532</lastUpdated>
<lastUpdated>20250127001739</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e74c5081964c4fd3f7d0c695f5a247bf
97d28333094cf5f92d1695e32e54b3f1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3d8468d1991db982ca5b5d85267496988ceed2fe
70ff7d72fe79203e6c36a2f45cde78ddb616caf0
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3bcdd5ee374718967b46baf59668286799e137d16426d599f95ce3c377ff147f
d44f4e8863e5bf8981a34ae7e365b870322c7a04ba3a373603e378e2668ed863
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c06792ea57f2a6168d40df85a8ca7556b28cb53a3641b0c297b47c383caa7703f1dfcf068e427b1e865f779178f7e646ec0de0325859eace1a202ba6088d9c8d
7d6a6a0939b007e119eaac3f420ea9539dda74ef3eff501108f8608a717885e17127593a7991dca9ed243e493867c9de76bbd1018140908183e19fac6e4abebf
50 changes: 44 additions & 6 deletions src/main/java/org/team4201/codex/Robot.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package org.team4201.codex;

import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.RobotBase;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.Field2d;
import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d;
import edu.wpi.first.units.measure.Distance;
import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.smartdashboard.*;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import org.team4201.codex.simulation.FieldSim;
import org.team4201.codex.simulation.visualization.Arm2d;
import org.team4201.codex.simulation.visualization.Elevator2d;
import org.team4201.codex.simulation.visualization.Flywheel2d;
import org.team4201.codex.simulation.visualization.configs.Arm2dConfig;
import org.team4201.codex.simulation.visualization.configs.Elevator2dConfig;
import org.team4201.codex.simulation.visualization.configs.Flywheel2dConfig;

import static edu.wpi.first.units.Units.*;

/**
* This is NOT meant for running full robot code. It is meant for testing code that can't be easily unit tested
Expand All @@ -15,6 +21,14 @@
*/
public class Robot extends TimedRobot {
FieldSim fieldSim = new FieldSim();


Mechanism2d testBot = new Mechanism2d(30, 30);
MechanismRoot2d superStructureRoot = testBot.getRoot("superStructureRoot", 15, 1);
Elevator2d elevator2d = new Elevator2d(new Elevator2dConfig("testElevator"), superStructureRoot);
Arm2d arm2d = new Arm2d(new Arm2dConfig("testArm"), elevator2d.getLigament());
Flywheel2d flywheel2d = new Flywheel2d(new Flywheel2dConfig("testFlywheel"), arm2d.getLigament());

/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
Expand All @@ -24,6 +38,23 @@ public Robot() {
DriverStation.reportError("Codex should not be run as robot code!", false);
throw new RuntimeException("Codex is run as robot code!");
}

Mechanism2d elevatorMechanism = new Mechanism2d(10, 30);
elevator2d.setAngle(Degree.of(90));
elevatorMechanism.getRoot("elevatorRoot", 5, 1).append(elevator2d.getSubElevator().getLigament());

Mechanism2d armMechanism = new Mechanism2d(15, 15);
arm2d.setAngle(Degree.of(90));
arm2d.getArmSubMechanism().getConfig().setAngleOffset(Degree.of(90));
armMechanism.getRoot("armRoot", 7.5, 1).append(arm2d.getArmSubMechanism().getLigament());

Mechanism2d flywheelMechanism = new Mechanism2d(5, 5);
flywheelMechanism.getRoot("flywheelRoot", 2.5, 2.5).append(flywheel2d.getSubFlywheel().getLigament());

SmartDashboard.putData("testBot", testBot);
SmartDashboard.putData("elevator", elevatorMechanism);
SmartDashboard.putData("arm", armMechanism);
SmartDashboard.putData("flywheel", flywheelMechanism);
}

/**
Expand Down Expand Up @@ -84,5 +115,12 @@ public void simulationInit() {}

/** This function is called periodically whilst in simulation. */
@Override
public void simulationPeriodic() {}
public void simulationPeriodic() {
System.out.println("Elevator2d Height: " + elevator2d.getLigament().getLength());
System.out.println("Arm2d Angle: " + arm2d.getLigament().getAngle());
System.out.println("Flywheel2d Angle: " + flywheel2d.getLigament().getAngle());
arm2d.update(Radians.of(Math.sin(Timer.getFPGATimestamp() % (2 * Math.PI))));
elevator2d.update(Inches.of(Math.abs(Math.sin(Timer.getFPGATimestamp() % (2 * Math.PI))) * 24));
flywheel2d.update(RotationsPerSecond.of(6 * Timer.getFPGATimestamp()));
}
}
134 changes: 118 additions & 16 deletions src/main/java/org/team4201/codex/simulation/visualization/Arm2d.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,165 @@
package org.team4201.codex.simulation.visualization;

import edu.wpi.first.units.measure.Angle;
import edu.wpi.first.units.measure.AngularVelocity;
import edu.wpi.first.units.measure.Distance;
import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d;
import edu.wpi.first.wpilibj.util.Color8Bit;
import edu.wpi.first.wpilibj.smartdashboard.MechanismObject2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d;
import org.team4201.codex.simulation.visualization.configs.Arm2dConfig;

import static edu.wpi.first.units.Units.*;

/**
* Class to represent an arm using {@link Mechanism2d}
* */
public class Arm2d implements AutoCloseable {
private final Arm2dConfig m_config;
private final MechanismLigament2d m_arm2d;
private final Color8Bit m_ligamentColor = new Color8Bit(235, 137, 52);
private final String m_name;
private MechanismObject2d m_parentObject;
private Arm2d m_subArm2d;

/**
* Create a new {@link Arm2d} instance
*
* @param name The name of the object (Must be unique across all {@link Mechanism2d} objects)
* @param config The {@link Arm2dConfig} that defines the Arm2d parameters
*/
public Arm2d(String name) {
m_name = name;
public Arm2d(Arm2dConfig config) {
this(config, null);
}

/**
* Create a new {@link Arm2d} instance
*
* @param config The {@link Arm2dConfig} that defines the Arm2d parameters
* @param parentObject The {@link MechanismObject2d} (Either a {@link MechanismRoot2d} or
* {@link MechanismLigament2d})the Arm2d attaches to
*/
public Arm2d(Arm2dConfig config, MechanismLigament2d parentObject) {
m_config = config;

// Create a "line" to represent the arm.
// We will use this to show its current position
m_arm2d = new MechanismLigament2d(m_name, 0, 0);
m_arm2d = new MechanismLigament2d(m_config.m_name,
m_config.m_initialLength.in(Inches),
m_config.m_initialAngle.in(Degrees),
m_config.m_initialWidth.in(Inches),
m_config.m_color);

if (parentObject != null) {
m_parentObject = parentObject;

Arm2dConfig armSubConfig = m_config.clone();
armSubConfig.m_name = armSubConfig.m_name + "_sub";
m_subArm2d = new Arm2d(armSubConfig);
m_parentObject.append(m_arm2d);
}
}

/**
* Get the {@link Arm2d}'s {@link Arm2dConfig}
*
* @return {@link Arm2dConfig}
*/
public Arm2dConfig getConfig() {
return m_config;
}

/**
* Get the {@link Arm2d}'s {@link MechanismLigament2d}
*
* @return {@link MechanismLigament2d}
*/
public MechanismLigament2d getArmLigament() {
public MechanismLigament2d getLigament() {
return m_arm2d;
}

/**
* Get the {@link Arm2d}'s parent {@link MechanismObject2d}. Returns null if it doesn't exist.
*
* @return {@link MechanismObject2d}
*/
public MechanismObject2d getParentObject() {
return m_parentObject;
}

/**
* Get the {@link Arm2d}'s subMechanism. For displaying the mechanism by itself.
*
* @return {@link Arm2d}
*/
public Arm2d getArmSubMechanism() {
return m_subArm2d;
}
/**
* Set the {@link Arm2d}'s {@link Angle}.
*
* @param angle Angle of the Arm2d
*/
public void setAngle(Angle angle) {
setAngle(angle, angle);
}

/**
* Set the {@link Arm2d}'s {@link Angle}. This function is used if you want a separate orientation for
* the standalone display of the Arm2d.
*
* @param angle Angle of the Arm2d
* @param subAngle Angle of the Arm2d's subMechanism.
*/
public void setAngle(Angle angle, Angle subAngle) {
m_arm2d.setAngle(angle.in(Degrees));

if (m_subArm2d != null) {
m_subArm2d.getLigament().setAngle(subAngle.in(Degrees));
}
}

/**
* Update the {@link Arm2d}'s position relative to its attachment point
*
* @param angle The angle to set the Arm2d to.
*/
public void update(Angle angle) {
update(angle, RotationsPerSecond.of(0));
}

/**
* Update the {@link Arm2d}'s position relative to its attachment point
*
* @param angle The angle to set the {@link Arm2d} to.
* @param angle The angle to set the Arm2d to.
* @param velocity The velocity of the Arm2d. Used to change the color of the Arm2d for visualization.
*/
public void update(double angle) {
update(angle, 0);
public void update(Angle angle, AngularVelocity velocity) {
update(angle, RotationsPerSecond.of(0), m_config.m_initialLength);
}

/**
* Update the {@link Arm2d}'s position relative to its attachment point
*
* @param angle The angle to set the {@link Arm2d} to.
* @param velocity The velocity of the {@link Arm2d}. Used to change the color of the {@link Arm2d} for visualization.
* @param angle The angle to set the Arm2d to.
* @param velocity The velocity of the Arm2d. Used to change the color of the Arm2d for visualization.
* @param length The length of the Arm2d. By default, it will use its initial length.
*/
public void update(double angle, double velocity) {
// m_arm2d.setAngle(307.5 - m_armJoint2d.getAngle() - angle);
public void update(Angle angle, AngularVelocity velocity, Distance length) {
m_arm2d.setLength(length.in(Inches));
m_arm2d.setAngle(m_config.m_angleOffset.minus(angle).in(Degrees));

// Update the ligament color based on the module's current speed for easier visualization
VisualizationUtils.updateMotorColor(m_arm2d, velocity, m_ligamentColor);
VisualizationUtils.updateMotorColor(m_arm2d, velocity.in(RotationsPerSecond), m_config.m_color);

if(m_subArm2d != null) {
m_subArm2d.update(angle, velocity, length);
}
}

@Override
public void close() throws Exception {
m_arm2d.close();

if(m_subArm2d != null) {
m_subArm2d.close();
}
}
}
Loading

0 comments on commit 8539f59

Please sign in to comment.