rubut
// Coding By Arda Başar
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc.robot;
import java.util.Set;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import com.fasterxml.jackson.databind.ser.std.CalendarSerializer;
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkLowLevel.MotorType;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Tracer;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.cameraserver.CameraServer;
public class Robot extends TimedRobot {
private Timer timer;
private boolean isButton3Pressed;
private long startTime;
private long realTime;
CANSparkMax Left_Leader = new CANSparkMax(2, MotorType.kBrushed);
CANSparkMax Left_Follower = new CANSparkMax(1, MotorType.kBrushed);
CANSparkMax Right_Leader = new CANSparkMax(3, MotorType.kBrushed);
CANSparkMax Right_Follower = new CANSparkMax(4, MotorType.kBrushed);
CANSparkMax Intech_Right = new CANSparkMax(5, MotorType.kBrushless);
CANSparkMax Intech_Left = new CANSparkMax(6, MotorType.kBrushless);
CANSparkMax Redline_Motor1 = new CANSparkMax(7, MotorType.kBrushed);
CANSparkMax Redline_Motor2 = new CANSparkMax(8, MotorType.kBrushed);
CANSparkMax UpMotor = new CANSparkMax(9, MotorType.kBrushless);
DifferentialDrive drive = new DifferentialDrive(Left_Leader, Right_Leader);
DigitalInput limitSwitch = new DigitalInput(9);
XboxController controller = new XboxController(0);
@Override
public void robotInit() {
timer = new Timer();
CameraServer.startAutomaticCapture();
isButton3Pressed = false;
startTime = 0;
realTime = 0;
}
@Override
public void robotPeriodic() {
Left_Follower.follow(Left_Leader);
Right_Follower.follow(Right_Leader);
}
@Override
public void autonomousInit() {
timer.reset();
timer.start();
isButton3Pressed = false;
startTime = System.currentTimeMillis();
Intech_Left.set(1);
Intech_Right.set(1);
}
@Override
public void autonomousPeriodic() {
// Autonomous code remains the same
// ... [previous autonomous code remains unchanged]
}
@Override
public void teleopInit() {
}
@Override
public void teleopPeriodic() {
// Using Xbox controller sticks for drive
// Left stick Y for forward/backward, Right stick X for rotation
drive.arcadeDrive(
-controller.getRightX() * 0.5,
-controller.getLeftY() * 0.5
);
// Button mappings:
// A Button (1) -> Previous Button 1
// X Button (3) -> Previous Button 3
// Right Bumper (6) -> Previous Button 8
// B Button (2) -> Previous Button 2
// Y Button (4) -> Previous Button 4
// Left Bumper (5) -> Previous Button 5
// Back Button -> Previous Button 6
if (controller.getAButton()) {
Redline_Motor1.set(1); // Redline Motor hızı
}
else if (controller.getXButton()) {
if (!isButton3Pressed) {
isButton3Pressed = true;
startTime = System.currentTimeMillis();
}
if (System.currentTimeMillis() - startTime <= 200) {
Redline_Motor1.set(-0.25);
} else if (System.currentTimeMillis() - startTime >= 500) {
Intech_Left.set(0.5);
Intech_Right.set(0.5);
if (System.currentTimeMillis() - startTime >= 1500) {
Redline_Motor1.set(0.5);
}
}
}
else if (controller.getRightBumper()) {
Redline_Motor1.set(-0.25);
}
else if (controller.getBButton()) {
Redline_Motor2.set(0.25);
}
else if (controller.getYButton()) {
Redline_Motor2.set(-0.25);
}
else if (controller.getLeftBumper()) {
UpMotor.set(0.25);
}
else if (controller.getBackButton()) {
if (limitSwitch.get()) {
// We are going up and top limit is tripped so stop
UpMotor.set(-0.25);
} else {
// We are going up but top limit is not tripped so go at commanded speed
UpMotor.set(0);
}
}
else {
isButton3Pressed = false;
Intech_Right.set(0);
Intech_Left.set(0);
Redline_Motor1.set(0);
Redline_Motor2.set(0);
UpMotor.set(0);
}
}
@Override
public void disabledInit() {
}
@Override
public void disabledPeriodic() {
}
@Override
public void testInit() {
}
@Override
public void testPeriodic() {
}
@Override
public void simulationInit() {
}
@Override
public void simulationPeriodic() {
}
}