frcconf Example
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
package com.swervedrivespecialties.exampleswerve.config; | |
import edu.wpi.first.networktables.PersistentException; | |
public class ConfigLoader { | |
private RobotMap robotMapInstance; | |
public RobotMap loadRobotMap() throws PersistentException { | |
if (robotMapInstance == null) { | |
robotMapInstance = new ConfiguredRobotMap("/Map", "/home/lvuser/deploy/map.ini"); | |
} | |
return robotMapInstance; | |
} | |
} |
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
package com.swervedrivespecialties.exampleswerve.config; | |
import edu.wpi.first.networktables.NetworkTableInstance; | |
import edu.wpi.first.networktables.PersistentException; | |
import java.lang.String; | |
public class ConfiguredRobotMap extends RobotMap { | |
String root; | |
String file; | |
public ConfiguredRobotMap(String root, String file) throws PersistentException { | |
this.root = root; | |
this.file = file; | |
putDefault(); | |
NetworkTableInstance.getDefault().loadEntries(file, root); | |
setupNT(); | |
NetworkTableInstance.getDefault().saveEntries(file, root); | |
} | |
private void setupNT() { | |
NetworkTableInstance inst = NetworkTableInstance.getDefault(); | |
inst.addEntryListener(inst.getEntry(String.format("%s/FRONT_LEFT/ANGLE_MOTOR", root)), entry -> this.FRONT_LEFT.ANGLE_MOTOR = ((Double) entry.value.getValue()).intValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/FRONT_LEFT/ANGLE_ENCODER", root)), entry -> this.FRONT_LEFT.ANGLE_ENCODER = ((Double) entry.value.getValue()).intValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/FRONT_LEFT/DRIVE_MOTOR", root)), entry -> this.FRONT_LEFT.DRIVE_MOTOR = ((Double) entry.value.getValue()).intValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/FRONT_LEFT/DRIVE_INVERT", root)), entry -> this.FRONT_LEFT.DRIVE_INVERT = ((Boolean) entry.value.getValue()).booleanValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/FRONT_RIGHT/ANGLE_MOTOR", root)), entry -> this.FRONT_RIGHT.ANGLE_MOTOR = ((Double) entry.value.getValue()).intValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/FRONT_RIGHT/ANGLE_ENCODER", root)), entry -> this.FRONT_RIGHT.ANGLE_ENCODER = ((Double) entry.value.getValue()).intValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/FRONT_RIGHT/DRIVE_MOTOR", root)), entry -> this.FRONT_RIGHT.DRIVE_MOTOR = ((Double) entry.value.getValue()).intValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/FRONT_RIGHT/DRIVE_INVERT", root)), entry -> this.FRONT_RIGHT.DRIVE_INVERT = ((Boolean) entry.value.getValue()).booleanValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/BACK_LEFT/ANGLE_MOTOR", root)), entry -> this.BACK_LEFT.ANGLE_MOTOR = ((Double) entry.value.getValue()).intValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/BACK_LEFT/ANGLE_ENCODER", root)), entry -> this.BACK_LEFT.ANGLE_ENCODER = ((Double) entry.value.getValue()).intValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/BACK_LEFT/DRIVE_MOTOR", root)), entry -> this.BACK_LEFT.DRIVE_MOTOR = ((Double) entry.value.getValue()).intValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/BACK_LEFT/DRIVE_INVERT", root)), entry -> this.BACK_LEFT.DRIVE_INVERT = ((Boolean) entry.value.getValue()).booleanValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/BACK_RIGHT/ANGLE_MOTOR", root)), entry -> this.BACK_RIGHT.ANGLE_MOTOR = ((Double) entry.value.getValue()).intValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/BACK_RIGHT/ANGLE_ENCODER", root)), entry -> this.BACK_RIGHT.ANGLE_ENCODER = ((Double) entry.value.getValue()).intValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/BACK_RIGHT/DRIVE_MOTOR", root)), entry -> this.BACK_RIGHT.DRIVE_MOTOR = ((Double) entry.value.getValue()).intValue(), 5); | |
inst.addEntryListener(inst.getEntry(String.format("%s/BACK_RIGHT/DRIVE_INVERT", root)), entry -> this.BACK_RIGHT.DRIVE_INVERT = ((Boolean) entry.value.getValue()).booleanValue(), 5); | |
} | |
private void putDefault() { | |
NetworkTableInstance inst = NetworkTableInstance.getDefault(); | |
inst.getEntry(String.format("%s/FRONT_LEFT/ANGLE_MOTOR", root)).forceSetValue(this.FRONT_LEFT.ANGLE_MOTOR); | |
inst.getEntry(String.format("%s/FRONT_LEFT/ANGLE_ENCODER", root)).forceSetValue(this.FRONT_LEFT.ANGLE_ENCODER); | |
inst.getEntry(String.format("%s/FRONT_LEFT/DRIVE_MOTOR", root)).forceSetValue(this.FRONT_LEFT.DRIVE_MOTOR); | |
inst.getEntry(String.format("%s/FRONT_LEFT/DRIVE_INVERT", root)).forceSetValue(this.FRONT_LEFT.DRIVE_INVERT); | |
inst.getEntry(String.format("%s/FRONT_RIGHT/ANGLE_MOTOR", root)).forceSetValue(this.FRONT_RIGHT.ANGLE_MOTOR); | |
inst.getEntry(String.format("%s/FRONT_RIGHT/ANGLE_ENCODER", root)).forceSetValue(this.FRONT_RIGHT.ANGLE_ENCODER); | |
inst.getEntry(String.format("%s/FRONT_RIGHT/DRIVE_MOTOR", root)).forceSetValue(this.FRONT_RIGHT.DRIVE_MOTOR); | |
inst.getEntry(String.format("%s/FRONT_RIGHT/DRIVE_INVERT", root)).forceSetValue(this.FRONT_RIGHT.DRIVE_INVERT); | |
inst.getEntry(String.format("%s/BACK_LEFT/ANGLE_MOTOR", root)).forceSetValue(this.BACK_LEFT.ANGLE_MOTOR); | |
inst.getEntry(String.format("%s/BACK_LEFT/ANGLE_ENCODER", root)).forceSetValue(this.BACK_LEFT.ANGLE_ENCODER); | |
inst.getEntry(String.format("%s/BACK_LEFT/DRIVE_MOTOR", root)).forceSetValue(this.BACK_LEFT.DRIVE_MOTOR); | |
inst.getEntry(String.format("%s/BACK_LEFT/DRIVE_INVERT", root)).forceSetValue(this.BACK_LEFT.DRIVE_INVERT); | |
inst.getEntry(String.format("%s/BACK_RIGHT/ANGLE_MOTOR", root)).forceSetValue(this.BACK_RIGHT.ANGLE_MOTOR); | |
inst.getEntry(String.format("%s/BACK_RIGHT/ANGLE_ENCODER", root)).forceSetValue(this.BACK_RIGHT.ANGLE_ENCODER); | |
inst.getEntry(String.format("%s/BACK_RIGHT/DRIVE_MOTOR", root)).forceSetValue(this.BACK_RIGHT.DRIVE_MOTOR); | |
inst.getEntry(String.format("%s/BACK_RIGHT/DRIVE_INVERT", root)).forceSetValue(this.BACK_RIGHT.DRIVE_INVERT); | |
} | |
} |
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
package com.swervedrivespecialties.exampleswerve.config; | |
import frcconf.Configurable; | |
@Configurable | |
public class RobotMap { | |
public SwerveModuleMap FRONT_LEFT = new SwerveModuleMap(); | |
public SwerveModuleMap FRONT_RIGHT = new SwerveModuleMap(); | |
public SwerveModuleMap BACK_LEFT = new SwerveModuleMap(); | |
public SwerveModuleMap BACK_RIGHT = new SwerveModuleMap(); | |
public static class SwerveModuleMap { | |
public int ANGLE_MOTOR; | |
public int ANGLE_ENCODER; | |
public int DRIVE_MOTOR; | |
public boolean DRIVE_INVERT; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment