diff --git a/build.gradle b/build.gradle index ef15cb6..06320ab 100644 --- a/build.gradle +++ b/build.gradle @@ -42,17 +42,20 @@ def includeDesktopSupport = false // Maven central needed for JUnit repositories { + maven { url "https://jitpack.io" } mavenCentral() } // Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries. // Also defines JUnit 4. dependencies { + compile 'com.github.WilliamAHartman:Jamepad:1.3.2' compile wpi.deps.wpilib() compile wpi.deps.vendor.java() nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio) nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop) testCompile 'junit:junit:4.12' + } // Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar') diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/frc/robot/OI.java b/src/main/java/frc/robot/OI.java index 5d57329..2704532 100644 --- a/src/main/java/frc/robot/OI.java +++ b/src/main/java/frc/robot/OI.java @@ -1,42 +1,20 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ package frc.robot; +import com.studiohartman.jamepad.ControllerManager; -/** - * This class is the glue that binds the controls on the physical operator - * interface to the commands and command groups that allow control of the robot. - */ -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: +import edu.wpi.first.wpilibj.Joystick; - // 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()); +public class OI { + private Joystick driverController = new Joystick(RobotMap.DRIVER_CONTROLLER); + private static ControllerManager controller = new ControllerManager(); + public double GetDriverRawAxis(int axis){ + return driverController.getRawAxis(axis); - // 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()); + public OI(){ + controller.initSDLGamepad(); + } } + diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index 6cf3ffa..906c22f 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -7,14 +7,17 @@ package frc.robot; +//import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX; + import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.command.Scheduler; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; -import frc.robot.commands.ExampleCommand; import frc.robot.subsystems.DriveTrain; -import frc.robot.subsystems.ExampleSubsystem; + +//import frc.robot.subsystems.DriveTrain; + /** * The VM is configured to automatically run this class, and to call the @@ -24,22 +27,26 @@ * project. */ public class Robot extends TimedRobot { - public static ExampleSubsystem m_subsystem = new ExampleSubsystem(); + public static DriveTrain driveTrain = new DriveTrain(); public static OI m_oi; - public static DriveTrain drivetrain; + //public static WPI_TalonSRX leftMotor1 = new WPI_TalonSRX(RobotMap.leftMotor1); + //public static WPI_TalonSRX leftMotor12 = new WPI_TalonSRX(RobotMap.leftMotor2); + //public static WPI_TalonSRX rightMotor1 = new WPI_TalonSRX(RobotMap.rightMotor1); + //public static WPI_TalonSRX rightMotor2 = new WPI_TalonSRX(RobotMap.rightMotor2); + //public static DriveTrain drivetrain; + Command m_autonomousCommand; SendableChooser m_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() { - drivetrain = new DriveTrain(); + //drivetrain = new DriveTrain(); m_oi = new OI(); - m_chooser.setDefaultOption("Default Auto", new ExampleCommand()); + // chooser.addOption("My Auto", new MyAutoCommand()); SmartDashboard.putData("Auto mode", m_chooser); //robot initialization goes here. YAY diff --git a/src/main/java/frc/robot/RobotMap.java b/src/main/java/frc/robot/RobotMap.java index 45360e4..0bb7e4c 100644 --- a/src/main/java/frc/robot/RobotMap.java +++ b/src/main/java/frc/robot/RobotMap.java @@ -23,4 +23,19 @@ public class RobotMap { // number and the module. For example you with a rangefinder: // public static int rangefinderPort = 1; // public static int rangefinderModule = 1; + public static final int Motor_Left_1_ID = 1; + public static final int Motor_Left_2_ID = 3; + public static final int Motor_Right_1_ID = 2; + public static final int Motor_Right_2_ID = 4; + public static final int DRIVER_CONTROLLER = 0; +public static final int LEFT_STICK_Y = 1; +public static final int LEFT_STICK_X = 2; +public static final int RIGHT_STICK_Y = 5; + +public static final int ONLY_STICKY = 0; +public static final int ONLY_STICKX = 0; +public static final int RIGHT_STICK_X = 0; +public static final int JOYSTICK_CONTROLLER = 0; + + } diff --git a/src/main/java/frc/robot/commands/Arcade_Drive.java b/src/main/java/frc/robot/commands/Arcade_Drive.java new file mode 100644 index 0000000..b1a88d9 --- /dev/null +++ b/src/main/java/frc/robot/commands/Arcade_Drive.java @@ -0,0 +1,60 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package frc.robot.commands; + +import edu.wpi.first.wpilibj.command.Command; +import frc.robot.Robot; +import frc.robot.RobotMap; + +public class Arcade_Drive extends Command { + public Arcade_Drive() { + // Use requires() here to declare subsystem dependencies + + requires(Robot.driveTrain); + } + + // Called just before this Command runs the first time + @Override + protected void initialize() { + } + + // Called repeatedly when this Command is scheduled to run + @Override + protected void execute() { + double leftstickY = Robot.m_oi.GetDriverRawAxis(RobotMap.LEFT_STICK_Y); + double leftstickX = Robot.m_oi.GetDriverRawAxis(RobotMap.RIGHT_STICK_X); + Robot.driveTrain.setLeftMotors(leftstickY*0.5); + Robot.driveTrain.setRightMotors(leftstickY*0.5); + if (leftstickX < 0){ + Robot.driveTrain.setLeftMotors(leftstickY*0.5); + Robot.driveTrain.setRightMotors(leftstickY*0.1); + if (leftstickX > 0){ + Robot.driveTrain.setRightMotors(leftstickY*0.5); + Robot.driveTrain.setLeftMotors(leftstickY*0.1); + } + } + } + // Make this return true when this Command no longer needs to run execute() + @Override + protected boolean isFinished() { + return false; + } + + // Called once after isFinished returns true + @Override + protected void end() { + Robot.driveTrain.setLeftMotors(0); + Robot.driveTrain.setRightMotors(0); + } + + // Called when another command which requires one or more of the same + // subsystems is scheduled to run + @Override + protected void interrupted() { + } +} diff --git a/src/main/java/frc/robot/commands/ExampleCommand.java b/src/main/java/frc/robot/commands/TankDrive.java similarity index 68% rename from src/main/java/frc/robot/commands/ExampleCommand.java rename to src/main/java/frc/robot/commands/TankDrive.java index 83a3fcc..5e46816 100644 --- a/src/main/java/frc/robot/commands/ExampleCommand.java +++ b/src/main/java/frc/robot/commands/TankDrive.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -9,14 +9,12 @@ import edu.wpi.first.wpilibj.command.Command; import frc.robot.Robot; +import frc.robot.RobotMap; -/** - * An example command. You can replace me with your own command. - */ -public class ExampleCommand extends Command { - public ExampleCommand() { +public class TankDrive extends Command { + public TankDrive() { // Use requires() here to declare subsystem dependencies - requires(Robot.m_subsystem); + requires(Robot.driveTrain); } // Called just before this Command runs the first time @@ -27,6 +25,11 @@ protected void initialize() { // Called repeatedly when this Command is scheduled to run @Override protected void execute() { + double leftstickY = Robot.m_oi.GetDriverRawAxis(RobotMap.LEFT_STICK_Y); + double rightstickY = Robot.m_oi.GetDriverRawAxis(RobotMap.RIGHT_STICK_Y); + + Robot.driveTrain.setLeftMotors(leftstickY*0.5); + Robot.driveTrain.setRightMotors(rightstickY*0.5); } // Make this return true when this Command no longer needs to run execute() @@ -38,11 +41,15 @@ protected boolean isFinished() { // Called once after isFinished returns true @Override protected void end() { + + Robot.driveTrain.setLeftMotors(0); + Robot.driveTrain.setRightMotors(0); } // Called when another command which requires one or more of the same // subsystems is scheduled to run @Override protected void interrupted() { + this.end(); } } diff --git a/src/main/java/frc/robot/subsystems/DriveTrain.java b/src/main/java/frc/robot/subsystems/DriveTrain.java index 567be5b..bba4305 100644 --- a/src/main/java/frc/robot/subsystems/DriveTrain.java +++ b/src/main/java/frc/robot/subsystems/DriveTrain.java @@ -12,6 +12,8 @@ import com.ctre.phoenix.motorcontrol.can.VictorSPX; import edu.wpi.first.wpilibj.command.Subsystem; +import frc.robot.RobotMap; +import frc.robot.commands.Arcade_Drive; /** * Add your docs here. @@ -19,61 +21,23 @@ public class DriveTrain extends Subsystem { // Put methods for controlling this subsystem // here. Call these from Commands. - TalonSRX rightMotor1; - VictorSPX rightMotor2; - TalonSRX leftMotor1; - VictorSPX leftMotor2; - - private double leftSpeed; - private double rightSpeed; - - public DriveTrain(){ - rightMotor1 = new TalonSRX(1); - rightMotor2 = new VictorSPX(2); - leftMotor1 = new TalonSRX(30); - leftMotor2 = new VictorSPX(4); - } - - public void tankDrive(double left, double right){ - - if(left > 1){ - left = 1; - } else if(left < -1){ - left = -1; - } else { - // these are valid inputs. do we want to change them? - if(left < 0){ - left = -left*left; - }else { - left = left*left; - } - } - if(right > 1){ - right = 1; - } else if(right < -1){ - right = -1; - } else { - // these are valid inputs. do we want to change them? - if(right < 0){ - right = -right*right; - }else { - right = right*right; - } - } - - leftSpeed = left; - rightSpeed = right; - - rightMotor1.set(ControlMode.PercentOutput, rightSpeed); - rightMotor2.set(ControlMode.PercentOutput, rightSpeed); - leftMotor1.set(ControlMode.PercentOutput, leftSpeed); - leftMotor2.set(ControlMode.PercentOutput, leftSpeed); - - } + private TalonSRX motorLeft1 = new TalonSRX(RobotMap.Motor_Left_1_ID); + private VictorSPX motorLeft2 = new VictorSPX(RobotMap.Motor_Left_2_ID); + private TalonSRX motorRight1 = new TalonSRX(RobotMap.Motor_Right_1_ID); + private VictorSPX motorRight2 = new VictorSPX(RobotMap.Motor_Right_2_ID); @Override public void initDefaultCommand() { // Set the default command for a subsystem here. - // setDefaultCommand(new MySpecialCommand()); + setDefaultCommand(new Arcade_Drive()); + } + + public void setLeftMotors(double speed){ + motorLeft1.set(ControlMode.PercentOutput, speed); + motorLeft2.set(ControlMode.PercentOutput, speed); + } + public void setRightMotors(double speed){ + motorRight1.set(ControlMode.PercentOutput, -speed); + motorRight2.set(ControlMode.PercentOutput, -speed); } }