From: Logan Howard Date: Sat, 18 Apr 2015 05:02:00 +0000 (-0700) Subject: rearrange a few more files. realize that adding the auton read from file thing was... X-Git-Url: http://challenge-bot.com/repos/?p=ozzloy%40gmail.com%2F3501-spark-go;a=commitdiff_plain;h=f139e3132139b3c27c10334c94aef9a6b8478767 rearrange a few more files. realize that adding the auton read from file thing was stupid, will replace later --- diff --git a/src/org/usfirst/frc/team3501/bases/CommandBase.java b/src/org/usfirst/frc/team3501/bases/CommandBase.java index d797ce6..770f48d 100644 --- a/src/org/usfirst/frc/team3501/bases/CommandBase.java +++ b/src/org/usfirst/frc/team3501/bases/CommandBase.java @@ -1,9 +1,9 @@ package org.usfirst.frc.team3501.bases; -import org.usfirst.frc.team3501.robot.AutonData; import org.usfirst.frc.team3501.robot.OI; import org.usfirst.frc.team3501.robot.Robot; import org.usfirst.frc.team3501.robot.subsystems.*; +import org.usfirst.frc.team3501.util.AutonData; public interface CommandBase { diff --git a/src/org/usfirst/frc/team3501/robot/AutonData.java b/src/org/usfirst/frc/team3501/robot/AutonData.java deleted file mode 100644 index a643b06..0000000 --- a/src/org/usfirst/frc/team3501/robot/AutonData.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.usfirst.frc.team3501.robot; - -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; - } -} diff --git a/src/org/usfirst/frc/team3501/robot/Robot.java b/src/org/usfirst/frc/team3501/robot/Robot.java index 532d254..c7ef783 100644 --- a/src/org/usfirst/frc/team3501/robot/Robot.java +++ b/src/org/usfirst/frc/team3501/robot/Robot.java @@ -11,6 +11,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import org.usfirst.frc.team3501.robot.autons.*; import org.usfirst.frc.team3501.robot.commands.*; import org.usfirst.frc.team3501.robot.subsystems.*; +import org.usfirst.frc.team3501.util.AutonData; public class Robot extends IterativeRobot { diff --git a/src/org/usfirst/frc/team3501/robot/autons/ContainerOverStep.java b/src/org/usfirst/frc/team3501/robot/autons/ContainerOverStep.java index 75e592b..35019a1 100644 --- a/src/org/usfirst/frc/team3501/robot/autons/ContainerOverStep.java +++ b/src/org/usfirst/frc/team3501/robot/autons/ContainerOverStep.java @@ -1,17 +1,15 @@ package org.usfirst.frc.team3501.robot.autons; -import org.usfirst.frc.team3501.robot.Robot; - -import edu.wpi.first.wpilibj.command.CommandGroup; +import org.usfirst.frc.team3501.bases.CommandGroup; public class ContainerOverStep extends CommandGroup { public ContainerOverStep() { super("ContainerOverStep"); - requires(Robot.drivetrain); - requires(Robot.arm); - requires(Robot.claw); + requires(drivetrain); + requires(arm); + requires(claw); queueCommands(); } diff --git a/src/org/usfirst/frc/team3501/robot/autons/PickUpContainer.java b/src/org/usfirst/frc/team3501/robot/autons/PickUpContainer.java index 3f4b4aa..87d82bc 100644 --- a/src/org/usfirst/frc/team3501/robot/autons/PickUpContainer.java +++ b/src/org/usfirst/frc/team3501/robot/autons/PickUpContainer.java @@ -1,7 +1,6 @@ package org.usfirst.frc.team3501.robot.autons; import org.usfirst.frc.team3501.bases.CommandGroup; -import org.usfirst.frc.team3501.robot.Robot; import org.usfirst.frc.team3501.robot.commands.*; public class PickUpContainer extends CommandGroup { @@ -9,8 +8,8 @@ public class PickUpContainer extends CommandGroup { public PickUpContainer() { super("PickUpContainer"); - requires(Robot.arm); - requires(Robot.claw); + requires(arm); + requires(claw); queueCommands(); } @@ -18,7 +17,7 @@ public class PickUpContainer extends CommandGroup { private void queueCommands() { addSequential(new CloseClaw()); addSequential(new MoveArmFor( - Robot.autonData.getTime("pickup_container"), - Robot.autonData.getSpeed("pickup_container"))); + autonData.getTime("pickup_container"), + autonData.getSpeed("pickup_container"))); } } 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; + } +}