Guest User

Untitled

a guest
Mar 5th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. package us.mn.k12.fairmont.robotics.subsystems;
  2.  
  3. import edu.wpi.first.wpilibj.Encoder;
  4. import edu.wpi.first.wpilibj.RobotDrive;
  5. import edu.wpi.first.wpilibj.Talon;
  6. import edu.wpi.first.wpilibj.Timer;
  7. import edu.wpi.first.wpilibj.command.Subsystem;
  8. import us.mn.k12.fairmont.robotics.RobotMap;
  9. import us.mn.k12.fairmont.robotics.commands.DriveWithJoysticks;
  10.  
  11. /**
  12.  *
  13.  * @author Teacher
  14.  */
  15. public class DriveTrain extends Subsystem {
  16.     // Put methods for controlling this subsystem
  17.     // here. Call these from Commands.
  18.  
  19.     RobotDrive drive;
  20.     Encoder enc;
  21.     Timer timer;
  22.  
  23.  
  24.     public DriveTrain() {
  25.         RobotDrive drive = new RobotDrive(RobotMap.frontLeftMotor, RobotMap.rearLeftMotor, RobotMap.frontRightMotor, RobotMap.rearRightMotor);
  26.  
  27.         Encoder enc = new Encoder(RobotMap.frontRightEncA, RobotMap.frontRightEncB);
  28.         timer = new Timer();
  29.         enc.start();
  30.     }
  31.     public void driveMechanum_Cartesian(double rightJoyY, double rightJoyX, double rotation) {
  32.         drive.mecanumDrive_Cartesian((rightJoyY * -1), rotation, rightJoyX * -1, 0); // Mechanam wheel rollers should form an x when looking directaly down from the top
  33.     }
  34.  
  35.     public void drivetest(double thing1, double thing2) {
  36.         drive.tankDrive(thing1, thing2);
  37.     }
  38.  
  39.     public boolean autoDrive(int dist, int speed) {
  40.         System.out.println("going fishes");
  41.         while (enc.get() <= dist - 1) {
  42. //          tal.set(speed*(.1*(dist-enc.get())));
  43.             if (enc.get() <= dist - 1) {
  44.                 driveMechanum_Cartesian(speed,0,speed);
  45.             }
  46.         }
  47.         return true;
  48.     }
  49.    
  50.    
  51.     // credit to team 1160's github for pieces of this
  52.     public void autoTimeDrive(double time, boolean run) {
  53.         timer.start();
  54.         timer.reset();
  55.         while (run) {
  56.             driveMechanum_Cartesian(.5,0,.5);
  57.             System.out.println(timer.get());
  58.             if (timer.get() >= time) {
  59.                 driveMechanum_Cartesian(0,0,0);
  60.                 run = false;
  61.             }
  62.         }
  63.     }
  64.    
  65.  
  66.     public void initDefaultCommand() {
  67.         // Set the default command for a subsystem here.
  68.         setDefaultCommand(new DriveWithJoysticks());
  69.     }
  70.  
  71.    
  72. }
Advertisement
Add Comment
Please, Sign In to add comment