Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.usfirst.frc.team6725.robot;
- import edu.wpi.first.wpilibj.ADXRS450_Gyro;
- import edu.wpi.first.wpilibj.AnalogGyro;
- import edu.wpi.first.wpilibj.AnalogTrigger;
- import edu.wpi.first.wpilibj.CameraServer;
- import edu.wpi.first.wpilibj.Compressor;
- import edu.wpi.first.wpilibj.DoubleSolenoid;
- import edu.wpi.first.wpilibj.IterativeRobot;
- import edu.wpi.first.wpilibj.Joystick;
- import edu.wpi.first.wpilibj.RobotDrive;
- import edu.wpi.first.wpilibj.Timer;
- import edu.wpi.first.wpilibj.buttons.Button;
- import edu.wpi.first.wpilibj.buttons.JoystickButton;
- import edu.wpi.first.wpilibj.command.Command;
- import edu.wpi.first.wpilibj.command.Scheduler;
- import edu.wpi.first.wpilibj.interfaces.Gyro;
- import edu.wpi.first.wpilibj.livewindow.LiveWindow;
- import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
- import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
- //import java.util.Timer;
- //import org.usfirst.frc.team6725.robot.commands.ExampleCommand;
- //import org.usfirst.frc.team6725.robot.commands.Test;
- //import org.usfirst.frc.team6725.robot.commands.climbfalse;
- //import org.usfirst.frc.team6725.robot.commands.getXandY;
- //import org.usfirst.frc.team6725.robot.commands.stgfjgf;
- //import org.usfirst.frc.team6725.robot.commands.stopclimbing;
- import org.usfirst.frc.team6725.robot.subsystems.ExampleSubsystem;
- /**
- * The VM is configured to automatically run this class, and to call the
- * functions corresponding to each mode, as described in the IterativeRobot
- * documentation. If you change the name of this class or the package after
- * creating this project, you must also update the manifest file in the resource
- * directory.
- */
- public class Robot extends IterativeRobot {
- public static final ExampleSubsystem exampleSubsystem = new ExampleSubsystem();
- public static Boolean RBPressed;
- public static OI oi;
- public static RobotDrive myRobot = new RobotDrive(0, 1, 2, 3);
- public static RobotDrive ropeClimb = new RobotDrive(4,5);
- public static Joystick stick = new Joystick(0);
- //Joystick leftJoy = new Joystick(1);
- //Buttons
- public static Button buttonA = new JoystickButton(stick, 1);
- public static Button buttonX = new JoystickButton(stick, 3);
- public static Button buttonB = new JoystickButton(stick, 2);
- public static Button buttonRB = new JoystickButton(stick, 6);
- public static Button buttonY = new JoystickButton(stick, 4);
- public static Button buttonLB = new JoystickButton(stick, 5);
- public static Double yVal;
- public static Double ValX;
- //public static ADXRS450_Gyro Gyro = new ADXRS450_Gyro();
- //public static Double Angle = 0.0;
- public static boolean isclimbing=false;
- //public static double[] recordx = new double[9000];
- ////public static double[] recordy = new double[9000];
- public static int i=0;
- public static boolean isautodone = false;
- public static long t;
- public static long endforward;
- public static long endback;
- public static long topeg;
- public static double Kp = 0.03;
- private Gyro gyro;
- //Pneumatics
- public static Compressor comp = new Compressor(0);
- public static DoubleSolenoid dSol1 = new DoubleSolenoid(0,1);
- //public static AnalogTrigger trigger0 = new AnalogTrigger(0);
- Command autonomousCommand;
- SendableChooser<Command> chooser = new SendableChooser<>();
- /**
- * This function is run when the robot is first started up and should be
- * used for any initialization code.
- */
- @Override
- public void robotInit() {
- // oi = new OI();
- // chooser.addDefault("Default Auto", new ExampleCommand());
- // chooser.addObject("My Auto", new MyAutoCommand());
- // SmartDashboard.putData("Auto mode", chooser);
- CameraServer server = CameraServer.getInstance();
- CameraServer server1 = CameraServer.getInstance();
- server.startAutomaticCapture("cam" ,0);
- server1.startAutomaticCapture("cam1",1);
- // myRobot.setSafetyEnabled(false);
- //Pneumatics
- comp.setClosedLoopControl(true);
- }
- /**
- * This function is called once each time the robot enters Disabled mode.
- * You can use it to reset any subsystem information you want to clear when
- * the robot is disabled.
- */
- @Override
- public void disabledInit() {
- }
- // public Robot() {
- // gyro = new AnalogGyro(1);
- // }
- @Override
- public void disabledPeriodic() {
- Scheduler.getInstance().run();
- }
- /**
- * This autonomous (along with the chooser code above) shows how to select
- * between different autonomous modes using the dashboard. The sendable
- * chooser code works with the Java SmartDashboard. If you prefer the
- * LabVIEW Dashboard, remove all of the chooser code and uncomment the
- * getString code to get the auto name from the text box below the Gyro
- *
- * You can add additional auto modes by adding additional commands to the
- * chooser code above (like the commented example) or additional comparisons
- * to the switch structure below with additional strings & commands.
- */
- @Override
- public void autonomousInit() {
- t = System.currentTimeMillis();
- ////
- endforward = t + 4000; // original : 3400;
- endback = t + 5200;
- topeg = t + 10000;
- //autonomousCommand = chooser.getSelected();
- //seconds = 0;
- /*
- * String autoSelected = SmartDashboard.getString("Auto Selector",
- * "Default"); switch(autoSelected) { case "My Auto": autonomousCommand
- * = new MyAutoCommand(); break; case "Default Auto": default:
- * autonomousCommand = new ExampleCommand(); break; }
- */
- // schedule the autonomous command (example)
- //if (autonomousCommand != null)
- //autonomousCommand.start();
- gyro = new AnalogGyro(1);
- gyro.calibrate();
- gyro.reset();
- }
- /**
- * This function is called periodically during autonomous
- */
- @Override
- public void autonomousPeriodic() {
- //if (System.currentTimeMillis() <= endforward) {
- //double angle = gyro.getAngle();
- //myRobot.drive(0.3, 0.0000001);
- //}
- /*
- while (System.currentTimeMillis() <= endforward){
- myRobot.drive(0.3, 0.0000001);
- }*/
- // if (System.currentTimeMillis() <= endback && System.currentTimeMillis() > endforward){
- // myRobot.drive(-0.4, -0.39); // original (-.4 , -0.39)
- // }
- //
- // if (System.currentTimeMillis() >= endback && System.currentTimeMillis() < topeg){
- // myRobot.drive(0.3, 0.0000001);
- // //gyro.reset();
- // //double angle = gyro.getAngle();
- // // System.out.println(angle*Kp);
- // }
- /*
- isautodone=true;
- if (isautodone==true)
- myRobot.drive(0, 0);*/
- /*while (System.currentTimeMillis() <= endback & System.currentTimeMillis() > endforward){
- myRobot.drive(-0.3, -0.0000001);
- }
- System.exit(0);*/
- // for(i=0;i<=5000;i++){
- // myRobot.drive(0.3, 0.0000001);
- //myRobot.drive(0.3, 0.0000001);
- /*while (seconds < 8){
- if(seconds <= 4){
- myRobot.drive(0.3, 0.0000001);
- seconds ++;
- //edu.wpi.first.wpilibj.Timer.delay(1);
- } else if (seconds > 4 & seconds < 8){
- myRobot.drive(-0.3, 0);
- seconds ++;
- // edu.wpi.first.wpilibj.Timer.delay(1);
- } else if (seconds >= 8){
- myRobot.drive(0, 0);
- seconds ++;
- }
- System.gc();
- Timer.delay(1);
- System.out.println(seconds);
- }*/
- /*for(int i = 0; i >= 8000; i++){
- if (i <= 4000){
- myRobot.drive(0.3, 0.0000001);
- } else if (i > 4000 & i < 8000){
- myRobot.drive(-0.3, 0.0);
- } else if (i == 8000){
- myRobot.drive(0, 0);
- }
- edu.wpi.first.wpilibj.Timer.delay(0.001);
- }*/
- /* Timer timeAuto = new Timer();
- TimerTask AutoMovement = new TimerTask(){
- @Override
- public void run() {
- // TODO Auto-generated method stub
- //seconds ++;
- if(seconds == 0){
- myRobot.drive(0.3, 0.0000001);
- seconds ++;
- edu.wpi.first.wpilibj.Timer.delay(1000);
- } else if (seconds == 1){
- myRobot.drive(-0.3, 0);
- seconds ++;
- edu.wpi.first.wpilibj.Timer.delay(1000);
- } else if (seconds > 2){
- timeAuto.cancel();
- timeAuto.purge();
- }
- System.gc();
- System.out.println(seconds);
- //edu.wpi.first.wpilibj.Timer.delay(1);
- }
- /*
- };
- timeAuto.scheduleAtFixedRate(AutoMovement, 0, 4000);*/
- gyro.reset();
- while (isAutonomous()){
- double angle = gyro.getAngle();
- myRobot.drive(-1, -angle*Kp);
- Timer.delay(0.004);
- }
- myRobot.drive(0.0, 0.0);
- }
- @Override
- public void teleopInit() {
- myRobot.drive(0, 0);
- // This makes sure that the autonomous stops running when
- // teleop starts running. If you want the autonomous to
- // continue until interrupted by another command, remove
- // this line or comment it out.
- //if (autonomousCommand != null)
- //autonomousCommand.cancel();
- }
- /**
- * This function is called periodically during operator control
- */
- @Override
- public void teleopPeriodic() {
- // Scheduler.getInstance().run();
- //buttonY.whileHeld(new Test());
- // System.out.println("X: " + stick.getX());
- // System.out.println("Y: " + stick.getY());
- // buttonLB.whileHeld(new getXandY());
- // buttonB.whileHeld(new climbfalse());
- //buttonB.whenReleased(new stopclimbing());
- // if(Robot.stick.getRawAxis(5)>0){
- // Robot.ropeClimb.arcadeDrive(-Robot.stick.getRawAxis(5), 0);
- // }
- //Pneumatics - Button A to extend, Button B to retract
- if(Robot.stick.getRawButton(1)){
- dSol1.set(DoubleSolenoid.Value.kForward);
- } else if (Robot.stick.getRawButton(2)){
- dSol1.set(DoubleSolenoid.Value.kReverse);
- }
- if(Robot.stick.getRawAxis(3)>0.5){
- Robot.ropeClimb.arcadeDrive(-Robot.stick.getRawAxis(3)*1.1, 0);
- }
- myRobot.arcadeDrive(-stick.getY(), -stick.getX());}
- /**
- * This function is called periodically during test mode
- */
- @Override
- public void testPeriodic() {
- LiveWindow.run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement