Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. package org.usfirst.frc.team4590.robot.commands;
  2.  
  3. import org.usfirst.frc.team4590.robot.subsystems.EncoderMotor;
  4.  
  5. import edu.wpi.first.wpilibj.PIDController;
  6. import edu.wpi.first.wpilibj.PIDController.PercentageTolerance;
  7. import edu.wpi.first.wpilibj.command.Command;
  8. import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
  9.  
  10. public class Rotate90Deg extends Command {
  11.    
  12.     EncoderMotor system;
  13.     PIDController pid;
  14.    
  15.     public Rotate90Deg() {
  16.         // TODO Auto-generated constructor stub
  17.         system = EncoderMotor.getInstance();
  18.         pid = new PIDController(0.0001, 0.00001, 0, 0, system, system);
  19.         requires(system);
  20.     }
  21.    
  22.     // Called just before this Command runs the first time
  23.     @Override
  24.     protected void initialize() {
  25.         system.resetEncoder();
  26.         pid.setAbsoluteTolerance(200);
  27.         pid.setSetpoint(2200);
  28.         pid.enable();
  29.         SmartDashboard.putData("pid", pid);
  30.     }
  31.  
  32.     // Called repeatedly when this Command is scheduled to run
  33.     @Override
  34.     protected void execute() {
  35.        
  36.     }
  37.    
  38.     private int timesHit = 0;
  39.     // Make this return true when this Command no longer needs to run execute()
  40.     @Override
  41.     protected boolean isFinished() {
  42.         if (pid.onTarget()) timesHit++;
  43.         else timesHit = 0;
  44.         if (timesHit >= 25) return true;
  45.         return false;
  46.     }
  47.  
  48.     // Called once after isFinished returns true
  49.     @Override
  50.     protected void end() {
  51.         pid.disable();
  52.         system.moveMotors(0);
  53.     }
  54.  
  55.         // Called when another command which requires one or more of the same
  56.         // subsystems is scheduled to run
  57.     @Override
  58.     protected void interrupted() {
  59.         end();
  60.     }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement