df9164536d559f84f84f29f5e86515a656ce20c1
1 package org
.usfirst
.frc
.team3501
.util
;
3 import java
.io
.BufferedReader
;
4 import java
.io
.FileReader
;
5 import java
.io
.IOException
;
6 import java
.util
.Arrays
;
7 import java
.util
.HashMap
;
9 public class AutonData
{
11 HashMap
<String
, Double
> speeds
;
12 HashMap
<String
, Double
> times
;
15 speeds
= new HashMap
<String
, Double
>();
16 times
= new HashMap
<String
, Double
>();
21 public double getSpeed(String key
) {
22 Double ret
= speeds
.get(key
);
24 return (ret
!= null) ? ret
: 0;
27 public double getTime(String key
) {
28 Double ret
= times
.get(key
);
30 return (ret
!= null) ? ret
: 0;
33 public void update() {
40 private void populate() {
44 file
= readConfigFile();
45 } catch (IOException e
) {
52 Arrays
.stream(file
.split("\n"))
53 .map(line
-> line
.split(" "))
54 .forEach((action
) -> {
55 double speed
= Double
.parseDouble(action
[0]);
56 double time
= Double
.parseDouble(action
[1]);
57 String name
= action
[2];
59 speeds
.put(name
, speed
);
60 times
.put(name
, time
);
62 } catch (Exception e
) {
68 private void populateDefaults() {
72 speeds
.put("drive_over_step", 0.7);
73 speeds
.put("drive_past_step", 0.5);
74 speeds
.put("pickup_container", 0.5);
76 times
.put("drive_over_step", 1.2);
77 times
.put("drive_past_step", 1.5);
78 times
.put("pickup_container", 1.4);
81 private String
readConfigFile() throws IOException
{
82 BufferedReader in
= new BufferedReader(new FileReader(
83 "auton_times_and_speeds.conf"));
85 StringBuilder sb
= new StringBuilder();
87 in
.readLine(); // get rid of first line
90 while ((curLine
= in
.readLine()) != null)
91 sb
.append(curLine
+ "\n");
92 String finalString
= sb
.toString();