DriveStraight command with encoder
authorniyatisriram <niyatisriram@gmail.com>
Sat, 21 Jan 2017 05:16:06 +0000 (21:16 -0800)
committerjessicabhalerao <jessicabhalerao@gmail.com>
Fri, 27 Jan 2017 03:40:24 +0000 (19:40 -0800)
src/org/usfirst/frc/team3501/robot/commands/driving/DriveStraight.java [new file with mode: 0644]

diff --git a/src/org/usfirst/frc/team3501/robot/commands/driving/DriveStraight.java b/src/org/usfirst/frc/team3501/robot/commands/driving/DriveStraight.java
new file mode 100644 (file)
index 0000000..b928524
--- /dev/null
@@ -0,0 +1,30 @@
+package org.usfirst.frc.team3501.robot.commands.driving;
+
+import org.usfirst.frc.team3501.robot.Robot;
+
+public class DriveStraight {
+
+  double distL;
+  double distR;
+  double moveR = Robot.getDriveTrain().getLeftSpeed();
+  double moveL = Robot.getDriveTrain().getRightSpeed();
+
+  public DriveStraight() {
+    distL = Robot.getDriveTrain().getLeftEncoderDistance();
+    distR = Robot.getDriveTrain().getRightEncoderDistance();
+  }
+
+  public void updateMotorSpeed() {
+    if (distL > distR) {
+      double k = distL / distR;
+      moveR *= k;
+      moveL /= k;
+    } else if (distR > distL) {
+      double k = distR / distL;
+      moveR /= k;
+      moveL *= k;
+    }
+
+    Robot.getDriveTrain().setMotorValues(moveR, moveL);
+  }
+}