- package frc.robot; //veya başka bişi
- /*
- *
- *
- *
- *
- *
- *
- *
- * HER CLASS NORMALDE FARKLI DOSYADA, javada bir dosyada sadece tek public class olabiliyor, aynı zamanda command ve subsystemlar için private kullanılamaz
- *
- *
- *
- *
- *
- *
- */
- import edu.wpi.first.wpilibj.TimedRobot;
- import edu.wpi.first.wpilibj2.command.SubsystemBase;
- import edu.wpi.first.wpilibj.drive.DifferentialDrive;
- import com.ctre.phoenix.motorcontrol.can.*;
- import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX;
- import edu.wpi.first.wpilibj.SpeedController;
- import edu.wpi.first.wpilibj.SpeedControllerGroup;
- import edu.wpi.first.wpilibj.drive.DifferentialDrive;
- import edu.wpi.first.wpilibj2.command.CommandBase;
- import edu.wpi.first.wpilibj2.command.button.JoystickButton;
- import edu.wpi.first.wpilibj.XboxController;
- import edu.wpi.first.wpilibj2.command.CommandScheduler;
- public class DriveBase extends SubsystemBase
- {
- private static DriveBase INSTANCE;
- public static DriveBase getInstance() {
- if (INSTANCE == null) {
- synchronized (DriveBase.class) {
- if (INSTANCE == null) {
- INSTANCE = new DriveBase();
- }
- }
- }
- return INSTANCE;
- }
- public WPI_VictorSPX mleft; //kaç motor olduğu yazmıyordu 2 güzel
- public WPI_VictorSPX mright;
- public DifferentialDrive difDrive;
- private DriveBase(){
- mleft = new WPI_VictorSPX(0);
- mright = new WPI_VictorSPX(1);
- difDrive = new DifferentialDrive(mleft,mright);
- }
- public tankDrive(double leftSpeed, double rightSpeed)
- {
- difDrive.tankDrive(leftSpeed*0.5,rightSpeed*0.5);
- }
- public void periodic() {
- }
- }
- public class Redline extends SubsystemBase
- {
- private static Redline INSTANCE;
- public static Redline getInstance() {
- if (INSTANCE == null) {
- synchronized (Redline.class) {
- if (INSTANCE == null) {
- INSTANCE = new Redline ();
- }
- }
- }
- return INSTANCE;
- }
- public WPI_VictorSPX motorZ;
- private Redline()
- {
- motorZ = new WPI_VictorSPX(2);
- }
- public void startMotor()
- {
- motorZ.set(0.5);
- }
- public void stopMotor()
- {
- motorZ.set(0);
- }
- }
- public class RedlineStart extends CommandBase
- {
- public Redline m_rl = Redline.getInstance();
- public RedlineStart(){
- }
- public void initilaze(){
- m_rl.startMotor();
- }
- public void end(boolean interrupted) {
- m_rl.stopMotor();
- }
- }
- public class BenimJoystick
- {
- public XboxController xBOX;
- public RedlineStart rlCommand = new RedlineStart();
- public BenimJoystick()
- {
- xBOX = new XboxController(0);
- configJoystick();
- }
- public void configJoystick()
- {
- JoystickButton rl_Button = new JoystickButton(xBOX, 1);
- rl_Button.whenHeld(rlCommand);
- }
- }
- public class Robot extends TimedRobot {
- public BenimJoystick stick = new BenimJoystick();
- public DriveBase m_drive = DriveBase.getInstance();
- @Override
- public void robotInit() {
- }
- @Override
- public void robotPeriodic() {
- CommandScheduler.getInstance().run();
- }
- @Override
- public void disabledInit() {
- }
- @Override
- public void disabledPeriodic() {
- }
- @Override
- public void autonomousInit() {
- }
- @Override
- public void autonomousPeriodic(){
- }
- @Override
- public void teleopInit() {
- }
- @Override
- public void teleopPeriodic() {
- m_drive.tankDrive(stick.xBOX.getRawAxis(1), stick.xBOX.getRawAxis(5));
- }
- @Override
- public void testInit() {
- }
- @Override
- public void testPeriodic() {
- }
- }