From b5d1f1a00d0e143d8396ea100a327c0fd66b9815 Mon Sep 17 00:00:00 2001 From: Kevin Palani Date: Thu, 18 Jan 2018 15:30:56 -0800 Subject: [PATCH 1/2] Initial Commit :) --- src/org/usfirst/frc/team2854/robot/Robot.java | 2 +- .../team2854/robot/subsystems/DriveTrain.java | 75 ++++++++++++++++++- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/src/org/usfirst/frc/team2854/robot/Robot.java b/src/org/usfirst/frc/team2854/robot/Robot.java index 184446a..f02d381 100644 --- a/src/org/usfirst/frc/team2854/robot/Robot.java +++ b/src/org/usfirst/frc/team2854/robot/Robot.java @@ -49,7 +49,7 @@ public void robotInit() { if(s instanceof Restartabale) { ((Restartabale) s).enable(); } - } + } } /** diff --git a/src/org/usfirst/frc/team2854/robot/subsystems/DriveTrain.java b/src/org/usfirst/frc/team2854/robot/subsystems/DriveTrain.java index 26f8459..e1933bf 100644 --- a/src/org/usfirst/frc/team2854/robot/subsystems/DriveTrain.java +++ b/src/org/usfirst/frc/team2854/robot/subsystems/DriveTrain.java @@ -2,6 +2,8 @@ import java.util.Random; +import javax.xml.bind.ValidationEvent; + import org.usfirst.frc.team2854.robot.Config; import org.usfirst.frc.team2854.robot.DummyPIDOutput; import org.usfirst.frc.team2854.robot.OI; @@ -43,10 +45,16 @@ public class DriveTrain extends Subsystem implements Restartabale { private DoubleSolenoid shifter; + /** + * Method that initializes the default command to JoyStickDrive. + */ public void initDefaultCommand() { setDefaultCommand(new JoystickDrive()); } + /** + * Method that enables the drive train. + */ public void enable() { System.out.println("Enabling drive train"); turnController.enable(); @@ -58,11 +66,17 @@ public void enable() { shift(startingGear); } + /** + * Method that disables the drive train. + */ public void disable() { System.out.println("Disableing drive train"); turnController.disable(); } + /** + * Default constructor. + */ public DriveTrain() { leftT1 = new TalonSRX(RobotMap.leftTalonID1); leftT1.setInverted(side); @@ -97,7 +111,11 @@ public DriveTrain() { rightT1.set(ControlMode.Follower, rightT2.getDeviceID()); } - + + /** + * Method that sets the PID values on shift. + * @param value - DoubleSolenoid.Value object + */ public void shift(DoubleSolenoid.Value value) { double P_Drive = .28; @@ -120,9 +138,18 @@ public void shift(DoubleSolenoid.Value value) { } updatePID(rightT2, P_Drive, I_Drive, D_Drive, F_Drive); updatePID(leftT2, P_Drive, I_Drive, D_Drive, F_Drive); - + SmartDashboard.putBoolean("Low Gear", value.equals(Value.kForward)); } - + //hypms + + /** + * Method that updates PID values + * @param talon - Talon object + * @param P - proportional gain + * @param I - integral gain + * @param D - derivative gain + * @param F - feed forward term + */ private void updatePID(TalonSRX talon, double P, double I, double D, double F) { final int timeOutConstant = 10; final int PIDIndex = 0; @@ -132,6 +159,15 @@ private void updatePID(TalonSRX talon, double P, double I, double D, double F) { talon.config_kF(PIDIndex, F, timeOutConstant); } + /** + * Method that configures a Talon to use specified PID values. + * @param talon - Talon object + * @param P - proportional gain + * @param I - integral gain + * @param D - derivative gain + * @param F - feed forward term + * @param side + */ private void configureTalon(TalonSRX talon, double P, double I, double D, double F, boolean side) { final int timeOutConstant = 10; @@ -161,6 +197,13 @@ private void configureTalon(TalonSRX talon, double P, double I, double D, double } + /** + * Method that initializes PID values when turning + * @param P - proportional gain + * @param I - integral gain + * @param D - derivative gain + * @param F - feed forward term + */ public void initTurnPID(double P, double I, double D, double F) { PIDSource turnSource = new PIDSource() { @@ -196,6 +239,9 @@ public PIDSourceType getPIDSourceType() { } + /** + * Method that writes to SmartDashboard + */ public void writeToDashBoard() { SmartDashboard.putNumber("Left Velocity", leftT2.getSelectedSensorVelocity(0)); @@ -211,6 +257,9 @@ public void writeToDashBoard() { } + /** + * Method that shifts gears. + */ public void toggleShift() { if (shifter.get() == Value.kForward) { shifter.set(Value.kReverse); @@ -225,6 +274,12 @@ public void toggleShift() { } + /** + * Method that drives. + * @param left - input percentage + * @param right - input percentage + * @param mode - ControlMode object that specifies ControlMode + */ public void drive(double left, double right, ControlMode mode) { if(mode.equals(ControlMode.Velocity)) { @@ -242,6 +297,12 @@ public void drive(double left, double right, ControlMode mode) { } + /** + * Method that drives straight. + * @param left - input percentage + * @param right - input percentage + * @param mode - ControlMode object that specifies ControlMode + */ public void driveStraight(double left, double right, ControlMode mode) { double output = turnController.get(); System.out.println(output); @@ -250,10 +311,18 @@ public void driveStraight(double left, double right, ControlMode mode) { } + /** + * Method that drives at the PercentOutput Control Mode. + * @param left - input percentage + * @param right - input percentage + */ public void drive(double left, double right) { drive(left, right, ControlMode.PercentOutput); } + /** + * Method that stops. + */ public void stop() { drive(0, 0); } From 956bd28f821934bb88951fc1e5359f6ce5d9de9d Mon Sep 17 00:00:00 2001 From: Kevin Palani Date: Thu, 18 Jan 2018 16:26:30 -0800 Subject: [PATCH 2/2] Finished some more documentation --- .../frc/team2854/robot/DummyPIDOutput.java | 10 ++++++ .../frc/team2854/robot/SensorBoard.java | 35 ++++++++++++++++--- .../frc/team2854/robot/SubsystemNames.java | 4 +++ .../robot/commands/DriveMotionMagik.java | 4 +-- .../team2854/robot/commands/DriveThottle.java | 21 ++++++++++- .../robot/commands/JoystickDrive.java | 21 ++++++++++- .../team2854/robot/commands/RunAllTalons.java | 12 ++++++- .../team2854/robot/subsystems/DriveTrain.java | 26 +++++++------- 8 files changed, 109 insertions(+), 24 deletions(-) diff --git a/src/org/usfirst/frc/team2854/robot/DummyPIDOutput.java b/src/org/usfirst/frc/team2854/robot/DummyPIDOutput.java index c08e8ab..627aaa5 100644 --- a/src/org/usfirst/frc/team2854/robot/DummyPIDOutput.java +++ b/src/org/usfirst/frc/team2854/robot/DummyPIDOutput.java @@ -2,14 +2,24 @@ import edu.wpi.first.wpilibj.PIDOutput; +/** + * @author Kevin Palani + * Class that represents a Dummy PID Output + */ public class DummyPIDOutput implements PIDOutput { private double output; + /** + * Default constructor + */ public DummyPIDOutput() { output = 0; } + /** + * Sets PID output value to output. + */ @Override public void pidWrite(double output) { //System.out.println("PId writing"); diff --git a/src/org/usfirst/frc/team2854/robot/SensorBoard.java b/src/org/usfirst/frc/team2854/robot/SensorBoard.java index 214460e..530fc21 100644 --- a/src/org/usfirst/frc/team2854/robot/SensorBoard.java +++ b/src/org/usfirst/frc/team2854/robot/SensorBoard.java @@ -16,7 +16,9 @@ public class SensorBoard { private BuiltInAccelerometer builtInacc; - + /** + * Default constructor. + */ public SensorBoard() { navX = new AHRS(I2C.Port.kMXP); @@ -28,6 +30,9 @@ public SensorBoard() { } + /** + * Calibrates gyro and forward accelerometer. + */ // public void calibrate(long time) { // long startTime = System.nanoTime(); // while(System.nanoTime() - startTime < time) { @@ -37,27 +42,47 @@ public SensorBoard() { // gyro.calibrate(); // forwardAccel.calibrate(); // } - + /** + * Gets the value of the gyro. + * @return - value of the gyro + */ // public double getGyroValue() { // return gyro.calculateValue(spiGyro.getRate(), navX.getRate()); // } -// + /** + * Gets the value of the forward acceleration. + * @return - value of the forward acceleration + */ // public double getForwardAccelValue() { // return forwardAccel.calculateValue(builtInacc.getX(), navX.getRawAccelY()); // } -// + /** + * Gets gyro. + * @return - gyro + */ // public DualSensor getGyro() { // return gyro; // } -// + /** + * Gets the forward acceleration. + * @return - forward acceleration. + */ // public DualSensor getForwardAccel() { // return forwardAccel; // } + /** + * Getter method for the Accelerometer. + * @return - built in accelerometer. + */ public BuiltInAccelerometer getAccelerometer() { return builtInacc; } + /** + * Getter method for NavX object. + * @return - NavX object + */ public AHRS getNavX() { return navX; } diff --git a/src/org/usfirst/frc/team2854/robot/SubsystemNames.java b/src/org/usfirst/frc/team2854/robot/SubsystemNames.java index f5379ea..b9a44e8 100644 --- a/src/org/usfirst/frc/team2854/robot/SubsystemNames.java +++ b/src/org/usfirst/frc/team2854/robot/SubsystemNames.java @@ -1,5 +1,9 @@ package org.usfirst.frc.team2854.robot; +/** + * @author Kevin Palani + * SubsystemNames + */ public enum SubsystemNames { DRIVE_TRAIN, SHIFTER; diff --git a/src/org/usfirst/frc/team2854/robot/commands/DriveMotionMagik.java b/src/org/usfirst/frc/team2854/robot/commands/DriveMotionMagik.java index 31f3928..2f75e60 100644 --- a/src/org/usfirst/frc/team2854/robot/commands/DriveMotionMagik.java +++ b/src/org/usfirst/frc/team2854/robot/commands/DriveMotionMagik.java @@ -8,9 +8,7 @@ import edu.wpi.first.wpilibj.command.Command; -/** - * - */ + public class DriveMotionMagik extends Command { private DriveTrain drive; diff --git a/src/org/usfirst/frc/team2854/robot/commands/DriveThottle.java b/src/org/usfirst/frc/team2854/robot/commands/DriveThottle.java index 91525bd..918e26d 100644 --- a/src/org/usfirst/frc/team2854/robot/commands/DriveThottle.java +++ b/src/org/usfirst/frc/team2854/robot/commands/DriveThottle.java @@ -9,35 +9,51 @@ import edu.wpi.first.wpilibj.command.Command; /** - * + * Drives at a constant percent speed. */ public class DriveThottle extends Command { private double percent; private DriveTrain drive; + /** + * Paramter constructor. + * @param percent - percent speed to drive at. + */ public DriveThottle(double percent) { requires(Robot.getSubsystem(SubsystemNames.DRIVE_TRAIN)); this.percent = percent; } // Called just before this Command runs the first time + /** + * Initializes the drive train. + */ protected void initialize() { drive = ((DriveTrain)Robot.getSubsystem(SubsystemNames.DRIVE_TRAIN)); } // Called repeatedly when this Command is scheduled to run + /** + * Drives the robot. + */ protected void execute() { System.out.println("Driving"); drive.drive(percent, percent, ControlMode.Velocity); } // Make this return true when this Command no longer needs to run execute() + /** + * Stops drive train. + */ protected boolean isFinished() { return false; } // Called once after isFinished returns true + /** + * Stops driving. + */ protected void end() { System.out.println("Stopping"); drive.stop(); @@ -45,6 +61,9 @@ protected void end() { // Called when another command which requires one or more of the same // subsystems is scheduled to run + /** + * Stops driving if interupted. + */ protected void interrupted() { System.out.println("Interupted"); drive.stop(); diff --git a/src/org/usfirst/frc/team2854/robot/commands/JoystickDrive.java b/src/org/usfirst/frc/team2854/robot/commands/JoystickDrive.java index 1f59e7e..850b611 100644 --- a/src/org/usfirst/frc/team2854/robot/commands/JoystickDrive.java +++ b/src/org/usfirst/frc/team2854/robot/commands/JoystickDrive.java @@ -15,18 +15,24 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; /** - * + * Drives the robot using joystick drive. */ public class JoystickDrive extends Command { private DriveTrain drive; + /** + * Default constructor. + */ public JoystickDrive() { requires(Robot.getSubsystem(SubsystemNames.DRIVE_TRAIN)); } // Called just before this Command runs the first time + /** + * Initializes the drivetrain. + */ protected void initialize() { drive = (DriveTrain) Robot.getSubsystem(SubsystemNames.DRIVE_TRAIN); @@ -35,6 +41,9 @@ protected void initialize() { // Called repeatedly when this Command is scheduled to run + /** + * Executes the driving. + */ protected void execute() { double speed = OI.joystick.getRawAxis(2) - OI.joystick.getRawAxis(3); //SmartDashboard.putNumber("target val", speed * Config.manuelSpeedMultiplier); @@ -49,17 +58,27 @@ protected void execute() { } // Make this return true when this Command no longer needs to run execute() + /** + * Stops drive train. + */ protected boolean isFinished() { return false; } // Called once after isFinished returns true + + /** + * Stops driving. + */ protected void end() { drive.stop(); } // Called when another command which requires one or more of the same // subsystems is scheduled to run + /** + * Stops drive when interrupted. + */ protected void interrupted() { drive.stop(); } diff --git a/src/org/usfirst/frc/team2854/robot/commands/RunAllTalons.java b/src/org/usfirst/frc/team2854/robot/commands/RunAllTalons.java index d111bcc..f8a90a3 100644 --- a/src/org/usfirst/frc/team2854/robot/commands/RunAllTalons.java +++ b/src/org/usfirst/frc/team2854/robot/commands/RunAllTalons.java @@ -9,21 +9,30 @@ import edu.wpi.first.wpilibj.command.Command; /** - * + * Runs all the Talons. */ public class RunAllTalons extends Command { + /** + * Default constructor + */ public RunAllTalons() { // Use requires() here to declare subsystem dependencies // eg. requires(chassis); } // Called just before this Command runs the first time + /** + * Initializes the Talons. + */ protected void initialize() { } // Called repeatedly when this Command is scheduled to run + /** + * Checks if Talon is functional. + */ protected void execute() { int i; for(i = 0; i < 6; i++) { @@ -42,6 +51,7 @@ protected void execute() { } // Make this return true when this Command no longer needs to run execute() + protected boolean isFinished() { return true; } diff --git a/src/org/usfirst/frc/team2854/robot/subsystems/DriveTrain.java b/src/org/usfirst/frc/team2854/robot/subsystems/DriveTrain.java index e1933bf..afa8ebe 100644 --- a/src/org/usfirst/frc/team2854/robot/subsystems/DriveTrain.java +++ b/src/org/usfirst/frc/team2854/robot/subsystems/DriveTrain.java @@ -46,14 +46,14 @@ public class DriveTrain extends Subsystem implements Restartabale { private DoubleSolenoid shifter; /** - * Method that initializes the default command to JoyStickDrive. + * Initializes the default command to JoyStickDrive. */ public void initDefaultCommand() { setDefaultCommand(new JoystickDrive()); } /** - * Method that enables the drive train. + * Enables the drive train. */ public void enable() { System.out.println("Enabling drive train"); @@ -67,7 +67,7 @@ public void enable() { } /** - * Method that disables the drive train. + * Disables the drive train. */ public void disable() { System.out.println("Disableing drive train"); @@ -113,7 +113,7 @@ public DriveTrain() { } /** - * Method that sets the PID values on shift. + * Sets the PID values on shift. * @param value - DoubleSolenoid.Value object */ public void shift(DoubleSolenoid.Value value) { @@ -143,7 +143,7 @@ public void shift(DoubleSolenoid.Value value) { //hypms /** - * Method that updates PID values + * Updates PID values * @param talon - Talon object * @param P - proportional gain * @param I - integral gain @@ -160,7 +160,7 @@ private void updatePID(TalonSRX talon, double P, double I, double D, double F) { } /** - * Method that configures a Talon to use specified PID values. + * Configures a Talon to use specified PID values. * @param talon - Talon object * @param P - proportional gain * @param I - integral gain @@ -198,7 +198,7 @@ private void configureTalon(TalonSRX talon, double P, double I, double D, double } /** - * Method that initializes PID values when turning + * Initializes PID values when turning * @param P - proportional gain * @param I - integral gain * @param D - derivative gain @@ -240,7 +240,7 @@ public PIDSourceType getPIDSourceType() { } /** - * Method that writes to SmartDashboard + * Writes to SmartDashboard */ public void writeToDashBoard() { @@ -258,7 +258,7 @@ public void writeToDashBoard() { } /** - * Method that shifts gears. + * Shifts the gears on the robot. */ public void toggleShift() { if (shifter.get() == Value.kForward) { @@ -275,7 +275,7 @@ public void toggleShift() { } /** - * Method that drives. + * Method that drives the robot at the specified ControlMode. * @param left - input percentage * @param right - input percentage * @param mode - ControlMode object that specifies ControlMode @@ -298,7 +298,7 @@ public void drive(double left, double right, ControlMode mode) { } /** - * Method that drives straight. + * Drives the robot straight. * @param left - input percentage * @param right - input percentage * @param mode - ControlMode object that specifies ControlMode @@ -312,7 +312,7 @@ public void driveStraight(double left, double right, ControlMode mode) { } /** - * Method that drives at the PercentOutput Control Mode. + * Drives the robot at the PercentOutput Control Mode. * @param left - input percentage * @param right - input percentage */ @@ -321,7 +321,7 @@ public void drive(double left, double right) { } /** - * Method that stops. + * Stops the robot. */ public void stop() { drive(0, 0);