Skip to content

Commit

Permalink
Add phoenix6 pigeon simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreiniger committed Jan 3, 2024
1 parent 642cca3 commit dd2a6ce
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 0 deletions.
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

39 changes: 39 additions & 0 deletions snobot_sim_java_phoenix6/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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",
],
)
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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",
],
)
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
5 changes: 5 additions & 0 deletions snobotsim_vendordep_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit dd2a6ce

Please sign in to comment.