diff --git a/settings.gradle b/settings.gradle index c3df992..d16271e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,3 +16,5 @@ include 'examples:test_robot_phoenix5_swerve' include 'examples:test_robot_rev' include 'examples:test_robot_rev_swerve' include 'examples:test_robot_wpi' +include 'snobot_sim_java_phoenix6' + diff --git a/snobot_sim_java_phoenix6/build.gradle b/snobot_sim_java_phoenix6/build.gradle new file mode 100644 index 0000000..f6351fa --- /dev/null +++ b/snobot_sim_java_phoenix6/build.gradle @@ -0,0 +1,39 @@ +plugins { + id 'java' + id 'maven-publish' + id 'edu.wpi.first.WpilibTools' version '1.1.0' +} + +group 'org.snobotv2' + +ext { + baseId = "snobot_sim_java_phoenix6" +} + +sourceCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 + +apply from: "${rootDir}/build_scripts/base_java.gradle" + +dependencies { + + implementation wpilibTools.deps.wpilibJava("wpilibj") + implementation wpilibTools.deps.wpilibJava("hal") + implementation wpilibTools.deps.wpilibJava("wpiutil") + implementation wpilibTools.deps.wpilibJava("wpimath") + implementation wpilibTools.deps.wpilibJava("wpiunits") + implementation wpilibTools.deps.wpilibJava("ntcore") + implementation wpilibTools.deps.wpilibJava("wpilibNewCommands") + implementation project(":snobot_sim_java_base") + + + implementation "com.ctre.phoenix6:wpiapi-java:${phoenix6Version}" + + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' + testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' + + testImplementation project(":snobot_sim_java_test_utils") +} + +apply from: "${rootDir}/build_scripts/base_java_publish.gradle" diff --git a/snobot_sim_java_phoenix6/src/main/java/org/snobotv2/module_wrappers/phoenix6/BUILD.bazel b/snobot_sim_java_phoenix6/src/main/java/org/snobotv2/module_wrappers/phoenix6/BUILD.bazel new file mode 100644 index 0000000..221f309 --- /dev/null +++ b/snobot_sim_java_phoenix6/src/main/java/org/snobotv2/module_wrappers/phoenix6/BUILD.bazel @@ -0,0 +1,12 @@ +load("//build_scripts/bazel:java_rules.bzl", "snobot_sim_java_library") + +snobot_sim_java_library( + name = "phoenix6", + srcs = glob(["*.java"]), + visibility = ["//visibility:public"], + deps = [ + "//snobot_sim_java_base/src/main/java/org/snobotv2/module_wrappers", + "@bzlmodrio-allwpilib//libraries/java/wpilibj", + "@bzlmodrio-phoenix6//libraries/java/wpiapi-java", + ], +) diff --git a/snobot_sim_java_phoenix6/src/main/java/org/snobotv2/module_wrappers/phoenix6/Pigeon2Wrapper.java b/snobot_sim_java_phoenix6/src/main/java/org/snobotv2/module_wrappers/phoenix6/Pigeon2Wrapper.java new file mode 100644 index 0000000..5796a9a --- /dev/null +++ b/snobot_sim_java_phoenix6/src/main/java/org/snobotv2/module_wrappers/phoenix6/Pigeon2Wrapper.java @@ -0,0 +1,13 @@ +package org.snobotv2.module_wrappers.phoenix6; + +import com.ctre.phoenix6.hardware.Pigeon2; +import org.snobotv2.module_wrappers.BaseGyroWrapper; + +@SuppressWarnings("removal") +public class Pigeon2Wrapper extends BaseGyroWrapper +{ + public Pigeon2Wrapper(Pigeon2 pigeon) + { + super((double angle) -> pigeon.getSimState().setRawYaw(-angle)); + } +} diff --git a/snobot_sim_java_phoenix6/src/test/java/org/snobotv2/module_wrappers/phoenix6/BUILD.bazel b/snobot_sim_java_phoenix6/src/test/java/org/snobotv2/module_wrappers/phoenix6/BUILD.bazel new file mode 100644 index 0000000..eafe12c --- /dev/null +++ b/snobot_sim_java_phoenix6/src/test/java/org/snobotv2/module_wrappers/phoenix6/BUILD.bazel @@ -0,0 +1,13 @@ +load("//build_scripts/bazel:java_rules.bzl", "snobot_sim_java_test") + +snobot_sim_java_test( + name = "test", + srcs = glob(["*.java"]), + deps = [ + "//snobot_sim_java_base/src/main/java/org/snobotv2/interfaces", + "//snobot_sim_java_phoenix6/src/main/java/org/snobotv2/module_wrappers/phoenix6", + "//snobot_sim_java_test_utils/src/main/java/org/snobotv2/test_utils", + "@bzlmodrio-allwpilib//libraries/java/hal", + "@bzlmodrio-phoenix6//libraries/java/wpiapi-java", + ], +) diff --git a/snobot_sim_java_phoenix6/src/test/java/org/snobotv2/module_wrappers/phoenix6/BasePhoenix6UnitTest.java b/snobot_sim_java_phoenix6/src/test/java/org/snobotv2/module_wrappers/phoenix6/BasePhoenix6UnitTest.java new file mode 100644 index 0000000..24067d9 --- /dev/null +++ b/snobot_sim_java_phoenix6/src/test/java/org/snobotv2/module_wrappers/phoenix6/BasePhoenix6UnitTest.java @@ -0,0 +1,21 @@ +package org.snobotv2.module_wrappers.phoenix6; + +import edu.wpi.first.hal.HAL; +import org.snobotv2.test_utils.BaseUnitTest; + +public class BasePhoenix6UnitTest extends BaseUnitTest +{ + protected void ctreSimLoop() + { + HAL.simPeriodicBefore(); + HAL.simPeriodicAfter(); + + try + { + Thread.sleep(20); + } catch (InterruptedException e) + { + e.printStackTrace(); // NOPMD + } + } +} diff --git a/snobot_sim_java_phoenix6/src/test/java/org/snobotv2/module_wrappers/phoenix6/TestPigeon2.java b/snobot_sim_java_phoenix6/src/test/java/org/snobotv2/module_wrappers/phoenix6/TestPigeon2.java new file mode 100644 index 0000000..6cbd5b3 --- /dev/null +++ b/snobot_sim_java_phoenix6/src/test/java/org/snobotv2/module_wrappers/phoenix6/TestPigeon2.java @@ -0,0 +1,40 @@ +package org.snobotv2.module_wrappers.phoenix6; + +import com.ctre.phoenix6.hardware.Pigeon2; +import org.junit.jupiter.api.Test; +import org.snobotv2.interfaces.IGyroWrapper; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@SuppressWarnings("removal") +public class TestPigeon2 extends BasePhoenix6UnitTest +{ + private static final double PIGEON_EPSILON = 1e-2; + + @Test + public void testBasicInline() + { + try (Pigeon2 pigeon = new Pigeon2(3)) + { + pigeon.reset(); + ctreSimLoop(); + + runTests(pigeon); + } + } + + private void runTests(Pigeon2 pigeon) + { + IGyroWrapper wrapper = new Pigeon2Wrapper(pigeon); + + assertEquals(0, pigeon.getAngle(), PIGEON_EPSILON); + + wrapper.setAngle(20); + ctreSimLoop(); + assertEquals(20, pigeon.getAngle(), PIGEON_EPSILON); + + wrapper.setAngle(-43.2); + ctreSimLoop(); + assertEquals(-43.2, pigeon.getAngle(), PIGEON_EPSILON); + } +} diff --git a/snobotsim_vendordep_template.json b/snobotsim_vendordep_template.json index 55f2a2c..e59254c 100644 --- a/snobotsim_vendordep_template.json +++ b/snobotsim_vendordep_template.json @@ -22,6 +22,11 @@ "artifactId": "snobot_sim_java_phoenix5", "version": "$VERSION" }, + { + "groupId": "org.snobotv2", + "artifactId": "snobot_sim_java_phoenix6", + "version": "$VERSION" + }, { "groupId": "org.snobotv2", "artifactId": "snobot_sim_java_revlib",