Facebook
From Tuna, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 142
  1. package frc.robot; //veya başka bişi
  2.  
  3. /*
  4. *
  5. *
  6. *
  7. *
  8. *
  9. *
  10. *
  11. *    HER CLASS NORMALDE FARKLI DOSYADA, javada bir dosyada sadece tek public class olabiliyor, aynı zamanda command ve subsystemlar için private kullanılamaz
  12. *
  13. *
  14. *
  15. *
  16. *
  17. *
  18. */
  19.  
  20. import edu.wpi.first.wpilibj.TimedRobot;
  21. import edu.wpi.first.wpilibj2.command.SubsystemBase;
  22.  
  23.  
  24. import edu.wpi.first.wpilibj.drive.DifferentialDrive;
  25. import com.ctre.phoenix.motorcontrol.can.*;
  26. import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX;
  27. import edu.wpi.first.wpilibj.SpeedController;
  28. import edu.wpi.first.wpilibj.SpeedControllerGroup;
  29. import edu.wpi.first.wpilibj.drive.DifferentialDrive;
  30. import edu.wpi.first.wpilibj2.command.CommandBase;
  31. import edu.wpi.first.wpilibj2.command.button.JoystickButton;
  32. import edu.wpi.first.wpilibj.XboxController;
  33. import edu.wpi.first.wpilibj2.command.CommandScheduler;
  34.  
  35. public class DriveBase extends SubsystemBase
  36. {
  37.     private static DriveBase INSTANCE;
  38.  
  39.     public static DriveBase getInstance() {
  40.         if (INSTANCE == null) {
  41.             synchronized (DriveBase.class) {
  42.                 if (INSTANCE == null) {
  43.                     INSTANCE = new DriveBase();
  44.                 }
  45.             }
  46.         }
  47.         return INSTANCE;
  48.     }
  49.  
  50.  
  51.    public WPI_VictorSPX mleft; //kaç motor olduğu yazmıyordu 2 güzel
  52.    public WPI_VictorSPX mright;
  53.  
  54.    public DifferentialDrive difDrive;
  55.  
  56.    private DriveBase(){
  57.       mleft    = new WPI_VictorSPX(0);
  58.       mright   = new WPI_VictorSPX(1);
  59.       difDrive = new DifferentialDrive(mleft,mright);
  60.    }
  61.  
  62.   public tankDrive(double leftSpeed, double rightSpeed)
  63.   {
  64.     difDrive.tankDrive(leftSpeed*0.5,rightSpeed*0.5);
  65.   }
  66.  
  67.  
  68.     public void periodic() {        
  69.     }
  70. }
  71.  
  72. public class Redline extends SubsystemBase
  73. {
  74.     private static Redline INSTANCE;
  75.  
  76.     public static Redline getInstance() {
  77.         if (INSTANCE == null) {
  78.             synchronized (Redline.class) {
  79.                 if (INSTANCE == null) {
  80.                     INSTANCE = new Redline ();
  81.                 }
  82.             }
  83.         }
  84.         return INSTANCE;
  85.     }
  86.  
  87.    
  88.     public WPI_VictorSPX motorZ;
  89.    
  90.     private Redline()
  91.     {
  92.     motorZ = new WPI_VictorSPX(2);
  93.     }
  94.    
  95.     public void startMotor()
  96.     {
  97.       motorZ.set(0.5);
  98.     }
  99.  
  100.     public void stopMotor()
  101.     {
  102.       motorZ.set(0);
  103.     }
  104.  
  105. }
  106.  
  107.  
  108. public class RedlineStart extends CommandBase
  109. {
  110.     public Redline m_rl = Redline.getInstance();
  111.    
  112.     public RedlineStart(){
  113.     }
  114.  
  115.     public void initilaze(){
  116.       m_rl.startMotor();
  117.      
  118.     }
  119.  
  120.     public void end(boolean interrupted) {
  121.       m_rl.stopMotor();
  122.     }
  123.  
  124. }
  125.  
  126.  
  127. public class BenimJoystick
  128. {
  129.  
  130.   public XboxController xBOX;
  131.   public RedlineStart rlCommand = new RedlineStart();
  132.  
  133.   public BenimJoystick()
  134.   {
  135.     xBOX = new XboxController(0);
  136.     configJoystick();
  137.   }
  138.  
  139.  
  140.   public void configJoystick()
  141.   {
  142.     JoystickButton rl_Button = new JoystickButton(xBOX, 1);
  143.     rl_Button.whenHeld(rlCommand);
  144.   }
  145. }
  146.  
  147.  
  148.  
  149. public class Robot extends TimedRobot {
  150.    
  151.   public BenimJoystick stick = new BenimJoystick();
  152.   public DriveBase m_drive = DriveBase.getInstance();
  153.  
  154.   @Override
  155.   public void robotInit() {
  156.   }
  157.  
  158.  
  159.   @Override
  160.   public void robotPeriodic() {
  161.       CommandScheduler.getInstance().run();
  162.   }
  163.  
  164.  
  165.   @Override
  166.   public void disabledInit() {
  167.   }
  168.  
  169.   @Override
  170.   public void disabledPeriodic() {
  171.   }
  172.  
  173.  
  174.   @Override
  175.   public void autonomousInit() {
  176.   }
  177.  
  178.  
  179.   @Override
  180.   public void autonomousPeriodic(){
  181.   }
  182.  
  183.   @Override
  184.   public void teleopInit() {
  185.   }
  186.  
  187.  
  188.   @Override
  189.   public void teleopPeriodic() {
  190.   m_drive.tankDrive(stick.xBOX.getRawAxis(1), stick.xBOX.getRawAxis(5));
  191.   }
  192.  
  193.   @Override
  194.   public void testInit() {
  195.   }
  196.  
  197.  
  198.   @Override
  199.   public void testPeriodic() {
  200.   }
  201. }