From e5d3d4e58c98119fc8450d30f4fcb493fce60888 Mon Sep 17 00:00:00 2001 From: Susan R Hallstead <57297286+Savage485@users.noreply.github.com> Date: Sat, 2 Nov 2019 14:32:41 -0600 Subject: [PATCH 1/5] Tank Drive!! --- gradlew | 0 src/main/java/frc/robot/OI.java | 7 ++ src/main/java/frc/robot/Robot.java | 21 ++++-- src/main/java/frc/robot/RobotMap.java | 9 +++ .../{ExampleCommand.java => TankDrive.java} | 20 ++++-- .../java/frc/robot/subsystems/DriveTrain.java | 69 +++++-------------- 6 files changed, 59 insertions(+), 67 deletions(-) mode change 100644 => 100755 gradlew rename src/main/java/frc/robot/commands/{ExampleCommand.java => TankDrive.java} (68%) 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..02dc7ba 100644 --- a/src/main/java/frc/robot/OI.java +++ b/src/main/java/frc/robot/OI.java @@ -7,11 +7,18 @@ package frc.robot; +import edu.wpi.first.wpilibj.XboxController; + /** * 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 { + private XboxController driverController = new XboxController(RobotMap.DRIVER_CONTROLLER); + + public double GetDriverRawAxis(int axis){ + return driverController.getRawAxis(axis); + } //// CREATING BUTTONS // One type of button is a joystick button which is any button on a //// joystick. 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..f14056b 100644 --- a/src/main/java/frc/robot/RobotMap.java +++ b/src/main/java/frc/robot/RobotMap.java @@ -23,4 +23,13 @@ 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 = 0; + public static final int Motor_Left_2_ID = 1; + public static final int Motor_Right_1_ID = 2; + public static final int Motor_Right_2_ID = 3; + public static final int DRIVER_CONTROLLER = 0; +public static final int LEFT_STICK_Y = 1; +public static final int RIGHT_STICK_Y = 5; + + } 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..9e3ab8e 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,14 @@ 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..6e43d4e 100644 --- a/src/main/java/frc/robot/subsystems/DriveTrain.java +++ b/src/main/java/frc/robot/subsystems/DriveTrain.java @@ -9,9 +9,10 @@ import com.ctre.phoenix.motorcontrol.ControlMode; import com.ctre.phoenix.motorcontrol.can.TalonSRX; -import com.ctre.phoenix.motorcontrol.can.VictorSPX; import edu.wpi.first.wpilibj.command.Subsystem; +import frc.robot.RobotMap; +import frc.robot.commands.TankDrive; /** * Add your docs here. @@ -19,61 +20,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 TalonSRX motorLeft2 = new TalonSRX(RobotMap.Motor_Left_2_ID); + private TalonSRX motorRight1 = new TalonSRX(RobotMap.Motor_Right_1_ID); + private TalonSRX motorRight2 = new TalonSRX(RobotMap.Motor_Right_2_ID); @Override public void initDefaultCommand() { // Set the default command for a subsystem here. - // setDefaultCommand(new MySpecialCommand()); + setDefaultCommand(new TankDrive()); + } + + 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); } } From 97244dd4f7e6a96a4b7338c89f2a45c08e0cedfb Mon Sep 17 00:00:00 2001 From: Susan R Hallstead <57297286+Savage485@users.noreply.github.com> Date: Fri, 15 Nov 2019 17:32:30 -0700 Subject: [PATCH 2/5] push --- src/main/java/frc/robot/RobotMap.java | 6 +++--- src/main/java/frc/robot/commands/TankDrive.java | 1 + src/main/java/frc/robot/subsystems/DriveTrain.java | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/frc/robot/RobotMap.java b/src/main/java/frc/robot/RobotMap.java index f14056b..d8e2117 100644 --- a/src/main/java/frc/robot/RobotMap.java +++ b/src/main/java/frc/robot/RobotMap.java @@ -23,10 +23,10 @@ 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 = 0; - public static final int Motor_Left_2_ID = 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 = 3; + 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 RIGHT_STICK_Y = 5; diff --git a/src/main/java/frc/robot/commands/TankDrive.java b/src/main/java/frc/robot/commands/TankDrive.java index 9e3ab8e..5e46816 100644 --- a/src/main/java/frc/robot/commands/TankDrive.java +++ b/src/main/java/frc/robot/commands/TankDrive.java @@ -41,6 +41,7 @@ protected boolean isFinished() { // Called once after isFinished returns true @Override protected void end() { + Robot.driveTrain.setLeftMotors(0); Robot.driveTrain.setRightMotors(0); } diff --git a/src/main/java/frc/robot/subsystems/DriveTrain.java b/src/main/java/frc/robot/subsystems/DriveTrain.java index 6e43d4e..3fe4318 100644 --- a/src/main/java/frc/robot/subsystems/DriveTrain.java +++ b/src/main/java/frc/robot/subsystems/DriveTrain.java @@ -9,7 +9,6 @@ import com.ctre.phoenix.motorcontrol.ControlMode; import com.ctre.phoenix.motorcontrol.can.TalonSRX; - import edu.wpi.first.wpilibj.command.Subsystem; import frc.robot.RobotMap; import frc.robot.commands.TankDrive; From 40d8423df35ade27cecef99e0418250ab64f7d00 Mon Sep 17 00:00:00 2001 From: Susan R Hallstead <57297286+Savage485@users.noreply.github.com> Date: Sat, 16 Nov 2019 10:49:53 -0700 Subject: [PATCH 3/5] Nice! --- build.gradle | 3 ++ src/main/java/frc/robot/OI.java | 47 ++++--------------- .../java/frc/robot/subsystems/DriveTrain.java | 10 ++-- 3 files changed, 17 insertions(+), 43 deletions(-) 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/src/main/java/frc/robot/OI.java b/src/main/java/frc/robot/OI.java index 02dc7ba..b83c45a 100644 --- a/src/main/java/frc/robot/OI.java +++ b/src/main/java/frc/robot/OI.java @@ -1,49 +1,18 @@ -/*----------------------------------------------------------------------------*/ -/* 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; import edu.wpi.first.wpilibj.XboxController; -/** - * 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 { private XboxController driverController = new XboxController(RobotMap.DRIVER_CONTROLLER); - + private static ControllerManager controller = new ControllerManager(); public double GetDriverRawAxis(int axis){ return driverController.getRawAxis(axis); + + + } + + public OI(){ + controller.initSDLGamepad(); } - //// 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()); } diff --git a/src/main/java/frc/robot/subsystems/DriveTrain.java b/src/main/java/frc/robot/subsystems/DriveTrain.java index 3fe4318..d125b3d 100644 --- a/src/main/java/frc/robot/subsystems/DriveTrain.java +++ b/src/main/java/frc/robot/subsystems/DriveTrain.java @@ -9,6 +9,8 @@ import com.ctre.phoenix.motorcontrol.ControlMode; import com.ctre.phoenix.motorcontrol.can.TalonSRX; +import com.ctre.phoenix.motorcontrol.can.VictorSPX; + import edu.wpi.first.wpilibj.command.Subsystem; import frc.robot.RobotMap; import frc.robot.commands.TankDrive; @@ -19,10 +21,10 @@ public class DriveTrain extends Subsystem { // Put methods for controlling this subsystem // here. Call these from Commands. - private TalonSRX motorLeft1 = new TalonSRX(RobotMap.Motor_Left_1_ID); - private TalonSRX motorLeft2 = new TalonSRX(RobotMap.Motor_Left_2_ID); - private TalonSRX motorRight1 = new TalonSRX(RobotMap.Motor_Right_1_ID); - private TalonSRX motorRight2 = new TalonSRX(RobotMap.Motor_Right_2_ID); + 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() { From 0cfb2eacb53511078be2cae1a5a1332f1e52c030 Mon Sep 17 00:00:00 2001 From: Susan R Hallstead <57297286+Savage485@users.noreply.github.com> Date: Sat, 16 Nov 2019 14:47:28 -0700 Subject: [PATCH 4/5] This is for Arcade Drive and Tank Drive. Right Now it is set to Arcade. --- src/main/java/frc/robot/OI.java | 9 ++- src/main/java/frc/robot/RobotMap.java | 6 ++ .../java/frc/robot/commands/Arcade_Drive.java | 60 +++++++++++++++++++ .../java/frc/robot/subsystems/DriveTrain.java | 4 +- 4 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 src/main/java/frc/robot/commands/Arcade_Drive.java diff --git a/src/main/java/frc/robot/OI.java b/src/main/java/frc/robot/OI.java index b83c45a..9cd3272 100644 --- a/src/main/java/frc/robot/OI.java +++ b/src/main/java/frc/robot/OI.java @@ -1,6 +1,8 @@ package frc.robot; import com.studiohartman.jamepad.ControllerManager; + + import edu.wpi.first.wpilibj.XboxController; public class OI { @@ -8,11 +10,12 @@ public class OI { private static ControllerManager controller = new ControllerManager(); public double GetDriverRawAxis(int axis){ return driverController.getRawAxis(axis); - - + } - + + public OI(){ controller.initSDLGamepad(); } } + diff --git a/src/main/java/frc/robot/RobotMap.java b/src/main/java/frc/robot/RobotMap.java index d8e2117..0bb7e4c 100644 --- a/src/main/java/frc/robot/RobotMap.java +++ b/src/main/java/frc/robot/RobotMap.java @@ -29,7 +29,13 @@ public class RobotMap { 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/subsystems/DriveTrain.java b/src/main/java/frc/robot/subsystems/DriveTrain.java index d125b3d..bba4305 100644 --- a/src/main/java/frc/robot/subsystems/DriveTrain.java +++ b/src/main/java/frc/robot/subsystems/DriveTrain.java @@ -13,7 +13,7 @@ import edu.wpi.first.wpilibj.command.Subsystem; import frc.robot.RobotMap; -import frc.robot.commands.TankDrive; +import frc.robot.commands.Arcade_Drive; /** * Add your docs here. @@ -29,7 +29,7 @@ public class DriveTrain extends Subsystem { @Override public void initDefaultCommand() { // Set the default command for a subsystem here. - setDefaultCommand(new TankDrive()); + setDefaultCommand(new Arcade_Drive()); } public void setLeftMotors(double speed){ From 3deb00125efcd6d805d5cc8d322796dfc42b0d61 Mon Sep 17 00:00:00 2001 From: Susan R Hallstead <57297286+Savage485@users.noreply.github.com> Date: Sat, 7 Dec 2019 09:50:57 -0700 Subject: [PATCH 5/5] h --- src/main/java/frc/robot/OI.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/frc/robot/OI.java b/src/main/java/frc/robot/OI.java index 9cd3272..2704532 100644 --- a/src/main/java/frc/robot/OI.java +++ b/src/main/java/frc/robot/OI.java @@ -2,11 +2,10 @@ package frc.robot; import com.studiohartman.jamepad.ControllerManager; - -import edu.wpi.first.wpilibj.XboxController; +import edu.wpi.first.wpilibj.Joystick; public class OI { - private XboxController driverController = new XboxController(RobotMap.DRIVER_CONTROLLER); + private Joystick driverController = new Joystick(RobotMap.DRIVER_CONTROLLER); private static ControllerManager controller = new ControllerManager(); public double GetDriverRawAxis(int axis){ return driverController.getRawAxis(axis);