Skip to content
This repository was archived by the owner on Jan 18, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/OI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions PiyushOMatic/src/org/usfirst/frc2974/PiyushOMatic/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
}

/**
Expand Down Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down