Skip to content
This repository was archived by the owner on Sep 14, 2019. It is now read-only.

Commit 0ce8802

Browse files
caengineerscaengineers
authored andcommitted
Finish writing AutoMoveTo, change RunScript to use PID commands instead
of AutoMove and AutoTurn
1 parent 619bf9b commit 0ce8802

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

Robot2018/src/org/usfirst/frc/team199/Robot2018/autonomous/AutoUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private static void logWarning (int lineNumber, String message) {
211211
* @param s the argument
212212
* @return if the argument is a point
213213
*/
214-
private static boolean isPoint (String s) {
214+
public static boolean isPoint (String s) {
215215
// checks if it starts and ends with parentheses
216216
if (!s.startsWith("(") || !s.endsWith(")"))
217217
return false;

Robot2018/src/org/usfirst/frc/team199/Robot2018/commands/AutoMoveTo.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.usfirst.frc.team199.Robot2018.commands;
22

3+
import org.usfirst.frc.team199.Robot2018.Robot;
34
import org.usfirst.frc.team199.Robot2018.autonomous.AutoUtils;
5+
import org.usfirst.frc.team199.Robot2018.autonomous.PIDSourceAverage;
46

57
//import org.usfirst.frc.team199.Robot2018.subsystems.Drivetrain;
68

@@ -15,9 +17,25 @@ public AutoMoveTo(String[] args) {
1517
//requires(Drivetrain);
1618
double rotation;
1719
double[] point;
20+
String parentheseless;
21+
String[] pointparts;
1822
for (String arg : args) {
1923
if (AutoUtils.isDouble(arg)) {
2024
rotation = Double.valueOf(arg);
25+
addSequential(new PIDTurn(rotation - AutoUtils.getRot(), Robot.dt, Robot.dt.getGyro()));
26+
AutoUtils.setRot(rotation);
27+
} else if (AutoUtils.isPoint(arg)) {
28+
parentheseless = arg.substring(1, arg.length() - 1);
29+
pointparts = parentheseless.split(",");
30+
point[0] = Double.parseDouble(pointparts[0]);
31+
point[1] = Double.parseDouble(pointparts[1]);
32+
addSequential(new PIDTurn(Math.toDegrees(Math.atan((point[0] - AutoUtils.getX())/(point[1] - AutoUtils.getY())) - AutoUtils.getRot()), Robot.dt, Robot.dt.getGyro()));
33+
addSequential(new PIDMove(Math.sqrt(((point[0] - AutoUtils.getX()) * (point[0] - AutoUtils.getX()) + ((point[1] - AutoUtils.getY()) * (point[1] - AutoUtils.getY())))), Robot.dt, new PIDSourceAverage(null, null)));
34+
AutoUtils.setX(point[0]);
35+
AutoUtils.setY(point[1]);
36+
AutoUtils.setRot(Math.toDegrees(Math.atan((point[0] - AutoUtils.getX())/(point[1] - AutoUtils.getY()))));
37+
} else {
38+
throw new IllegalArgumentException();
2139
}
2240
}
2341

Robot2018/src/org/usfirst/frc/team199/Robot2018/commands/RunScript.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44

55
import org.usfirst.frc.team199.Robot2018.Robot;
6+
import org.usfirst.frc.team199.Robot2018.autonomous.PIDSourceAverage;
67

78
import edu.wpi.first.wpilibj.command.CommandGroup;
89
import edu.wpi.first.wpilibj.command.WaitCommand;
@@ -25,10 +26,10 @@ public RunScript(String scriptName) {
2526
addSequential(new AutoMoveTo(cmdArgs.split(" ")));
2627
break;
2728
case "turn":
28-
addSequential(new AutoTurn(Double.parseDouble(cmdArgs)));
29+
addSequential(new PIDTurn(Double.parseDouble(cmdArgs), Robot.dt, Robot.dt.getGyro()));
2930
break;
3031
case "move":
31-
addSequential(new AutoMove(Double.parseDouble(cmdArgs)));
32+
addSequential(new PIDMove(Double.parseDouble(cmdArgs), Robot.dt, new PIDSourceAverage(null, null))));
3233
break;
3334
case "switch":
3435
addSequential(new EjectToSwitch());

0 commit comments

Comments
 (0)