--- /dev/null
+# format is: `speed time name`. speed can be negative for reverse motion.
+0.7 1.2 drive_over_step
+0.5 1.5 drive_past_step
+0.5 1.4 pickup_container
--- /dev/null
+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<String, Double> speeds;
+ HashMap<String, Double> times;
+
+ public AutonData() {
+ speeds = new HashMap<String, Double>();
+ times = new HashMap<String, Double>();
+
+ 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;
+ }
+}
public static OI oi;
- private SendableChooser autoChooser;
+ public static AutonData autonData;
+ private SendableChooser autonChooser;
private Command autonomousCommand;
public void robotInit() {
pneumatics = new Pneumatics();
+ autonData = new AutonData();
+
chooseAuto();
}
public void autonomousInit() {
schedule(new TurnOnCompressor());
- autonomousCommand = (Command) autoChooser.getSelected();
+ autonData.update();
+
+ autonomousCommand = (Command) autonChooser.getSelected();
autonomousCommand.start();
}
}
private void chooseAuto() {
- autoChooser = new SendableChooser();
+ autonChooser = new SendableChooser();
- autoChooser.addDefault("Pick up container", new ContainerOverStep());
- autoChooser.addObject("Drive over step", new DriveOverStep());
- autoChooser.addObject("Drive past step", new DrivePastStep());
+ autonChooser.addDefault("Pick up container", new ContainerOverStep());
+ autonChooser.addObject("Drive over step", new DriveOverStep());
+ autonChooser.addObject("Drive past step", new DrivePastStep());
- SmartDashboard.putData("Auto Mode", autoChooser);
+ SmartDashboard.putData("Auto Mode", autonChooser);
}
private void schedule(Command c) {
public static final int CLAW_FORWARD_CHANNEL = 0, CLAW_REVERSE_CHANNEL = 1;
public static final Value OPEN = Value.kForward, CLOSED = Value.kReverse;
-
- // auton
- public static final double OVER_STEP_TIME = 1.2, OVER_STEP_SPEED = 0.7,
- PAST_STEP_TIME = 1.5, PAST_STEP_SPEED = 0.5,
- PICKUP_TIME = 1.4, PICKUP_SPEED = 0.5;
}
package org.usfirst.frc.team3501.robot.autons;
-import org.usfirst.frc.team3501.robot.RobotMap;
-import org.usfirst.frc.team3501.robot.commands.CommandBase;
+import org.usfirst.frc.team3501.robot.commands.Command;
-public class DriveOverStep extends CommandBase {
+public class DriveOverStep extends Command {
private double speed;
super("DriveOverStep");
requires(drivetrain);
- setTimeout(RobotMap.OVER_STEP_TIME);
- speed = RobotMap.OVER_STEP_SPEED;
+ setTimeout(autonData.getTime("drive_over_step"));
+ speed = autonData.getSpeed("drive_over_step");
}
// TODO: this is an ugly "solution"
package org.usfirst.frc.team3501.robot.autons;
-import org.usfirst.frc.team3501.robot.RobotMap;
-import org.usfirst.frc.team3501.robot.commands.CommandBase;
+import org.usfirst.frc.team3501.robot.commands.Command;
-public class DrivePastStep extends CommandBase {
+public class DrivePastStep extends Command {
private double speed;
super("DrivePastStep");
requires(drivetrain);
- setTimeout(RobotMap.PAST_STEP_TIME);
- this.speed = RobotMap.PAST_STEP_SPEED;
+ setTimeout(autonData.getTime("drive_past_step"));
+ speed = autonData.getSpeed("drive_past_step");
}
protected void execute() {
package org.usfirst.frc.team3501.robot.autons;
import org.usfirst.frc.team3501.robot.Robot;
-import org.usfirst.frc.team3501.robot.RobotMap;
import org.usfirst.frc.team3501.robot.commands.*;
-import edu.wpi.first.wpilibj.command.CommandGroup;
-
public class PickUpContainer extends CommandGroup {
public PickUpContainer() {
private void queueCommands() {
addSequential(new CloseClaw());
- addSequential(new MoveArmFor(RobotMap.PICKUP_TIME, RobotMap.PICKUP_SPEED));
+ addSequential(new MoveArmFor(
+ Robot.autonData.getTime("pickup_container"),
+ Robot.autonData.getSpeed("pickup_container")));
}
}
package org.usfirst.frc.team3501.robot.commands;
-public class CloseClaw extends CommandBase {
+public class CloseClaw extends Command {
public CloseClaw() {
super("CloseClaw");
--- /dev/null
+package org.usfirst.frc.team3501.robot.commands;
+
+import edu.wpi.first.wpilibj.command.Scheduler;
+
+public abstract class Command
+ extends edu.wpi.first.wpilibj.command.Command
+ implements CommandBase {
+
+ public Command(String commandName) {
+ super(commandName);
+ }
+
+ protected void schedule(Command c) {
+ Scheduler.getInstance().add(c);
+ }
+
+ protected void initialize() {}
+
+ protected void execute() {}
+
+ protected void end() {}
+
+ protected void interrupted() {}
+}
package org.usfirst.frc.team3501.robot.commands;
+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 edu.wpi.first.wpilibj.command.Command;
-import edu.wpi.first.wpilibj.command.Scheduler;
+public interface CommandBase {
-public abstract class CommandBase extends Command {
+ final static OI oi = Robot.oi;
- protected static OI oi;
+ final static AutonData autonData = Robot.autonData;
- protected static Drivetrain drivetrain;
- protected static Arm arm;
- protected static Claw claw;
+ final static Drivetrain drivetrain = Robot.drivetrain;
+ final static Arm arm = Robot.arm;
+ final static Claw claw = Robot.claw;
- protected static Pneumatics pneumatics;
-
- public CommandBase(String commandName) {
- super(commandName);
-
- oi = Robot.oi;
-
- drivetrain = Robot.drivetrain;
- arm = Robot.arm;
- claw = Robot.claw;
-
- pneumatics = Robot.pneumatics;
- }
-
- protected void schedule(Command c) {
- Scheduler.getInstance().add(c);
- }
-
- protected void initialize() {}
-
- protected void execute() {}
-
- protected void end() {}
-
- protected void interrupted() {}
+ final static Pneumatics pneumatics = Robot.pneumatics;
}
--- /dev/null
+package org.usfirst.frc.team3501.robot.commands;
+
+public class CommandGroup
+ extends edu.wpi.first.wpilibj.command.CommandGroup
+ implements CommandBase {
+
+ public CommandGroup(String commandGroupName) {
+ super(commandGroupName);
+ }
+}
package org.usfirst.frc.team3501.robot.commands;
-public class DriveFor extends CommandBase {
+public class DriveFor extends Command {
private double speed;
package org.usfirst.frc.team3501.robot.commands;
-public class DriveWithJoysticks extends CommandBase {
+public class DriveWithJoysticks extends Command {
public DriveWithJoysticks() {
super("DriveWithJoysticks");
package org.usfirst.frc.team3501.robot.commands;
-public class MoveArm extends CommandBase {
+public class MoveArm extends Command {
public MoveArm() {
super("MoveArm");
package org.usfirst.frc.team3501.robot.commands;
-public class MoveArmFor extends CommandBase {
+public class MoveArmFor extends Command {
private double speed;
package org.usfirst.frc.team3501.robot.commands;
-public class OpenClaw extends CommandBase {
+public class OpenClaw extends Command {
public OpenClaw() {
super("OpenClaw");
package org.usfirst.frc.team3501.robot.commands;
-public class TensionLeftWinch extends CommandBase {
+public class TensionLeftWinch extends Command {
private double speed;
package org.usfirst.frc.team3501.robot.commands;
-public class TensionRightWinch extends CommandBase {
+public class TensionRightWinch extends Command {
private double speed;
package org.usfirst.frc.team3501.robot.commands;
-public class ToggleClaw extends CommandBase {
+public class ToggleClaw extends Command {
public ToggleClaw() {
super("ToggleClaw");
package org.usfirst.frc.team3501.robot.commands;
-public class TurnOffCompressor extends CommandBase {
+public class TurnOffCompressor extends Command {
public TurnOffCompressor() {
super("TurnOffCompressor");
package org.usfirst.frc.team3501.robot.commands;
-public class TurnOnCompressor extends CommandBase {
+public class TurnOnCompressor extends Command {
public TurnOnCompressor() {
super("TurnOnCompressor");