Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package org.usfirst.frc.team295.robot;
import com.ctre.CANTalon;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
/**
* 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 {
RobotDrive myRobot; // class that handles basic drive operations
Joystick driver; // set to ID 1 in DriverStation
CANTalon driveBackLeft;
CANTalon driveBackRight;
CANTalon driveFrontLeft;
CANTalon driveFrontRight;
JoystickButton high;
JoystickButton low;
DoubleSolenoid shifter;
public static final DoubleSolenoid.Value GearHigh = DoubleSolenoid.Value.kReverse;
public static final DoubleSolenoid.Value GearLow = DoubleSolenoid.Value.kForward;
public Robot() {
driver = new Joystick(0);
driveBackLeft = new CANTalon(4);
driveFrontLeft = new CANTalon(3);
driveBackRight = new CANTalon(2);
driveFrontRight = new CANTalon(1);
Compressor c = new Compressor(0);
high = new JoystickButton(driver,2);
low = new JoystickButton(driver,1);
shifter = new DoubleSolenoid(0, 1);
shifter.set(GearHigh);
c.setClosedLoopControl(true);
myRobot = new RobotDrive(driveFrontLeft,driveBackLeft,driveFrontRight,driveBackRight);
myRobot.setInvertedMotor(RobotDrive.MotorType.kRearRight, true);
myRobot.setExpiration(0.1);
}
/**
* Runs the motors with tank steering.
*/
public void teleopPeriodic() {
// driveBackRight.set(1);
// driveFrontRight.set(1);
// driveBackLeft.set(1);
// driveFrontLeft.set(1);
while (isOperatorControl() && isEnabled()) {
myRobot.tankDrive(driver.getRawAxis(1), driver.getRawAxis(5));
Timer.delay(0.005); // wait for a motor update time
if(high.get()){
shifter.set(GearHigh);
}
if(low.get()){
shifter.set(GearLow);
}
}
}
public void disabled(){
System.out.println("disabled");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment