Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1.  
  2. package org.usfirst.frc.team5945.robot.subsystems;
  3.  
  4. import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
  5.  
  6. import edu.wpi.first.wpilibj.Encoder;
  7. import edu.wpi.first.wpilibj.Talon;
  8. import edu.wpi.first.wpilibj.command.Subsystem;
  9.  
  10. /**
  11. *
  12. */
  13. public class EncoderTest extends Subsystem {
  14.  
  15. // Put methods for controlling this subsystem
  16. // here. Call these from Commands.
  17. private static Encoder enc;
  18. private static WPI_TalonSRX motor = new WPI_TalonSRX(3);
  19. public static double motorRadius = 0.2, distancePerPulse;
  20.  
  21. public EncoderTest() {
  22. super();
  23.  
  24. enc = new Encoder(0,1,false,Encoder.EncodingType.k4X);
  25. enc.reset();
  26. distancePerPulse = motorRadius *(2.0*Math.PI)/7;//how much it moves in inches per pulse
  27. enc.setDistancePerPulse(distancePerPulse);
  28. System.out.println("Distance???" + distancePerPulse);
  29. System.out.println("Distance per pulse??" + enc.getDistancePerPulse());
  30. enc.setReverseDirection(false);
  31. }
  32.  
  33. public void initDefaultCommand() {
  34. // Set the default command for a subsystem here.
  35. //setDefaultCommand(new MySpecialCommand());
  36. }
  37.  
  38. public int getEncCount() {
  39. return enc.get();
  40. }
  41.  
  42. public void resetEnc() {
  43. enc.reset();
  44. }
  45.  
  46. public double getEncDistance() {
  47. return enc.getDistance();
  48. }
  49.  
  50.  
  51. public void setMotor(double volt) {
  52. motor.set(volt);
  53. }
  54. }
  55.  
  56.  
  57.  
  58. package org.usfirst.frc.team5945.robot.commands;
  59.  
  60. import org.usfirst.frc.team5945.robot.Robot;
  61.  
  62. import edu.wpi.first.wpilibj.command.Command;
  63.  
  64. public class RunEncoderMotor extends Command{
  65. public RunEncoderMotor() {
  66. requires(Robot.encoderTest);
  67. }
  68.  
  69. protected void initialize() {
  70. Robot.encoderTest.setMotor(0.5);
  71. }
  72.  
  73. protected void execute() {
  74. //System.out.println("count" + Robot.encoderTest.getEncCount());
  75. //System.out.println("Distance traveled: " + Robot.encoderTest.getEncDistance());
  76. }
  77.  
  78. protected boolean isFinished() {
  79. return false; //condition for distance
  80. }
  81.  
  82. protected void end() {
  83. System.out.println("End?");
  84. }
  85.  
  86. protected void interrupted() {
  87. end();
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement