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

Commit 64b5912

Browse files
authored
Auto testing (#82)
* address issues #44 and 45 change problems in script parsing from warning to error and allow coordinate points with spaces between * use replaceAll instead of for loop * modify changing and getting AutoUtils values PIDTurn and PIDMove can now move to an absolute value and they also update the position and angle based on encoder and gyro values instead of the assumed values * add documentation * use absolute values in AutoMoveTo * modify RunScript to use absolute values * fix what alex fixed in his code * modify atan to atan2 * modify atan2 to pass in the right values * initial ds computer changes (#1) * added more functionality to intakeEject * add requires to default intake command * add end and interrupted to defaultIntake * changes to make intake work * start testing auto * use sd interface instead of sd in PIDMove and PIDTurn * testing auto changes relative vs absolute = problems moved math in PIDMove and PIDTurn to initialize instead of in the constructor added try catch for manipulator in DefaultIntake command (Daniel P, Kevin W, Laura M, Dean B) * fixed PIDMove and other tiny random things PIDMove was calculating as if numbers were normal angles when in fact they are bearings so we switched x and y * fix AutoMoveTo test
1 parent bff95a8 commit 64b5912

File tree

21 files changed

+553
-189
lines changed

21 files changed

+553
-189
lines changed

AAAScripts/scripts.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ RxLx:
3636
#-------------------------------------------------
3737

3838
#Exchange
39-
RxxE
39+
RxxE:
4040
moveto (0, 188.4) (-210.6, 188.4) (-210.6, 44.4) (-123.6, 44.4) (-123.6, -39.6) 180 #Curve around switch for baseline #then go to exchange
4141
exchange
4242

@@ -144,7 +144,7 @@ LxRx:
144144
#-------------------------------------------------
145145

146146
#Exchange
147-
LxxE
147+
LxxE:
148148
moveto (0, 188.4) (210.6, 188.4) (210.6, 3.7) (124.8, 3.7) (124.8, -3.3) 180 #Curve around switch for baseline then go to exchange
149149
exchange
150150

@@ -244,13 +244,13 @@ moveto (48,80.375) #cross baseline
244244
CRxx:
245245
moveto (0,60) 90 #5 feet forward, turn 90
246246
moveto (48,60) -90 #4 feet right,turn -90
247-
moveto(48,104.375) #7 feet forward until against switch enclosure, compensating for robot length
247+
moveto (48,104.375) #7 feet forward until against switch enclosure, compensating for robot length
248248
switch #deploy switch
249249

250250
CLxx:
251251
moveto (0,60) -90 #5 feet forward, turn -90
252252
moveto (-48,60) 90 #4 feet left,turn 90
253-
moveto(-48,104.375) #7 feet forward until against switch enclosure,compensating for robot length
253+
moveto (-48,104.375) #7 feet forward until against switch enclosure,compensating for robot length
254254
switch #deploy switch
255255

256256

@@ -275,7 +275,7 @@ scale #deploy scale
275275
CRLx:
276276
moveto (0,60) 90 #5 feet forward, turn 90
277277
moveto (48,60) -90 #4 feet right,turn -90
278-
moveto(48,104.375) #7 feet forward until against switch enclosure
278+
moveto (48,104.375) #7 feet forward until against switch enclosure
279279
switch #deploy switch
280280
move -39 #move 39 inches back
281281
turn -90 #turn -90 degrees
@@ -294,7 +294,7 @@ scale #deploy scale2
294294
CRRx:
295295
moveto (0,60) 90 #5 feet forward, turn 90
296296
moveto (48,60) -90 #4 feet right,turn -90
297-
moveto(48,104.375) #7 feet forward until against switch enclosure
297+
moveto (48,104.375) #7 feet forward until against switch enclosure
298298
switch #deploy switch
299299
move -39 #move 39 inches back
300300
turn -90 #turn -90 degrees
@@ -313,7 +313,7 @@ scale #deploy scale
313313
CLRx:
314314
moveto (0,60) -90 #5 feet forward, turn -90
315315
moveto (-48,60) 90 #4 feet left,turn 90
316-
moveto(-48,104.375) #7 feet forward until against switch enclosure
316+
moveto (-48,104.375) #7 feet forward until against switch enclosure
317317
switch #deploy switch
318318
move -39 #move 39 inches back
319319
turn -90 #turn -90 degrees
@@ -331,7 +331,7 @@ scale #deploy scale
331331
CLLx:
332332
moveto (0,60) -90 #5 feet forward, turn -90
333333
moveto (-48,60) 90 #4 feet left,turn 90
334-
moveto(-48,104.375) #7 feet forward until against switch enclosure
334+
moveto (-48,104.375) #7 feet forward until against switch enclosure
335335
switch #deploy switch
336336
move -39 #move 39 inches back
337337
turn 90 #turn 90 degrees
@@ -352,7 +352,7 @@ scale #deploy scale2
352352
CRxE:
353353
moveto (0,60) 90 #5 feet forward, turn 90
354354
moveto (48,60) -90 #4 feet right,turn -90
355-
moveto(48,104.375) #7 feet forward until against switch enclosure, compensating for robot length
355+
moveto (48,104.375) #7 feet forward until against switch enclosure, compensating for robot length
356356
switch #deploy switch
357357
move -24 # 2 feet back
358358
turn -90
@@ -368,7 +368,7 @@ exchange
368368
CLxE:
369369
moveto (0,60) -90 #5 feet forward, turn -90
370370
moveto (-48,60) 90 #3 feet left,turn 90
371-
moveto(-48,104.375) #7 feet forward until against switch enclosure,compensating for robot length
371+
moveto (-48,104.375) #7 feet forward until against switch enclosure,compensating for robot length
372372
switch #deploy switch
373373
move -24
374374
turn 90
@@ -383,7 +383,7 @@ exchange
383383
CxxE:
384384
moveto (0,60) -90 #5 feet forward, turn -90
385385
moveto (-48,60) 90 #3 feet left,turn 90
386-
moveto(-48,104.375) #7 feet forward until against switch enclosure,compensating for robot length
386+
moveto (-48,104.375) #7 feet forward until against switch enclosure,compensating for robot length
387387
move -96 #move 8 feet back
388388
turn 180 #turn 180 degrees to face the exchange
389389
exchange
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#Sun Feb 18 15:40:25 PST 2018
1+
#Tue Feb 20 09:44:13 PST 2018
22
C\:\\Users\\dean\\git\\RobotCode2018\\Robot2018\\lib\\libpathfinderjava.so=4087ee38c338446b8305f67716260df4

Robot2018/src/org/usfirst/frc/team199/Robot2018/OI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public OI() {
9090
MoveLiftUpButton.whileHeld(new RunLift(Robot.lift, true));
9191
MoveLiftDownButton.whileHeld(new RunLift(Robot.lift, false));
9292

93-
// manipulator = new Joystick(2);
93+
manipulator = new Joystick(2);
9494
// closeIntake = new JoystickButton(manipulator, getButton("Close Intake
9595
// Button", 1));
9696
// closeIntake.whenPressed(new CloseIntake());

Robot2018/src/org/usfirst/frc/team199/Robot2018/Robot.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import java.util.Map;
1313

1414
import org.usfirst.frc.team199.Robot2018.autonomous.AutoUtils;
15+
import org.usfirst.frc.team199.Robot2018.autonomous.Position;
1516
import org.usfirst.frc.team199.Robot2018.commands.Autonomous;
16-
import org.usfirst.frc.team199.Robot2018.commands.Autonomous.Position;
1717
import org.usfirst.frc.team199.Robot2018.commands.Autonomous.Strategy;
1818
import org.usfirst.frc.team199.Robot2018.commands.ShiftLowGear;
1919
import org.usfirst.frc.team199.Robot2018.subsystems.Climber;
@@ -22,9 +22,9 @@
2222
import org.usfirst.frc.team199.Robot2018.subsystems.IntakeEject;
2323
import org.usfirst.frc.team199.Robot2018.subsystems.Lift;
2424

25-
import edu.wpi.first.wpilibj.CameraServer;
2625
import edu.wpi.first.wpilibj.DriverStation;
2726
import edu.wpi.first.wpilibj.IterativeRobot;
27+
import edu.wpi.first.wpilibj.PIDController;
2828
import edu.wpi.first.wpilibj.Preferences;
2929
import edu.wpi.first.wpilibj.command.Command;
3030
import edu.wpi.first.wpilibj.command.Scheduler;
@@ -53,7 +53,7 @@ public class Robot extends IterativeRobot {
5353
public static Map<String, ArrayList<String[]>> autoScripts;
5454

5555
Command autonomousCommand;
56-
SendableChooser<Position> posChooser = new SendableChooser<Position>();
56+
SendableChooser<Autonomous.Position> posChooser = new SendableChooser<Autonomous.Position>();
5757
Map<String, SendableChooser<Strategy>> stratChoosers = new HashMap<String, SendableChooser<Strategy>>();
5858
String[] fmsPossibilities = { "LL", "LR", "RL", "RR" };
5959

@@ -69,6 +69,14 @@ public double getConst(String key, double def) {
6969
}
7070
return pref.getDouble("Const/" + key, def);
7171
}
72+
73+
public void putData(String string, PIDController controller) {
74+
SmartDashboard.putData(string, controller);
75+
}
76+
77+
public void putNumber(String string, double d) {
78+
SmartDashboard.putNumber(string, d);
79+
}
7280
/*
7381
* if (!SmartDashboard.containsKey("Const/" + key)) { if
7482
* (!SmartDashboard.putNumber("Const/" + key, def)) {
@@ -109,7 +117,7 @@ public void robotInit() {
109117
oi = new OI();
110118

111119
// auto position chooser
112-
for (Position p : Position.values()) {
120+
for (Autonomous.Position p : Autonomous.Position.values()) {
113121
posChooser.addObject(p.getSDName(), p);
114122
}
115123
SmartDashboard.putData("Starting Position", posChooser);
@@ -131,8 +139,8 @@ public void robotInit() {
131139
autoScripts = AutoUtils.parseScriptFile(Preferences.getInstance().getString("autoscripts", ""));
132140

133141
listen = new Listener();
134-
CameraServer.getInstance().startAutomaticCapture(0);
135-
CameraServer.getInstance().startAutomaticCapture(1);
142+
// CameraServer.getInstance().startAutomaticCapture(0);
143+
// CameraServer.getInstance().startAutomaticCapture(1);
136144
}
137145

138146
/**
@@ -157,9 +165,11 @@ public void disabledPeriodic() {
157165
*/
158166
@Override
159167
public void autonomousInit() {
168+
dt.resetAHRS();
169+
AutoUtils.position = new Position(0, 0, 0);
160170
Scheduler.getInstance().add(new ShiftLowGear());
161171
String fmsInput = DriverStation.getInstance().getGameSpecificMessage();
162-
Position startPos = posChooser.getSelected();
172+
Autonomous.Position startPos = posChooser.getSelected();
163173
double autoDelay = SmartDashboard.getNumber("Auto Delay", 0);
164174

165175
Map<String, Strategy> strategies = new HashMap<String, Strategy>();
@@ -169,8 +179,8 @@ public void autonomousInit() {
169179
strategies.put(key, chooser.getSelected());
170180
}
171181

172-
Autonomous auto = new Autonomous(startPos, strategies, autoDelay, fmsInput, false);
173-
auto.start();
182+
Scheduler.getInstance().add(new Autonomous(startPos, strategies, autoDelay, fmsInput, false));
183+
// auto.start();
174184
}
175185

176186
/**

Robot2018/src/org/usfirst/frc/team199/Robot2018/RobotMap.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,10 @@ public RobotMap() {
130130

131131
leftIntakeMotor = new VictorSP(getPort("IntakeLeftVictorSP", 9));
132132
rightIntakeMotor = new VictorSP(getPort("IntakeRightVictorSP", 8));
133-
// leftIntakeHorizontalSolenoid = new
134-
// DoubleSolenoid(getPort("IntakeLeftHorizontalSolenoidPort1", 2),
135-
// getPort("IntakeLeftHorizontalSolenoidPort2", 3));
136-
// rightIntakeHorizontalSolenoid = new
137-
// DoubleSolenoid(getPort("IntakeRightHorizontalSolenoidPort1", 4),
138-
// getPort("IntakeRightHorizontalSolenoidPort2", 5));
133+
leftIntakeHorizontalSolenoid = new DoubleSolenoid(getPort("IntakeLeftHorizontalSolenoidPort1", 2),
134+
getPort("IntakeLeftHorizontalSolenoidPort2", 3));
135+
rightIntakeHorizontalSolenoid = new DoubleSolenoid(getPort("IntakeRightHorizontalSolenoidPort1", 4),
136+
getPort("IntakeRightHorizontalSolenoidPort2", 5));
139137
// leftIntakeVerticalSolenoid = new
140138
// DoubleSolenoid(getPort("IntakeLeftVerticalSolenoidPort1", 6),
141139
// getPort("IntakeLeftVerticalSolenoidPort2", 7));
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package org.usfirst.frc.team199.Robot2018;
22

3+
import edu.wpi.first.wpilibj.PIDController;
4+
35
public interface SmartDashboardInterface {
46
public double getConst(String key, double def);
7+
8+
public void putData(String string, PIDController controller);
9+
10+
public void putNumber(String string, double d);
511
}

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class AutoUtils {
88

9-
public static Position position = new Position(0, 0, 0);
9+
public static Position position;
1010

1111
/**
1212
* Parses the inputted script file into a map of scripts
@@ -24,23 +24,25 @@ public static Map<String, ArrayList<String[]>> parseScriptFile(String scriptFile
2424
ArrayList<String[]> currScript = new ArrayList<String[]>();
2525
String currScriptName = "";
2626

27-
int count = 1;
27+
int count = 0;
28+
int errorCount = 0;
2829
for (String line : lines) {
30+
count++;
2931
// remove comments
3032
int commentIndex = line.indexOf("#");
3133
if (commentIndex != -1)
3234
line = line.substring(0, commentIndex);
3335

3436
// trim and remove extra whitespace just to make it neater
35-
line = line.trim().replaceAll("\\s+", " ");
37+
line = line.trim().replaceAll("\\s+", " ");
3638
// make coordinates with spaces also work
3739
int parenIndex = line.indexOf("(");
3840
while (parenIndex != -1) {
3941
// removes all spaces between the parentheses
4042
int endParenIndex = line.indexOf(")", parenIndex);
4143
String coord = line.substring(parenIndex + 1, endParenIndex);
4244
line = line.substring(0, parenIndex + 1) + coord.replaceAll(" ", "") + line.substring(endParenIndex);
43-
45+
4446
// finds next parentheses
4547
parenIndex = line.indexOf("(", parenIndex + 1);
4648
}
@@ -74,9 +76,11 @@ public static Map<String, ArrayList<String[]>> parseScriptFile(String scriptFile
7476
if (isValidCommand(instruction, args, count)) {
7577
String[] command = { instruction, args };
7678
currScript.add(command);
79+
} else {
80+
errorCount++;
7781
}
7882
}
79-
count++;
83+
8084
}
8185

8286
// puts the last script in
@@ -85,6 +89,8 @@ public static Map<String, ArrayList<String[]>> parseScriptFile(String scriptFile
8589
// remove the stray one in the beginning
8690
autoScripts.remove("");
8791

92+
System.out.println("[INFO] Successfuly parsed " + count + " lines with " + errorCount + " errors.");
93+
8894
return autoScripts;
8995
}
9096

@@ -187,7 +193,7 @@ else if (instruction.equals("jump")) {
187193
* the message to log
188194
*/
189195

190-
private static void logWarning (int lineNumber, String message) {
196+
private static void logWarning(int lineNumber, String message) {
191197
System.err.println("[ERROR] Line " + lineNumber + ": " + message);
192198
}
193199

@@ -243,16 +249,16 @@ public static double[] parsePoint(String cmdArgs) {
243249
double[] point = new double[2];
244250
String parentheseless;
245251
String[] pointparts;
246-
if (AutoUtils.isPoint(cmdArgs)) {
252+
if (isPoint(cmdArgs)) {
247253
parentheseless = cmdArgs.substring(1, cmdArgs.length() - 1);
248254
pointparts = parentheseless.split(",");
249-
try {
250-
point[0] = Double.parseDouble(pointparts[0]);
251-
point[1] = Double.parseDouble(pointparts[1]);
252-
} catch (Exception e) {
253-
point[0] = 1;
254-
point[1] = 1;
255-
}
255+
try {
256+
point[0] = Double.parseDouble(pointparts[0]);
257+
point[1] = Double.parseDouble(pointparts[1]);
258+
} catch (Exception e) {
259+
point[0] = 1;
260+
point[1] = 1;
261+
}
256262
}
257263
return point;
258264
}

Robot2018/src/org/usfirst/frc/team199/Robot2018/autonomous/scriptupload/scriptupload.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#nt setup
22
from networktables import NetworkTables
33
import __future__
4+
import time
45
NetworkTables.initialize(server='10.1.99.2')
56
prefs = NetworkTables.getTable("Preferences")
67

@@ -30,6 +31,8 @@
3031
prefs.putString("autoscripts", oneline)
3132
print("Uploading %s as a String[] to key \"autoscripts\"" % filename)
3233

34+
time.sleep(0.1)
35+
3336
#checks if the key has been filled
3437
tester = "" #a variable to check if autoscripts is None
3538

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

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)