huyle125 / 5027-Robot-Code

0 stars 0 forks source link

2016 Robot Drive Code #1

Open huyle125 opened 8 years ago

huyle125 commented 8 years ago
package org.usfirst.frc.team5027.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.RobotDrive;

public class Robot extends IterativeRobot {//This is where you make variables
    Joystick JoyOne;

    Talon FrontLeftMotor;
    Talon FrontRightMotor;
    Talon BackLeftMotor;
    Talon BackRightMotor;

    final int PwmOne = 1;
    final int PwmTwo = 2;
    final int PwmThree = 3;
    final int PwmFour = 4;
    final int JoyInput = 1;
    RobotDrive Drive;

    public void robotInit() {//This is where you initialize the variables
        FrontLeftMotor = new Talon(PwmOne);
        FrontRightMotor = new Talon(PwmTwo);
        BackLeftMotor = new Talon(PwmThree);
        BackRightMotor = new Talon(PwmFour);
        JoyOne = new Joystick(JoyInput);
        Drive = new RobotDrive(FrontLeftMotor, BackLeftMotor, FrontRightMotor, BackRightMotor);
        Drive.setInvertedMotor(RobotDrive.MotorType.kFrontLeft, true);
        Drive.setInvertedMotor(RobotDrive.MotorType.kRearLeft, true);
        Drive.setInvertedMotor(RobotDrive.MotorType.kFrontRight, true);
        Drive.setInvertedMotor(RobotDrive.MotorType.kRearRight, true);

    }

    public void autonomousInit() {

    }

    public void autonomousPeriodic() {//This is where you auto Code Run

    }

    public void teleopInit(){

    }

    public void teleopPeriodic() {//This is where your control Code Run.
        Drive.arcadeDrive(JoyOne);

       if (JoyOne.getRawButton(1)){
           FrontLeftMotor.set(1.0);
           BackLeftMotor.set(1.0);
       }
       else {
           FrontLeftMotor.set(0.0);
           BackLeftMotor.set(0.0);
       }
       if (JoyOne.getRawButton(2)){
           FrontRightMotor.set(1.0);
           BackRightMotor.set(1.0);
       }
       else {
           FrontRightMotor.set(0.0);
           BackRightMotor.set(0.0);
       }
    }

    public void testPeriodic() {//This is where you Test Code Run

    }

}
huyle125 commented 8 years ago

2/16/16 Code

package org.usfirst.frc.team5027.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.RobotDrive;

import edu.wpi.first.wpilibj.CameraServer;

public class Robot extends IterativeRobot {//This is where you make variables

    RobotDrive Drive;
    Joystick JoyOne;

    //Motor Controller
    Victor FrontLeftMotor;
    Victor FrontRightMotor;
    Victor BackLeftMotor;
    Victor BackRightMotor;

    //Pwm Slots
    final int PwmOne = 1;
    final int PwmTwo = 2;
    final int PwmThree = 3;
    final int PwmFour = 4;

    final int JoyInput = 1;

    CameraServer server;

    public void robotInit() {//This is where you initialize the variables
        FrontLeftMotor = new Victor(PwmOne);
        BackLeftMotor = new Victor(PwmTwo);
        FrontRightMotor = new Victor(PwmThree);
        BackRightMotor = new Victor(PwmFour);

        Drive = new RobotDrive(FrontLeftMotor, BackLeftMotor, FrontRightMotor, BackRightMotor);
        Drive.setInvertedMotor(RobotDrive.MotorType.kFrontLeft, true);
        Drive.setInvertedMotor(RobotDrive.MotorType.kRearLeft, true);
        Drive.setInvertedMotor(RobotDrive.MotorType.kFrontRight, true);
        Drive.setInvertedMotor(RobotDrive.MotorType.kRearRight, true);

        JoyOne = new Joystick(JoyInput);

        server = CameraServer.getInstance();
        server.setQuality(50);

        server.startAutomaticCapture("cam0");

    }

    public void autonomousInit() {

    }

    public void autonomousPeriodic() {//This is where you auto Code Run

    }

    public void teleopInit(){

    }

    public void teleopPeriodic() {//This is where your control Code Run.

        if (JoyOne.getRawButton(1)){
            Drive.arcadeDrive(JoyOne.getY()/2.0, JoyOne.getX()/2.0);
        }
        else {
            Drive.arcadeDrive(JoyOne);
        }

    }

    public void testPeriodic() {//This is where you Test Code Run

    }

}