fix bugs
authorCindy Zhang <cindyzyx9@gmail.com>
Fri, 27 Jan 2017 03:36:14 +0000 (19:36 -0800)
committerCindy Zhang <cindyzyx9@gmail.com>
Sat, 28 Jan 2017 04:21:48 +0000 (20:21 -0800)
src/org/usfirst/frc/team3501/robot/Robot.java
src/org/usfirst/frc/team3501/robot/commands/driving/DriveDistance.java
src/org/usfirst/frc/team3501/robot/subsystems/DriveTrain.java

index c2e4f996d49458d36e9e300d101888b341214047..a9dd0ffca26c681bc26f422abca97d940cea553a 100644 (file)
@@ -1,6 +1,6 @@
 package org.usfirst.frc.team3501.robot;
 
-import org.usfirst.frc.team3501.robot.commands.driving.TimeDrive;
+import org.usfirst.frc.team3501.robot.commands.driving.DriveDistance;
 import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
 import org.usfirst.frc.team3501.robot.subsystems.Intake;
 import org.usfirst.frc.team3501.robot.subsystems.Shooter;
@@ -40,7 +40,7 @@ public class Robot extends IterativeRobot {
 
   @Override
   public void autonomousInit() {
-    Scheduler.getInstance().add(new TimeDrive(1.5, 0.4));
+    Scheduler.getInstance().add(new DriveDistance(25, 10));
   }
 
   @Override
index 47fc46ea0303ed6689b3c2a03b6c918b30407c8f..5c0c20b92a7ee20f2a83d0fbaec3da6792462aba 100755 (executable)
@@ -1,6 +1,5 @@
 package org.usfirst.frc.team3501.robot.commands.driving;
 
-import org.usfirst.frc.team3501.robot.MathLib;
 import org.usfirst.frc.team3501.robot.Robot;
 import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
 import org.usfirst.frc.team3501.robot.utils.PIDController;
@@ -31,8 +30,11 @@ public class DriveDistance extends Command {
   private double driveI;
   private double driveD;
 
-  public DriveDistance(double distance, double motorVal) {
+  public DriveDistance(double distance, double maxTimeOut) {
     requires(driveTrain);
+    this.maxTimeOut = maxTimeOut;
+    this.target = distance;
+
     this.driveP = driveTrain.driveP;
     this.driveI = driveTrain.driveI;
     this.driveD = driveTrain.driveD;
@@ -69,12 +71,12 @@ public class DriveDistance extends Command {
           .calcPID(this.driveTrain.getAngle() - this.driveTrain.getZeroAngle());
     }
     // System.out.println("turn: " + xVal);
-    double leftDrive = MathLib.calcLeftTankDrive(-xVal, yVal);
-    double rightDrive = MathLib.calcRightTankDrive(xVal, -yVal);
+    double leftDrive = yVal - xVal;
+    double rightDrive = yVal + xVal;
 
     this.driveTrain.setMotorValues(leftDrive, rightDrive);
 
-    System.out.println(driveTrain.getAvgEncoderDistance());
+    driveTrain.printEncoderOutput();
     // System.out.println("motorval: " + yVal);
   }
 
index ba5392a62075ba75f66adfa032e68391fb4a84a7..44744c4a078fa0f0edca7d3b0a6ca5e2290b481a 100644 (file)
@@ -7,6 +7,7 @@ import org.usfirst.frc.team3501.robot.utils.BNO055;
 import com.ctre.CANTalon;
 
 import edu.wpi.first.wpilibj.Encoder;
+import edu.wpi.first.wpilibj.I2C.Port;
 import edu.wpi.first.wpilibj.RobotDrive;
 import edu.wpi.first.wpilibj.command.Subsystem;
 
@@ -46,6 +47,10 @@ public class DriveTrain extends Subsystem {
 
     // ROBOT DRIVE
     robotDrive = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight);
+
+    this.imu = BNO055.getInstance(BNO055.opmode_t.OPERATION_MODE_IMUPLUS,
+        BNO055.vector_type_t.VECTOR_EULER, Port.kOnboard, (byte) 0x28);
+    gyroZero = imu.getHeading();
   }
 
   public static DriveTrain getDriveTrain() {
@@ -98,6 +103,11 @@ public class DriveTrain extends Subsystem {
     return rightEncoder.getDistance();
   }
 
+  public void printEncoderOutput() {
+    System.out.println("left: " + getLeftEncoderDistance());
+    System.out.println("right: " + getRightEncoderDistance());
+  }
+
   public double getAvgEncoderDistance() {
     return (leftEncoder.getDistance() + rightEncoder.getDistance()) / 2;
   }