-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
642cca3
commit dd2a6ce
Showing
8 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
12 changes: 12 additions & 0 deletions
12
snobot_sim_java_phoenix6/src/main/java/org/snobotv2/module_wrappers/phoenix6/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
13 changes: 13 additions & 0 deletions
13
...sim_java_phoenix6/src/main/java/org/snobotv2/module_wrappers/phoenix6/Pigeon2Wrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
snobot_sim_java_phoenix6/src/test/java/org/snobotv2/module_wrappers/phoenix6/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
21 changes: 21 additions & 0 deletions
21
...va_phoenix6/src/test/java/org/snobotv2/module_wrappers/phoenix6/BasePhoenix6UnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ot_sim_java_phoenix6/src/test/java/org/snobotv2/module_wrappers/phoenix6/TestPigeon2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters