diff --git a/PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/OI.java b/PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/OI.java index 7fa8c43..d320194 100644 --- a/PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/OI.java +++ b/PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/OI.java @@ -23,33 +23,33 @@ */ @SuppressWarnings("unused") public class OI { - //// CREATING BUTTONS - // One type of button is a joystick button which is any button on a joystick. - // You create one by telling it which joystick it's on and which button - // number it is. - // Joystick stick = new Joystick(port); - // Button button = new JoystickButton(stick, buttonNumber); - - // There are a few additional built in buttons you can use. Additionally, - // by subclassing Button you can create custom triggers and bind those to - // commands the same as any other Button. - - //// TRIGGERING COMMANDS WITH BUTTONS - // Once you have a button, it's trivial to bind it to a button in one of - // three ways: - - // Start the command when the button is pressed and let it run the command - // until it is finished as determined by it's isFinished method. - // button.whenPressed(new ExampleCommand()); - - // Run the command while the button is being held down and interrupt it once - // the button is released. - // button.whileHeld(new ExampleCommand()); - - // Start the command when the button is released and let it run the command - // until it is finished as determined by it's isFinished method. + //// CREATING BUTTONS + // One type of button is a joystick button which is any button on a joystick. + // You create one by telling it which joystick it's on and which button + // number it is. + // Joystick stick = new Joystick(port); + // Button button = new JoystickButton(stick, buttonNumber); + + // There are a few additional built in buttons you can use. Additionally, + // by subclassing Button you can create custom triggers and bind those to + // commands the same as any other Button. + + //// TRIGGERING COMMANDS WITH BUTTONS + // Once you have a button, it's trivial to bind it to a button in one of + // three ways: + + // Start the command when the button is pressed and let it run the command + // until it is finished as determined by it's isFinished method. + // button.whenPressed(new ExampleCommand()); + + // Run the command while the button is being held down and interrupt it once + // the button is released. + // button.whileHeld(new ExampleCommand()); + + // Start the command when the button is released and let it run the command + // until it is finished as determined by it's isFinished method. // button.whenReleased(new ExampleCommand()); - + // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS public Joystick left; diff --git a/PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/Robot.java b/PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/Robot.java index 1ac2cee..cf0e318 100644 --- a/PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/Robot.java +++ b/PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/Robot.java @@ -11,7 +11,9 @@ package org.usfirst.frc2974.PiyushOMatic; +import edu.wpi.first.wpilibj.CameraServer; import edu.wpi.first.wpilibj.IterativeRobot; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.command.Scheduler; import edu.wpi.first.wpilibj.livewindow.LiveWindow; @@ -33,6 +35,10 @@ public class Robot extends IterativeRobot { public Command autonomousCommand; + + //camera + CameraServer server; + public static OI oi; // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS public static DriveTrain driveTrain; @@ -61,6 +67,12 @@ public void robotInit() { // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS // autonomousCommand = new ForwardForFeet(5); // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS + + //camera + server = CameraServer.getInstance(); + server.setQuality(50); + //the camera name (ex "cam0") can be found through the roborio web interface + server.startAutomaticCapture("cam0"); } /** @@ -116,4 +128,17 @@ public void teleopPeriodic() { public void testPeriodic() { LiveWindow.run(); } + + + /** + * start up automatic capture you should see the video stream from the + * webcam in your FRC PC Dashboard. + */ + public void operatorControl() { + + while (isOperatorControl() && isEnabled()) { + /** robot code here! **/ + Timer.delay(0.005); // wait for a motor update time + } + } } diff --git a/PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/autonomous/ForwardForFeet.java b/PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/autonomous/ForwardForFeet.java index fdb1b19..e6af857 100644 --- a/PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/autonomous/ForwardForFeet.java +++ b/PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/autonomous/ForwardForFeet.java @@ -20,14 +20,33 @@ protected void initialize() { // Called repeatedly when this Command is scheduled to run protected void execute() { - Robot.driveTrain.set(1, 1); + //makes the robot end up parallel to it's start position + if(!isFinishedLeft()) + { + if(!isFinishedRight()) + Robot.driveTrain.set(1, 1); + else + Robot.driveTrain.set(1,0); + } + else if(!isFinishedRight()) + Robot.driveTrain.set(0, 1); + } // Make this return true when this Command no longer needs to run execute() protected boolean isFinished() { - return Robot.driveTrain.getDistanceTravelled()>=feetToTravel*12; + return isFinishedLeft() && isFinishedRight(); + } + protected boolean isFinishedLeft() + { + return Robot.driveTrain.getDistanceTravelledLeft()>=feetToTravel*12; + } + + protected boolean isFinishedRight() + { + return Robot.driveTrain.getDistanceTravelledRight()>=feetToTravel*12; } boolean isDead=false;