Skip to content

Commit 45de424

Browse files
committed
Merge branch 'telemetry-rewrite'
2 parents b8fc96e + 54aafec commit 45de424

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+268
-162
lines changed

build.gradle

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,72 @@
1-
plugins {
2-
id "java"
3-
id "idea"
4-
id "net.ltgt.apt-idea" version "0.15"
5-
id "jaci.openrio.gradle.GradleRIO" version "2018.03.06" apply false
6-
id "net.ltgt.errorprone" version "0.0.13"
7-
id "com.diffplug.gradle.spotless" version "3.10.0"
8-
}
9-
10-
description = 'Third Coast Framework'
11-
12-
ext {
13-
libs = [
14-
jetbrainsAnnotations: 'org.jetbrains:annotations:15.0',
15-
jsr305 : 'com.google.code.findbugs:jsr305:3.0.2',
16-
bytebuddy : 'net.bytebuddy:byte-buddy:1.7.10',
17-
dagger : 'com.google.dagger:dagger:2.14.1',
18-
daggerCompiler : 'com.google.dagger:dagger-compiler:2.14.1',
19-
logback : 'ch.qos.logback:logback-classic:1.2.3',
20-
moshi : 'com.squareup.moshi:moshi:1.5.0',
21-
nanohttpd : 'org.nanohttpd:nanohttpd:2.3.2-SNAPSHOT',
22-
objenesis : 'org.objenesis:objenesis:2.6',
23-
slf4j : 'org.slf4j:slf4j-api:1.7.25',
24-
spock : 'org.spockframework:spock-core:1.1-groovy-2.4',
25-
toml4j : 'com.moandjiezana.toml:toml4j:0.7.2',
26-
autoFactory : 'com.google.auto.factory:auto-factory:1.0-beta5',
27-
]
28-
specificationTitle = 'Third Coast Library'
29-
specificationVersion = '18.5.0'
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
maven { url "https://plugins.gradle.org/m2/" }
5+
}
6+
dependencies {
7+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+'
8+
classpath "gradle.plugin.jaci.openrio.gradle:GradleRIO:2018.03.06"
9+
classpath "net.ltgt.gradle:gradle-apt-plugin:0.18"
10+
classpath "com.diffplug.spotless:spotless-plugin-gradle:3.14.0"
11+
classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.16"
12+
}
3013
}
3114

3215
subprojects {
33-
apply plugin: 'java'
16+
group = 'org.strykeforce.thirdcoast'
17+
version = '18.6.0'
18+
19+
apply plugin: 'java-library'
20+
apply plugin: 'groovy'
3421
apply plugin: 'jaci.openrio.gradle.GradleRIO'
3522
apply plugin: 'net.ltgt.apt-idea'
23+
apply plugin: 'com.diffplug.gradle.spotless'
3624
apply plugin: 'net.ltgt.errorprone'
3725

3826
repositories {
3927
jcenter()
40-
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } // nanohttpd
4128
}
42-
}
4329

44-
spotless {
45-
java {
46-
googleJavaFormat()
47-
target '**/*.java'
30+
dependencies {
31+
implementation wpilib()
32+
implementation ctre()
33+
implementation navx()
34+
implementation 'com.moandjiezana.toml:toml4j:0.7.2'
35+
implementation 'org.slf4j:slf4j-api:1.7.25'
36+
implementation 'com.squareup.moshi:moshi:1.5.0' // TODO: move to telemetry
37+
38+
implementation 'com.google.dagger:dagger:2.14.1'
39+
annotationProcessor 'com.google.dagger:dagger-compiler:2.14.1'
40+
41+
compileOnly 'com.google.auto.factory:auto-factory:1.0-beta5'
42+
annotationProcessor 'com.google.auto.factory:auto-factory:1.0-beta5'
43+
44+
compileOnly 'org.jetbrains:annotations:15.0'
45+
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
46+
47+
errorprone 'com.google.errorprone:error_prone_core:2.3.1'
48+
49+
testImplementation 'org.spockframework:spock-core:1.1-groovy-2.4'
50+
testImplementation 'ch.qos.logback:logback-classic:1.2.3'
51+
testRuntime 'net.bytebuddy:byte-buddy:1.7.10'
52+
testRuntime 'org.objenesis:objenesis:2.6'
53+
}
54+
55+
idea {
56+
module {
57+
downloadJavadoc = true
58+
downloadSources = true
59+
}
4860
}
49-
}
5061

51-
idea {
52-
module {
53-
apt {
54-
addGeneratedSourcesDirs = true
55-
addAptDependencies = false
62+
spotless {
63+
java {
64+
googleJavaFormat()
65+
target '**/*.java'
5666
}
5767
}
5868
}
5969

60-
task wrapper(type: Wrapper) {
61-
gradleVersion = '4.2.1'
70+
wrapper {
71+
gradleVersion = '4.9'
6272
}

core/build.gradle

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,3 @@
1-
plugins {
2-
id 'groovy'
3-
id 'maven'
4-
id "com.jfrog.bintray" version "1.8.0"
5-
}
1+
apply from: "${rootDir}/gradle/publish.gradle"
62

7-
apply from: 'javadoc.gradle'
8-
apply from: 'publish.gradle'
9-
10-
project.version = specificationVersion
11-
group = 'org.strykeforce.thirdcoast'
12-
13-
dependencies {
14-
compile wpilib()
15-
compile ctre()
16-
compile navx()
17-
compile libs.toml4j
18-
compile libs.moshi
19-
compile libs.nanohttpd
20-
compile libs.dagger
21-
compile libs.slf4j
22-
compileOnly libs.jetbrainsAnnotations
23-
compileOnly libs.jsr305
24-
compileOnly libs.autoFactory
25-
26-
annotationProcessor libs.daggerCompiler
27-
annotationProcessor libs.autoFactory
28-
29-
testCompile libs.spock
30-
testCompile libs.logback
31-
testRuntime libs.bytebuddy
32-
testRuntime libs.objenesis
33-
}
34-
35-
task sourcesJar(type: Jar, dependsOn: classes) {
36-
classifier = 'sources'
37-
from sourceSets.main.allSource
38-
}
39-
40-
task javadocJar(type: Jar, dependsOn: javadoc) {
41-
classifier = 'javadoc'
42-
from javadoc.destinationDir
43-
}
44-
45-
artifacts {
46-
archives sourcesJar
47-
archives javadocJar
48-
}
49-
50-
idea {
51-
module {
52-
downloadJavadoc = true
53-
downloadSources = true
54-
}
55-
}
3+
sourceCompatibility = 1.8

core/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
projectDescription=Third Coast core library

core/src/main/java/org/strykeforce/thirdcoast/swerve/SwerveDrive.java

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package org.strykeforce.thirdcoast.swerve;
22

3-
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
43
import com.kauailabs.navx.frc.AHRS;
54
import com.moandjiezana.toml.Toml;
65
import edu.wpi.first.wpilibj.Preferences;
7-
import javax.inject.Inject;
8-
import javax.inject.Singleton;
96
import org.slf4j.Logger;
107
import org.slf4j.LoggerFactory;
8+
import org.strykeforce.thirdcoast.talon.Errors;
119
import org.strykeforce.thirdcoast.talon.TalonConfiguration;
12-
import org.strykeforce.thirdcoast.telemetry.TelemetryService;
13-
import org.strykeforce.thirdcoast.telemetry.item.TalonItem;
1410
import org.strykeforce.thirdcoast.util.Settings;
1511

12+
import javax.inject.Inject;
13+
import javax.inject.Singleton;
14+
1615
/**
1716
* Control a Third Coast swerve drive.
1817
*
@@ -33,7 +32,8 @@
3332
public class SwerveDrive {
3433

3534
private static final Logger logger = LoggerFactory.getLogger(SwerveDrive.class);
36-
private static final String TABLE = "THIRDCOAST.SWERVE";
35+
private static final String SWERVE_TABLE = "THIRDCOAST.SWERVE";
36+
private static final String TALONS_TABLE = "THIRDCOAST.TALONS";
3737
private static final int WHEEL_COUNT = 4;
3838
final AHRS gyro;
3939
private final double kLengthComponent;
@@ -49,9 +49,15 @@ public class SwerveDrive {
4949
this.wheels = wheels;
5050
logger.info("field orientation driving is {}", gyro == null ? "DISABLED" : "ENABLED");
5151

52-
Toml toml = settings.getTable(TABLE);
52+
Toml toml = settings.getTable(SWERVE_TABLE);
5353
boolean enableGyroLogging = toml.getBoolean("enableGyroLogging", true);
5454

55+
Toml talonsToml = settings.getTable(TALONS_TABLE);
56+
final boolean summarizeErrors = talonsToml.getBoolean("summarizeErrors", false);
57+
Errors.setSummarized(summarizeErrors);
58+
Errors.setCount(0);
59+
logger.debug("TalonSRX configuration errors summarized = {}", summarizeErrors);
60+
5561
double length = toml.getDouble("length");
5662
double width = toml.getDouble("width");
5763
double radius = Math.hypot(length, width);
@@ -204,32 +210,15 @@ public void saveAzimuthPositions() {
204210
* @see #saveAzimuthPositions()
205211
*/
206212
public void zeroAzimuthEncoders() {
213+
Errors.setCount(0);
207214
Preferences prefs = Preferences.getInstance();
208215
for (int i = 0; i < WHEEL_COUNT; i++) {
209216
int position = prefs.getInt(getPreferenceKeyForWheel(i), 0);
210217
wheels[i].setAzimuthZero(position);
211218
logger.info("azimuth {}: loaded zero = {}", i, position);
212219
}
213-
}
214-
215-
/**
216-
* Register the swerve wheel azimuth and drive {@link com.ctre.phoenix.motorcontrol.can.TalonSRX}
217-
* with the Telemetry service for data collection. The Telemetry service will set the Talon status
218-
* frame update rates to default values during registration.
219-
*
220-
* @param telemetryService the active Telemetry service instance created by the robot
221-
*/
222-
public void registerWith(TelemetryService telemetryService) {
223-
for (int i = 0; i < WHEEL_COUNT; i++) {
224-
TalonSRX t = wheels[i].getAzimuthTalon();
225-
if (t != null)
226-
telemetryService.register(
227-
new TalonItem(t, "Azimuth Talon " + i + " (" + t.getDeviceID() + ")"));
228-
t = wheels[i].getDriveTalon();
229-
if (t != null)
230-
telemetryService.register(
231-
new TalonItem(t, "Drive Talon " + i + " (" + t.getDeviceID() + ")"));
232-
}
220+
int errorCount = Errors.getCount();
221+
if (errorCount > 0) logger.error("TalonSRX set azimuth zero error count = {}", errorCount);
233222
}
234223

235224
/**

core/src/main/java/org/strykeforce/thirdcoast/swerve/Wheel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
public abstract class Wheel {
3434

3535
static final Logger logger = LoggerFactory.getLogger(Wheel.class);
36-
private static final String TABLE = "THIRDCOAST.WHEEL";
36+
private static final String WHEEL_TABLE = "THIRDCOAST.WHEEL";
3737
private static final int TICKS = 4096;
3838
protected final double kDriveSetpointMax;
3939
protected final TalonSRX driveTalon;
@@ -50,7 +50,7 @@ public abstract class Wheel {
5050
*/
5151
public Wheel(Settings settings, TalonSRX azimuth, TalonSRX drive) {
5252

53-
Toml toml = settings.getTable(TABLE);
53+
Toml toml = settings.getTable(WHEEL_TABLE);
5454
kDriveSetpointMax = (double) toml.getLong("driveSetpointMax");
5555

5656
azimuthTalon = azimuth;

core/src/main/java/org/strykeforce/thirdcoast/talon/Errors.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,36 @@
77
/** Utility class to check for and display TalonSRX configuration errors. */
88
public class Errors {
99

10+
private static boolean summarized = true;
11+
private static int count;
12+
1013
public static void check(ErrorCode error, Logger logger) {
1114
if (error != null && error != ErrorCode.OK) {
12-
logger.error("error while configuring Talon: {}", error);
15+
if (summarized) count++;
16+
else logger.error("error while configuring Talon: {}", error);
1317
}
1418
}
1519

1620
public static void check(TalonSRX talon, String method, ErrorCode error, Logger logger) {
1721
if (error != null && error != ErrorCode.OK) {
18-
logger.error("Talon {}: {} error {}", talon.getDeviceID(), method, error);
22+
if (summarized) count++;
23+
else logger.error("Talon {}: {} error {}", talon.getDeviceID(), method, error);
1924
}
2025
}
26+
27+
public static boolean isSummarized() {
28+
return summarized;
29+
}
30+
31+
public static void setSummarized(boolean summarized) {
32+
Errors.summarized = summarized;
33+
}
34+
35+
public static int getCount() {
36+
return count;
37+
}
38+
39+
public static void setCount(int count) {
40+
Errors.count = count;
41+
}
2142
}

core/src/main/java/org/strykeforce/thirdcoast/talon/Talons.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
import com.ctre.phoenix.motorcontrol.StatusFrameEnhanced;
77
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
88
import com.moandjiezana.toml.Toml;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
import org.strykeforce.thirdcoast.util.Settings;
12+
13+
import javax.annotation.ParametersAreNonnullByDefault;
14+
import javax.inject.Inject;
15+
import javax.inject.Singleton;
916
import java.util.ArrayList;
1017
import java.util.HashMap;
1118
import java.util.List;
1219
import java.util.Map;
1320
import java.util.stream.Collectors;
14-
import javax.annotation.ParametersAreNonnullByDefault;
15-
import javax.inject.Inject;
16-
import javax.inject.Singleton;
17-
import org.slf4j.Logger;
18-
import org.slf4j.LoggerFactory;
19-
import org.strykeforce.thirdcoast.util.Settings;
2021

2122
/** Instantiate {@link TalonSRX} instances with defaults. */
2223
@Singleton
@@ -36,6 +37,10 @@ public Talons(Settings settings, Factory factory) {
3637
final int timeout = settingsTable.getLong("timeout").intValue();
3738
logger.debug("TalonSRX configuration timeout = {}", timeout);
3839

40+
final boolean summarizeErrors = settingsTable.getBoolean("summarizeErrors", false);
41+
Errors.setSummarized(summarizeErrors);
42+
logger.debug("TalonSRX configuration errors summarized = {}", summarizeErrors);
43+
3944
List<TalonConfiguration> talonConfigurations = new ArrayList<>();
4045
List<Toml> talonConfigTables = settings.getTables(TALONS);
4146
if (talonConfigTables.size() == 0) logger.warn("no TalonSRX configurations available");
@@ -51,6 +56,7 @@ public Talons(Settings settings, Factory factory) {
5156
logger.debug("added '{}' for TalonSRX ids: {}", config.getName(), config.getTalonIds());
5257
}
5358

59+
Errors.setCount(0);
5460
for (TalonConfiguration config : talonConfigurations) {
5561
for (Integer id : config.getTalonIds()) {
5662
if (talons.containsKey(id)) {
@@ -62,6 +68,8 @@ public Talons(Settings settings, Factory factory) {
6268
talons.put(id, talon);
6369
}
6470
}
71+
int errorCount = Errors.getCount();
72+
if (errorCount > 0) logger.error("TalonSRX configuration error count = {}", errorCount);
6573
}
6674

6775
@SuppressWarnings("unused")

core/src/main/resources/META-INF/thirdcoast/defaults.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818

1919
[THIRDCOAST.TALONS]
2020
timeout = 10
21+
summarizeErrors = false

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
githubUrl=https://github.com/strykeforce/thirdcoast

0 commit comments

Comments
 (0)