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

Commit 237bde6

Browse files
committed
use absolute values in AutoMoveTo
1 parent 4a8dbdb commit 237bde6

2 files changed

Lines changed: 34 additions & 19 deletions

File tree

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,11 @@ public AutoMoveTo(String[] args, DrivetrainInterface dt, SmartDashboardInterface
2424
for (String arg : args) {
2525
if (AutoUtils.isDouble(arg)) {
2626
rotation = Double.valueOf(arg);
27-
double relrotation = rotation - AutoUtils.position.getRot();
28-
addSequential(new PIDTurn(relrotation, dt, sd, pidMoveSrc));
29-
AutoUtils.position.setRot(rotation);
27+
addSequential(new PIDTurn(rotation, dt, sd, pidMoveSrc, true));
3028
} else if (AutoUtils.isPoint(arg)) {
3129
point = AutoUtils.parsePoint(arg);
32-
double deltaX = point[0] - AutoUtils.position.getX();
33-
double deltaY = point[1] - AutoUtils.position.getY();
34-
double atan = Math.toDegrees(Math.atan(deltaX / deltaY));
35-
double relrotation = atan - AutoUtils.position.getRot();
36-
addSequential(new PIDTurn(relrotation, dt, sd, pidMoveSrc));
37-
double dX2 = deltaX * deltaX;
38-
double dY2 = deltaY * deltaY;
39-
double distance = Math.sqrt(dX2 + dY2);
40-
addSequential(new PIDMove(distance, dt, sd, pidMoveSrc));
41-
double x = AutoUtils.position.getX();
42-
double y = AutoUtils.position.getY();
43-
AutoUtils.position.setX(point[0]);
44-
AutoUtils.position.setY(point[1]);
45-
AutoUtils.position.setRot(Math.toDegrees(Math.atan((point[0] - x) / (point[1] - y))));
30+
addSequential(new PIDTurn(point, dt, sd, pidMoveSrc));
31+
addSequential(new PIDMove(point, dt, sd, pidMoveSrc));
4632
} else {
4733
throw new IllegalArgumentException();
4834
}

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,20 @@ public class PIDTurn extends Command implements PIDOutput {
4242
* @param sd
4343
* the Smart Dashboard reference, or a SmartDashboardInterface for
4444
* testing
45+
* @param absolute
46+
* whether the target passed is absolute or relative
4547
*/
46-
public PIDTurn(double targ, DrivetrainInterface dt, SmartDashboardInterface sd, PIDSource ahrs) {
48+
public PIDTurn(double targ, DrivetrainInterface dt, SmartDashboardInterface sd, PIDSource ahrs, boolean absolute) {
4749
// Use requires() here to declare subsystem dependencies
48-
target = targ;
4950
this.dt = dt;
5051
this.ahrs = ahrs;
5152

53+
if (absolute) {
54+
target = targ - AutoUtils.position.getRot();
55+
} else {
56+
target = targ;
57+
}
58+
5259
if (Robot.dt != null) {
5360
requires(Robot.dt);
5461
}
@@ -61,6 +68,28 @@ public PIDTurn(double targ, DrivetrainInterface dt, SmartDashboardInterface sd,
6168
// tim = new Timer();
6269
}
6370

71+
/**
72+
* Constructs this command with a new PIDController. Sets all of the
73+
* controller's PID constants based on SD prefs. Sets the controller's PIDSource
74+
* to the AHRS (gyro) object and sets its PIDOutput to this command which
75+
* implements PIDOutput's pidWrite() method.
76+
*
77+
* @param targ
78+
* the target bearing (in degrees) to turn to (so negative if turning
79+
* left, positive if turning right)
80+
* @param dt
81+
* the Drivetrain (for actual code) or a DrivetrainInterface (for
82+
* testing)
83+
* @param ahrs
84+
* the AHRS (gyro)
85+
* @param sd
86+
* the Smart Dashboard reference, or a SmartDashboardInterface for
87+
* testing
88+
*/
89+
public PIDTurn(double targ, DrivetrainInterface dt, SmartDashboardInterface sd, PIDSource ahrs) {
90+
this(targ, dt, sd, ahrs, false);
91+
}
92+
6493
/**
6594
* Constructs this command with a new PIDController. Sets all of the
6695
* controller's PID constants based on SD prefs. Sets the controller's PIDSource

0 commit comments

Comments
 (0)