Skip to content
This repository has been archived by the owner on Dec 24, 2018. It is now read-only.

Commit

Permalink
Add telemetry logging (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewda authored Jul 27, 2018
1 parent 3d6618c commit cd0f424
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
!.idea/codeStyles
**.iml
build
src/main/resources/branch.txt
src/main/resources/buildtime.txt
src/main/resources/changes.txt
src/main/resources/commit.txt
43 changes: 42 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import java.text.SimpleDateFormat

buildscript {
ext.kotlinVersion = '1.2.31'
ext.kotlinVersion = '1.2.50'
ext.gradleRioVersion = '2018.03.06'
ext.sertainVersion = '1.2.0'
ext.ktlintVersion = '0.19.0'
Expand All @@ -23,6 +25,7 @@ tasks.whenTaskAdded { task ->
if (task.name == 'deploy' || task.name == 'deployMain') task.dependsOn 'assemble'
}
check.dependsOn 'ktlint'
compileKotlin.dependsOn 'versionTxt'

repositories {
google()
Expand Down Expand Up @@ -93,3 +96,41 @@ task ktlint(type: JavaExec) {
classpath = configurations.ktlint
args 'src/**/*.kt'
}

def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}

def getGitBranch = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--abbrev-ref', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}

def getGitFilesChanged = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'diff', '--name-only', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim().replace('\n', ', ')
}

task versionTxt() {
doLast {
String resourcesDir = "$projectDir/src/main/resources"
new File("$resourcesDir/branch.txt").text = getGitBranch()
new File("$resourcesDir/commit.txt").text = getGitHash()
new File("$resourcesDir/changes.txt").text = getGitFilesChanged()
new File("$resourcesDir/buildtime.txt").text =
new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())
}
}
6 changes: 6 additions & 0 deletions src/main/java/org/sert2521/powerup/Poe.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import org.sert2521.powerup.intake.Intake
import org.sert2521.powerup.util.Lights
import org.sert2521.powerup.util.Modes
import org.sert2521.powerup.util.UDPServer
import org.sert2521.powerup.util.initPreferences
import org.sert2521.powerup.util.logTelemetry
import org.sertain.Robot

class Poe : Robot() {
Expand All @@ -20,7 +22,11 @@ class Poe : Robot() {
Auto
Modes
Lights

UDPServer.start()
CameraServer.getInstance().startAutomaticCapture()

initPreferences()
logTelemetry()
}
}
35 changes: 35 additions & 0 deletions src/main/java/org/sert2521/powerup/util/Oi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.sert2521.powerup.util
import edu.wpi.first.wpilibj.Joystick
import edu.wpi.first.wpilibj.Preferences
import edu.wpi.first.wpilibj.XboxController
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard

// Driver joysticks. Left and right used for tank drive, only right used for arcade drive.
val leftJoystick by lazy { Joystick(LEFT_STICK_PORT) }
Expand All @@ -19,3 +20,37 @@ val normalEjectSpeedScalar
get() = Preferences.getInstance().getDouble("normal_eject_speed_scalar", 0.6)
val fastEjectSpeedScalar get() = Preferences.getInstance().getDouble("fast_eject_speed_scalar", 1.0)
val driveSpeedScalar get() = Preferences.getInstance().getDouble("drive_speed_scalar", 0.85)

fun initPreferences() {
Preferences.getInstance().putDouble("intake_speed_scalar", intakeSpeedScalar)
Preferences.getInstance().putDouble("normal_eject_speed_scalar", normalEjectSpeedScalar)
Preferences.getInstance().putDouble("fast_eject_speed_scalar", fastEjectSpeedScalar)
Preferences.getInstance().putDouble("drive_speed_scalar", driveSpeedScalar)
}

fun logTelemetry() {
"branch.txt".asResource {
println("Branch: $it")
SmartDashboard.putString("branch", it)
}

"commit.txt".asResource {
println("Commit: $it")
SmartDashboard.putString("commit", it)
}

"changes.txt".asResource {
println("Changes: $it")
SmartDashboard.putString("changes", it)
}

"buildtime.txt".asResource {
println("Buildtime: $it")
SmartDashboard.putString("buildtime", it)
}
}

fun String.asResource(work: (String) -> Unit) {
val content = this.javaClass::class.java.getResource("/$this").readText()
work(content)
}
Empty file added src/main/resources/.gitkeep
Empty file.

0 comments on commit cd0f424

Please sign in to comment.