X-Git-Url: http://challenge-bot.com/repos/?a=blobdiff_plain;f=src%2Forg%2Fusfirst%2Ffrc%2Fteam3501%2Futil%2FAutonData.java;fp=src%2Forg%2Fusfirst%2Ffrc%2Fteam3501%2Futil%2FAutonData.java;h=df9164536d559f84f84f29f5e86515a656ce20c1;hb=f139e3132139b3c27c10334c94aef9a6b8478767;hp=0000000000000000000000000000000000000000;hpb=5b3b1652e197b540e14b8f5b405314b6f33d733c;p=3501%2F3501-spark-go diff --git a/src/org/usfirst/frc/team3501/util/AutonData.java b/src/org/usfirst/frc/team3501/util/AutonData.java new file mode 100644 index 0000000..df91645 --- /dev/null +++ b/src/org/usfirst/frc/team3501/util/AutonData.java @@ -0,0 +1,98 @@ +package org.usfirst.frc.team3501.util; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; + +public class AutonData { + + HashMap speeds; + HashMap times; + + public AutonData() { + speeds = new HashMap(); + times = new HashMap(); + + populate(); + } + + public double getSpeed(String key) { + Double ret = speeds.get(key); + + return (ret != null) ? ret : 0; + } + + public double getTime(String key) { + Double ret = times.get(key); + + return (ret != null) ? ret : 0; + } + + public void update() { + speeds.clear(); + times.clear(); + + populate(); + } + + private void populate() { + String file; + + try { + file = readConfigFile(); + } catch (IOException e) { + e.printStackTrace(); + populateDefaults(); + return; + } + + try { + Arrays.stream(file.split("\n")) + .map(line -> line.split(" ")) + .forEach((action) -> { + double speed = Double.parseDouble(action[0]); + double time = Double.parseDouble(action[1]); + String name = action[2]; + + speeds.put(name, speed); + times.put(name, time); + }); + } catch (Exception e) { + e.printStackTrace(); + populateDefaults(); + } + } + + private void populateDefaults() { + speeds.clear(); + times.clear(); + + speeds.put("drive_over_step", 0.7); + speeds.put("drive_past_step", 0.5); + speeds.put("pickup_container", 0.5); + + times.put("drive_over_step", 1.2); + times.put("drive_past_step", 1.5); + times.put("pickup_container", 1.4); + } + + private String readConfigFile() throws IOException { + BufferedReader in = new BufferedReader(new FileReader( + "auton_times_and_speeds.conf")); + + StringBuilder sb = new StringBuilder(); + + in.readLine(); // get rid of first line + + String curLine; + while ((curLine = in.readLine()) != null) + sb.append(curLine + "\n"); + String finalString = sb.toString(); + + in.close(); + + return finalString; + } +}