Skip to content

Commit f311b72

Browse files
authored
Merge pull request #22 from strykeforce/frc-2022
Update for 2022 FRC dependencies
2 parents f92085b + 5246fa1 commit f311b72

20 files changed

+284
-209
lines changed

build.gradle

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,38 @@
1+
import edu.wpi.first.gradlerio.deploy.roborio.RoboRIO
2+
13
plugins {
24
id "java"
3-
id "org.jetbrains.kotlin.jvm" version "1.5.0"
4-
id "edu.wpi.first.GradleRIO" version "2021.3.1"
5+
id "org.jetbrains.kotlin.jvm" version "1.6.10"
6+
id "edu.wpi.first.GradleRIO" version "2022.1.1"
57
}
68

7-
version = "21.0.0"
9+
version = "22.0.0"
810

911
sourceCompatibility = JavaVersion.VERSION_11
1012
targetCompatibility = JavaVersion.VERSION_11
1113

1214
def ROBOT_MAIN_CLASS = "org.strykeforce.thirdcoast.DummyMain"
1315

14-
// Define my targets (RoboRIO) and artifacts (deployable files)
15-
// This is added by GradleRIO's backing project EmbeddedTools.
1616
deploy {
1717
targets {
18-
roboRIO("roborio") {
19-
// Team number is loaded either from the .wpilib/wpilib_preferences.json
20-
// or from command line. If not found an exception will be thrown.
21-
// You can use getTeamOrDefault(team) instead of getTeamNumber if you
22-
// want to store a team number in this file.
23-
team = frc.getTeamNumber()
24-
}
25-
}
26-
artifacts {
27-
frcJavaArtifact('frcJava') {
28-
targets << "roborio"
29-
// Debug can be overridden by command line, for use with VSCode
30-
debug = frc.getDebugOrDefault(false)
31-
}
32-
// Built in artifact to deploy arbitrary files to the roboRIO.
33-
fileTreeArtifact('frcStaticFileDeploy') {
34-
// The directory below is the local directory to deploy
35-
files = fileTree(dir: 'src/main/deploy')
36-
// Deploy to RoboRIO target, into /home/lvuser/deploy
37-
targets << "roborio"
38-
directory = '/home/lvuser/deploy'
18+
roborio(getTargetTypeClass('RoboRIO')) {
19+
team = project.frc.getTeamNumber()
20+
debug = project.frc.getDebugOrDefault(false)
21+
artifacts {
22+
frcJava(getArtifactTypeClass('FRCJavaArtifact')) {}
23+
frcStaticFileDeploy(getArtifactTypeClass('FileTreeArtifact')) {
24+
files = project.fileTree('src/main/deploy')
25+
directory = '/home/lvuser/deploy'
26+
}
27+
}
3928
}
4029
}
4130
}
4231

43-
// Set this to true to enable desktop support.
32+
def deployArtifact = deploy.targets.roborio.artifacts.frcJava
33+
34+
wpi.java.debugJni = false
35+
4436
def includeDesktopSupport = false
4537

4638
repositories {
@@ -50,14 +42,22 @@ repositories {
5042
// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries.
5143
// Also defines JUnit 4.
5244
dependencies {
53-
implementation wpi.deps.wpilib()
54-
nativeZip wpi.deps.wpilibJni(wpi.platforms.roborio)
55-
nativeDesktopZip wpi.deps.wpilibJni(wpi.platforms.desktop)
45+
implementation wpi.java.deps.wpilib()
46+
implementation wpi.java.vendor.java()
5647

48+
roborioDebug wpi.java.deps.wpilibJniDebug(wpi.platforms.roborio)
49+
roborioDebug wpi.java.vendor.jniDebug(wpi.platforms.roborio)
5750

58-
implementation wpi.deps.vendor.java()
59-
nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio)
60-
nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop)
51+
roborioRelease wpi.java.deps.wpilibJniRelease(wpi.platforms.roborio)
52+
roborioRelease wpi.java.vendor.jniRelease(wpi.platforms.roborio)
53+
54+
nativeDebug wpi.java.deps.wpilibJniDebug(wpi.platforms.desktop)
55+
nativeDebug wpi.java.vendor.jniDebug(wpi.platforms.desktop)
56+
simulationDebug wpi.sim.enableDebug()
57+
58+
nativeRelease wpi.java.deps.wpilibJniRelease(wpi.platforms.desktop)
59+
nativeRelease wpi.java.vendor.jniRelease(wpi.platforms.desktop)
60+
simulationRelease wpi.sim.enableRelease()
6161

6262
// We need to add the Kotlin stdlib in order to use most Kotlin language features.
6363
// implementation "org.jetbrains.kotlin:kotlin-stdlib"
@@ -68,8 +68,8 @@ dependencies {
6868
implementation("net.consensys.cava:cava-toml:0.5.0")
6969

7070
// Logging
71-
implementation("io.github.microutils:kotlin-logging-jvm:2.0.6")
72-
implementation("ch.qos.logback:logback-classic:1.2.3")
71+
implementation('io.github.microutils:kotlin-logging-jvm:2.1.21')
72+
implementation('ch.qos.logback:logback-classic:1.2.10')
7373

7474
// Koin
7575
implementation("org.koin:koin-core:1.0.2")
@@ -81,10 +81,6 @@ dependencies {
8181
testImplementation("org.junit.jupiter:junit-jupiter")
8282
testImplementation("org.assertj:assertj-core:3.19.0")
8383
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0")
84-
85-
// Enable simulation gui support. Must check the box in vscode to enable support
86-
// upon debugging
87-
simulation wpi.deps.sim.gui(wpi.platforms.desktop, false)
8884
}
8985

9086
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
@@ -97,16 +93,13 @@ test {
9793
useJUnitPlatform()
9894
}
9995

100-
// Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar')
101-
// in order to make them all available at runtime. Also adding the manifest so WPILib
102-
// knows where to look for our Robot Class.
10396
jar {
10497
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
10598
manifest edu.wpi.first.gradlerio.GradleRIOPlugin.javaManifest(ROBOT_MAIN_CLASS)
106-
manifest {
107-
attributes(
108-
'Implementation-Title': 'Third Coast Telemetry Utility (tct)',
109-
'Implementation-Version': archiveVersion
110-
)
111-
}
99+
duplicatesStrategy = DuplicatesStrategy.INCLUDE
112100
}
101+
102+
// Configure jar and deploy tasks
103+
deployArtifact.jarTask = jar
104+
wpi.java.configureExecutableTasks(jar)
105+
wpi.java.configureTestTasks(test)

gradle/wrapper/gradle-wrapper.jar

501 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=permwrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=permwrapper/dists

gradlew

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ esac
8282

8383
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
8484

85+
8586
# Determine the Java command to use to start the JVM.
8687
if [ -n "$JAVA_HOME" ] ; then
8788
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -129,6 +130,7 @@ fi
129130
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
130131
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131132
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133+
132134
JAVACMD=`cygpath --unix "$JAVACMD"`
133135

134136
# We build the pattern for arguments to be converted via cygpath

gradlew.bat

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
2929
set APP_BASE_NAME=%~n0
3030
set APP_HOME=%DIRNAME%
3131

32+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
33+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34+
3235
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
3336
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
3437

@@ -37,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
3740

3841
set JAVA_EXE=java.exe
3942
%JAVA_EXE% -version >NUL 2>&1
40-
if "%ERRORLEVEL%" == "0" goto init
43+
if "%ERRORLEVEL%" == "0" goto execute
4144

4245
echo.
4346
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -51,7 +54,7 @@ goto fail
5154
set JAVA_HOME=%JAVA_HOME:"=%
5255
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5356

54-
if exist "%JAVA_EXE%" goto init
57+
if exist "%JAVA_EXE%" goto execute
5558

5659
echo.
5760
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -61,28 +64,14 @@ echo location of your Java installation.
6164

6265
goto fail
6366

64-
:init
65-
@rem Get command-line arguments, handling Windows variants
66-
67-
if not "%OS%" == "Windows_NT" goto win9xME_args
68-
69-
:win9xME_args
70-
@rem Slurp the command line arguments.
71-
set CMD_LINE_ARGS=
72-
set _SKIP=2
73-
74-
:win9xME_args_slurp
75-
if "x%~1" == "x" goto execute
76-
77-
set CMD_LINE_ARGS=%*
78-
7967
:execute
8068
@rem Setup the command line
8169

8270
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
8371

72+
8473
@rem Execute Gradle
85-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
74+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
8675

8776
:end
8877
@rem End local scope for the variables with windows NT shell

settings.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pluginManagement {
44
repositories {
55
mavenLocal()
66
gradlePluginPortal()
7-
String frcYear = '2020'
7+
String frcYear = '2022'
88
File frcHome
99
if (OperatingSystem.current().isWindows()) {
1010
String publicFolder = System.getenv('PUBLIC')
@@ -25,5 +25,3 @@ pluginManagement {
2525
}
2626
}
2727
}
28-
29-
rootProject.name = "tct"

src/main/kotlin/org/strykeforce/thirdcoast/Koin.kt

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@ import com.ctre.phoenix.motorcontrol.can.TalonFX
77
import com.ctre.phoenix.motorcontrol.can.TalonSRX
88
import com.ctre.phoenix.motorcontrol.can.TalonSRXConfiguration
99
import com.ctre.phoenix.sensors.PigeonIMU
10+
import edu.wpi.first.math.geometry.Translation2d
1011
import edu.wpi.first.wpilibj.DigitalOutput
12+
import edu.wpi.first.wpilibj.PneumaticsModuleType
1113
import edu.wpi.first.wpilibj.Servo
1214
import edu.wpi.first.wpilibj.Solenoid
1315
import org.jline.reader.LineReader
1416
import org.jline.reader.LineReaderBuilder
1517
import org.jline.terminal.Terminal
1618
import org.jline.terminal.TerminalBuilder
1719
import org.koin.dsl.module.module
20+
import org.strykeforce.swerve.*
1821
import org.strykeforce.thirdcoast.command.Command
1922
import org.strykeforce.thirdcoast.device.*
20-
import org.strykeforce.thirdcoast.swerve.SwerveDrive
21-
import org.strykeforce.thirdcoast.swerve.SwerveDriveConfig
22-
import org.strykeforce.thirdcoast.swerve.Wheel
23-
import org.strykeforce.thirdcoast.telemetry.TelemetryController
24-
import org.strykeforce.thirdcoast.telemetry.TelemetryService
25-
import org.strykeforce.thirdcoast.telemetry.grapher.ClientHandler
23+
import org.strykeforce.telemetry.TelemetryController
24+
import org.strykeforce.telemetry.TelemetryService
25+
import org.strykeforce.telemetry.grapher.ClientHandler
2626
import java.net.DatagramSocket
27+
import java.net.InetSocketAddress
2728
import java.util.function.Function
2829

2930
private const val CLIENT_PORT = 5801
@@ -33,15 +34,23 @@ val tctModule = module {
3334

3435
factory { ClientHandler(CLIENT_PORT, DatagramSocket()) }
3536

36-
single { TelemetryService(Function { inventory -> TelemetryController(inventory, get(), SERVER_PORT) }) }
37+
single {
38+
TelemetryService(Function { inventory ->
39+
TelemetryController(
40+
inventory,
41+
get(),
42+
InetSocketAddress(SERVER_PORT)
43+
)
44+
})
45+
}
3746

3847
single { TalonService(get()) { id -> TalonSRX(id) } }
39-
48+
4049
single { TalonFxService(get()) { id -> TalonFX(id) } }
4150

4251
single { ServoService { id -> Servo(id) } }
4352

44-
single { SolenoidService { id -> Solenoid(id) } }
53+
single { SolenoidService { id -> Solenoid(PneumaticsModuleType.CTREPCM, id) } }
4554

4655
single { DigitalOutputService { id -> DigitalOutput(id) } }
4756

@@ -59,16 +68,27 @@ val tctModule = module {
5968

6069
val swerveModule = module {
6170

62-
single {
63-
SwerveDriveConfig().apply {
64-
wheels = getWheels()
65-
}
66-
}
71+
single { SwerveDrive(*getSwerveModules()) }
72+
73+
}
6774

68-
single { SwerveDrive(get()) }
75+
private fun getSwerveModules() = Array<SwerveModule>(4) { i -> getSwerveModule(i) }
6976

77+
private val moduleBuilder = TalonSwerveModule.Builder().driveGearRatio(1.0).wheelDiameterInches(1.0)
78+
.driveMaximumMetersPerSecond(1.0)
79+
80+
private fun getSwerveModule(i: Int) : TalonSwerveModule {
81+
val location = when (i) {
82+
0 -> Translation2d(1.0, 1.0)
83+
1 -> Translation2d(1.0, -1.0)
84+
2 -> Translation2d(-1.0, 1.0)
85+
else -> Translation2d(-1.0, -1.0)
86+
}
87+
return moduleBuilder.azimuthTalon(TalonSRX(i)).driveTalon(TalonFX(i + 10))
88+
.wheelLocationMeters(location).build()
7089
}
7190

91+
/*
7292
private fun getWheels(): Array<Wheel> {
7393
val azimuthConfig = TalonSRXConfiguration().apply {
7494
primaryPID.selectedFeedbackSensor = FeedbackDevice.CTRE_MagEncoder_Relative
@@ -107,3 +127,4 @@ private fun getWheels(): Array<Wheel> {
107127
)
108128
}
109129
}
130+
*/

src/main/kotlin/org/strykeforce/thirdcoast/Readers.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.jline.terminal.Terminal
77
import org.strykeforce.thirdcoast.command.DOUBLE_FORMAT_4
88
import org.strykeforce.thirdcoast.command.MenuCommand
99
import org.strykeforce.thirdcoast.command.prompt
10+
import java.util.*
1011
import kotlin.math.roundToInt
1112

1213
const val INVALID = -1
@@ -40,7 +41,7 @@ fun LineReader.readDouble(
4041

4142
fun LineReader.readBoolean(prompt: String = PROMPT, default: Boolean = false) = try {
4243
val line = this.readLine(prompt, null, if (default) "y" else "n").trim()
43-
when (line.toLowerCase()) {
44+
when (line.lowercase(Locale.getDefault())) {
4445
"y" -> true
4546
"n" -> false
4647
"" -> throw EndOfFileException()

src/main/kotlin/org/strykeforce/thirdcoast/Robot.kt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.strykeforce.thirdcoast
22

3-
import edu.wpi.first.wpilibj.PowerDistributionPanel
4-
import org.strykeforce.thirdcoast.telemetry.item.PowerDistributionPanelItem
53
import edu.wpi.first.wpilibj.TimedRobot
64
import mu.KotlinLogging
75
import net.consensys.cava.toml.Toml
@@ -11,8 +9,8 @@ import org.koin.log.Logger.SLF4JLogger
119
import org.koin.standalone.KoinComponent
1210
import org.koin.standalone.StandAloneContext.startKoin
1311
import org.koin.standalone.inject
12+
import org.strykeforce.telemetry.TelemetryService
1413
import org.strykeforce.thirdcoast.command.Command
15-
import org.strykeforce.thirdcoast.telemetry.TelemetryService
1614
import kotlin.concurrent.thread
1715
import kotlin.system.exitProcess
1816

@@ -22,8 +20,7 @@ class Robot : TimedRobot(), KoinComponent {
2220

2321
override fun robotInit() {
2422
startKoin(listOf(tctModule, swerveModule), logger = SLF4JLogger())
25-
val telemetryService:TelemetryService by inject()
26-
telemetryService.register(PowerDistributionPanelItem(PowerDistributionPanel()))
23+
val telemetryService: TelemetryService by inject()
2724
thread(name = "tct", start = true) {
2825
val toml = parseResource("/commands.toml")
2926
val root = Command.createFromToml(toml)
@@ -54,9 +51,8 @@ fun parseResource(path: String): TomlTable {
5451
exitProcess(-1)
5552
}
5653

57-
fun loadResource(resource: String): String =
58-
try {
59-
object {}.javaClass.getResource(resource).readText(Charsets.UTF_8)
60-
} catch (all: Exception) {
61-
throw RuntimeException("Failed to load resource=$resource!", all)
62-
}
54+
fun loadResource(resource: String): String = try {
55+
object {}.javaClass.getResource(resource).readText(Charsets.UTF_8)
56+
} catch (all: Exception) {
57+
throw RuntimeException("Failed to load resource=$resource!", all)
58+
}

0 commit comments

Comments
 (0)