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

Commit 6f11de6

Browse files
committed
2 parents de26026 + 1b992ff commit 6f11de6

8 files changed

Lines changed: 111 additions & 21 deletions

File tree

Robot2018/lib/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/User_Libraries.properties
1+
User_Libraries.properties

Robot2018/lib/User_Libraries.properties

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
* interface to the commands and command groups that allow control of the robot.
2727
*/
2828
public class OI {
29+
/*
30+
* WHENEVER YOU ADD OR CHANGE WHAT A BUTTON OR JOYSTICK DOES, indicate in
31+
* /docs/controllers.txt to keep that reference up to date.
32+
*/
2933

3034
public Joystick leftJoy;
3135
private JoystickButton shiftLowGearButton;

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

Lines changed: 7 additions & 2 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
@@ -25,6 +25,7 @@ public static Map<String, ArrayList<String[]>> parseScriptFile(String scriptFile
2525
String currScriptName = "";
2626

2727
int count = 0;
28+
int errorCount = 0;
2829
for (String line : lines) {
2930
count++;
3031
// remove comments
@@ -75,6 +76,8 @@ public static Map<String, ArrayList<String[]>> parseScriptFile(String scriptFile
7576
if (isValidCommand(instruction, args, count)) {
7677
String[] command = { instruction, args };
7778
currScript.add(command);
79+
} else {
80+
errorCount++;
7881
}
7982
}
8083

@@ -86,6 +89,8 @@ public static Map<String, ArrayList<String[]>> parseScriptFile(String scriptFile
8689
// remove the stray one in the beginning
8790
autoScripts.remove("");
8891

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

@@ -244,7 +249,7 @@ public static double[] parsePoint(String cmdArgs) {
244249
double[] point = new double[2];
245250
String parentheseless;
246251
String[] pointparts;
247-
if (AutoUtils.isPoint(cmdArgs)) {
252+
if (isPoint(cmdArgs)) {
248253
parentheseless = cmdArgs.substring(1, cmdArgs.length() - 1);
249254
pointparts = parentheseless.split(",");
250255
try {

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
public class DefaultIntake extends Command {
1111

12+
private boolean manipulatorPluggedIn = true;
13+
1214
public DefaultIntake() {
1315
// Use requires() here to declare subsystem dependencies
1416
// eg. requires(chassis);
@@ -17,13 +19,21 @@ public DefaultIntake() {
1719

1820
// Called just before this Command runs the first time
1921
protected void initialize() {
22+
try {
23+
Robot.oi.manipulator.getRawAxis(1);
24+
} catch (NullPointerException e) {
25+
System.err.println("[ERROR] Manipulator not plugged in.");
26+
manipulatorPluggedIn = false;
27+
}
2028
}
2129

2230
// Called repeatedly when this Command is scheduled to run
2331
protected void execute() {
2432
// 1 and 5 represent the axes' index in driver station
25-
Robot.intakeEject.runLeftIntake(Robot.oi.manipulator.getRawAxis(1));
26-
Robot.intakeEject.runRightIntake(Robot.oi.manipulator.getRawAxis(5));
33+
if (manipulatorPluggedIn) {
34+
Robot.intakeEject.runLeftIntake(Robot.oi.manipulator.getRawAxis(1));
35+
Robot.intakeEject.runRightIntake(Robot.oi.manipulator.getRawAxis(5));
36+
}
2737
}
2838

2939
// Make this return true when this Command no longer needs to run execute()

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import edu.wpi.first.wpilibj.PIDOutput;
1010
import edu.wpi.first.wpilibj.PIDSource;
1111
import edu.wpi.first.wpilibj.command.Command;
12-
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1312

1413
/**
1514
* Drives the robot a certain target distance using PID. Implements PIDOutput in
@@ -21,6 +20,9 @@ public class PIDMove extends Command implements PIDOutput {
2120
private DrivetrainInterface dt;
2221
private PIDController moveController;
2322
private PIDSource avg;
23+
private SmartDashboardInterface sd;
24+
private double pointX;
25+
private double pointY;
2426

2527
/**
2628
* Constructs this command with a new PIDController. Sets all of the
@@ -43,13 +45,14 @@ public PIDMove(double targ, DrivetrainInterface dt, SmartDashboardInterface sd,
4345
target = targ;
4446
this.dt = dt;
4547
this.avg = avg;
48+
this.sd = sd;
4649
if (Robot.dt != null) {
4750
requires(Robot.dt);
4851
}
4952
double kf = 1 / (dt.getCurrentMaxSpeed() * sd.getConst("Default PID Update Time", 0.05));
5053
moveController = new PIDController(sd.getConst("MovekP", 0.1), sd.getConst("MovekI", 0),
5154
sd.getConst("MovekD", 0), kf, avg, this);
52-
SmartDashboard.putData("Move PID", moveController);
55+
sd.putData("Move PID", moveController);
5356
}
5457

5558
/**
@@ -70,20 +73,19 @@ public PIDMove(double targ, DrivetrainInterface dt, SmartDashboardInterface sd,
7073
* the PIDSorceAverage of the DT's two Encoders
7174
*/
7275
public PIDMove(double[] point, DrivetrainInterface dt, SmartDashboardInterface sd, PIDSource avg) {
73-
double dx = point[0] - AutoUtils.position.getX();
74-
double dy = point[1] - AutoUtils.position.getY();
76+
pointX = point[0];
77+
pointY = point[1];
7578

76-
double dist = Math.sqrt(dx * dx + dy * dy); // pythagorean theorem to find distance
77-
78-
this.target = dist;
7979
this.dt = dt;
8080
this.avg = avg;
81+
this.sd = sd;
8182
if (Robot.dt != null) {
8283
requires(Robot.dt);
8384
}
8485
double kf = 1 / (dt.getCurrentMaxSpeed() * sd.getConst("Default PID Update Time", 0.05));
8586
moveController = new PIDController(sd.getConst("MovekP", 1), sd.getConst("MovekI", 0), sd.getConst("MovekD", 0),
8687
kf, avg, this);
88+
sd.putData("Move PID", moveController);
8789
}
8890

8991
/**
@@ -92,6 +94,12 @@ public PIDMove(double[] point, DrivetrainInterface dt, SmartDashboardInterface s
9294
*/
9395
@Override
9496
public void initialize() {
97+
double dx = pointX - AutoUtils.position.getX();
98+
double dy = pointY - AutoUtils.position.getY();
99+
100+
double dist = Math.sqrt(dx * dx + dy * dy); // pythagorean theorem to find distance
101+
this.target = dist;
102+
95103
dt.resetDistEncs();
96104
moveController.disable();
97105
// input is in inches
@@ -100,6 +108,7 @@ public void initialize() {
100108
moveController.setOutputRange(-1.0, 1.0);
101109
moveController.setContinuous(false);
102110
moveController.setAbsoluteTolerance(Robot.getConst("MoveTolerance", 0.1));
111+
System.out.println("move target = " + target);
103112
moveController.setSetpoint(target);
104113

105114
moveController.enable();
@@ -114,8 +123,8 @@ public void initialize() {
114123
@Override
115124
protected void execute() {
116125
System.out.println("Enc Avg Dist: " + avg.pidGet());
117-
SmartDashboard.putNumber("Move PID Result", moveController.get());
118-
SmartDashboard.putNumber("Move PID Error", moveController.getError());
126+
sd.putNumber("Move PID Result", moveController.get());
127+
sd.putNumber("Move PID Error", moveController.getError());
119128
}
120129

121130
/**
@@ -144,10 +153,13 @@ protected void end() {
144153

145154
double angle = Math.toRadians(AutoUtils.position.getRot());
146155
double dist = avg.pidGet();
147-
double x = Math.cos(angle) * dist;
148-
double y = Math.sin(angle) * dist;
156+
// x and y are switched because we are using bearings
157+
double y = Math.cos(angle) * dist;
158+
double x = Math.sin(angle) * dist;
149159
AutoUtils.position.changeX(x);
150160
AutoUtils.position.changeY(y);
161+
162+
AutoUtils.position.setRot(dt.getAHRSAngle());
151163
}
152164

153165
/**
@@ -173,6 +185,6 @@ protected void interrupted() {
173185
@Override
174186
public void pidWrite(double output) {
175187
dt.arcadeDrive(output, 0);
176-
SmartDashboard.putNumber("Move PID Output", output);
188+
sd.putNumber("Move PID Output", output);
177189
}
178190
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,11 @@ protected void initialize() {
152152

153153
System.out.println("x = " + dx + ", y = " + dy);
154154

155+
// x and y are switched because we are using bearings
155156
double absTurn = Math.toDegrees(Math.atan2(dx, dy));
156157
target = absTurn - AutoUtils.position.getRot();
157-
System.out.println("position rotation = " + AutoUtils.position.getRot());
158-
System.out.println("target = " + target);
158+
System.out.println("current bearing = " + AutoUtils.position.getRot());
159+
System.out.println("target bearing = " + target);
159160
}
160161

161162
System.out.println("Turn to point: " + turnToPoint);

docs/controllers.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
controller indices
2+
manipulator
3+
buttons
4+
1 A
5+
2 B
6+
3 X
7+
4 Y
8+
5 LB
9+
6 RB
10+
7 back
11+
8 start
12+
9 N/a
13+
10 N/a
14+
press mode to toggle mode light
15+
axes
16+
0 left thumbstick X axis (D-pad if mode light on)
17+
1 left thumbstick Y axis (D-pad if mode light on)
18+
2 left trigger
19+
3 right trigger
20+
4 right thumbstick X axis
21+
5 right thumbstick Y axis
22+
mode light off:
23+
POV
24+
D-pad (left joystick if mode light on)
25+
rumble
26+
fake news
27+
left joystick
28+
buttons
29+
1
30+
2
31+
3
32+
4
33+
5
34+
6
35+
7
36+
8
37+
9
38+
10
39+
11
40+
axes
41+
0 X axis
42+
1 Y axis (forward is negative)
43+
2 Z axis (knob at base)
44+
right joystick
45+
buttons
46+
1
47+
2
48+
3
49+
4
50+
5
51+
6
52+
7
53+
8
54+
9
55+
10
56+
11
57+
axes
58+
0 X axis
59+
1 Y axis (forward is negative)
60+
2 Z axis (knob at base)

0 commit comments

Comments
 (0)