Skip to content

Commit

Permalink
Merge in master
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Gleason committed Oct 16, 2017
2 parents 43013fd + 03e3abb commit dd1d21f
Show file tree
Hide file tree
Showing 311 changed files with 2,373 additions and 793 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ robot2017.iws
#Other
.metadata/
.DS_Store
bash.exe.stackdump

#Copied log files
logs/
Expand Down
44 changes: 6 additions & 38 deletions RoboRIO/src/main/java/org/usfirst/frc/team449/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,12 @@
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.usfirst.frc.team449.robot.drive.unidirectional.DriveTalonCluster;
import org.usfirst.frc.team449.robot.drive.unidirectional.DriveTalonClusterShiftable;
import org.usfirst.frc.team449.robot.generalInterfaces.shiftable.commands.SwitchToGear;
import org.usfirst.frc.team449.robot.other.Clock;
import org.usfirst.frc.team449.robot.other.Logger;
import org.usfirst.frc.team449.robot.oi.unidirectional.OIUnidirectional;
import org.usfirst.frc.team449.robot.subsystem.complex.climber.ClimberCurrentLimited;
import org.usfirst.frc.team449.robot.subsystem.complex.intake.IntakeFixedAndActuated;
import org.usfirst.frc.team449.robot.subsystem.complex.shooter.LoggingShooter;
import org.usfirst.frc.team449.robot.subsystem.interfaces.motionProfile.commands.RunLoadedProfile;
import org.usfirst.frc.team449.robot.subsystem.interfaces.solenoid.SolenoidSimple;
import org.usfirst.frc.team449.robot.subsystem.interfaces.solenoid.commands.SolenoidForward;
import org.usfirst.frc.team449.robot.subsystem.interfaces.solenoid.commands.SolenoidReverse;
import org.usfirst.frc.team449.robot.subsystem.singleImplementation.camera.CameraNetwork;
import org.usfirst.frc.team449.robot.subsystem.singleImplementation.pneumatics.Pneumatics;
import org.usfirst.frc.team449.robot.subsystem.singleImplementation.pneumatics.commands.StartCompressor;
import org.yaml.snakeyaml.Yaml;

import java.io.FileReader;
Expand All @@ -48,16 +36,6 @@ public class Robot extends IterativeRobot {
@NotNull
public static final String RESOURCES_PATH = "/home/lvuser/449_resources/";

/**
* The current time in milliseconds as it was stored the last time a method in robot was run.
*/
private static long currentTimeMillis;

/**
* The time robotInit started running.
*/
private static long startTime;

/**
* The drive
*/
Expand Down Expand Up @@ -92,23 +70,13 @@ public class Robot extends IterativeRobot {
@Nullable
private Command autonomousCommand;

/**
* Get the current time, in milliseconds, since startup.
*
* @return current time in milliseconds.
*/
@Contract(pure = true)
public static long currentTimeMillis() {
return currentTimeMillis - startTime;
}

/**
* The method that runs when the robot is turned on. Initializes all subsystems from the map.
*/
public void robotInit() {
//Set up start time
currentTimeMillis = System.currentTimeMillis();
startTime = currentTimeMillis;
Clock.setStartTime();
Clock.updateTime();

//Yes this should be a print statement, it's useful to know that robotInit started.
System.out.println("Started robotInit.");
Expand Down Expand Up @@ -222,7 +190,7 @@ public void teleopInit() {
@Override
public void teleopPeriodic() {
//Refresh the current time.
currentTimeMillis = System.currentTimeMillis();
Clock.updateTime();
//Run all commands. This is a WPILib thing you don't really have to worry about.
Scheduler.getInstance().run();
}
Expand Down Expand Up @@ -253,7 +221,7 @@ public void autonomousInit() {
@Override
public void autonomousPeriodic() {
//Update the current time
currentTimeMillis = System.currentTimeMillis();
Clock.updateTime();
//Run all commands. This is a WPILib thing you don't really have to worry about.
Scheduler.getInstance().run();
}
Expand Down Expand Up @@ -295,7 +263,7 @@ private void sendModeOverI2C(I2C i2C, String mode) {
*/
private void doStartupTasks() {
//Refresh the current time.
currentTimeMillis = System.currentTimeMillis();
Clock.updateTime();

//Start running the logger
loggerNotifier.startPeriodic(robotMap.getLogger().getLoopTimeSecs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import org.usfirst.frc.team449.robot.jacksonWrappers.MappedDigitalInput;
import org.usfirst.frc.team449.robot.jacksonWrappers.YamlCommand;
import org.usfirst.frc.team449.robot.oi.OI;
import org.usfirst.frc.team449.robot.other.Logger;
import org.usfirst.frc.team449.robot.oi.buttons.CommandButton;
import org.usfirst.frc.team449.robot.oi.unidirectional.OIUnidirectional;
import org.usfirst.frc.team449.robot.other.Logger;
import org.usfirst.frc.team449.robot.other.MotionProfileData;
import org.usfirst.frc.team449.robot.subsystem.complex.climber.ClimberCurrentLimited;
import org.usfirst.frc.team449.robot.subsystem.complex.intake.IntakeFixedAndActuated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.usfirst.frc.team449.robot.Robot;
import org.usfirst.frc.team449.robot.jacksonWrappers.YamlCommandWrapper;
import org.usfirst.frc.team449.robot.other.Clock;

/**
* A command that does nothing and finishes after a set number of milliseconds. For use to create a delay in sequential
Expand Down Expand Up @@ -39,7 +39,7 @@ public WaitForMillis(@JsonProperty(required = true) long time) {
*/
@Override
protected void initialize() {
startTime = Robot.currentTimeMillis();
startTime = Clock.currentTimeMillis();
}

/**
Expand All @@ -49,6 +49,6 @@ protected void initialize() {
*/
@Override
protected boolean isFinished() {
return Robot.currentTimeMillis() - startTime >= timeout;
return Clock.currentTimeMillis() - startTime >= timeout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.usfirst.frc.team449.robot.components.AutoshiftComponent;
import org.usfirst.frc.team449.robot.drive.shifting.DriveShiftable;
import org.usfirst.frc.team449.robot.drive.unidirectional.DriveUnidirectional;
import org.usfirst.frc.team449.robot.generalInterfaces.shiftable.Shiftable;
import org.usfirst.frc.team449.robot.jacksonWrappers.YamlSubsystem;
import org.usfirst.frc.team449.robot.oi.fieldoriented.OIFieldOriented;
import org.usfirst.frc.team449.robot.other.Logger;
Expand All @@ -18,7 +19,7 @@
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_OBJECT, property = "@class")
@JsonIdentityInfo(generator = ObjectIdGenerators.StringIdGenerator.class)
public class FieldOrientedUnidirectionalDriveCommandShifting <T extends YamlSubsystem & DriveUnidirectional & SubsystemNavX & DriveShiftable>
public class FieldOrientedUnidirectionalDriveCommandShifting<T extends YamlSubsystem & DriveUnidirectional & SubsystemNavX & DriveShiftable>
extends FieldOrientedUnidirectionalDriveCommand {

/**
Expand All @@ -33,25 +34,31 @@ public class FieldOrientedUnidirectionalDriveCommandShifting <T extends YamlSubs
@NotNull
private final AutoshiftComponent autoshiftComponent;

/**
* The coefficient to multiply the loop output by in high gear. Defaults to 1.
*/
private final double highGearAngularCoefficient;

/**
* Default constructor
*
* @param toleranceBuffer How many consecutive loops have to be run while within tolerance to be considered on
* target. Multiply by loop period of ~20 milliseconds for time. Defaults to 0.
* @param absoluteTolerance The maximum number of degrees off from the target at which we can be considered within
* tolerance.
* @param minimumOutput The minimum output of the loop. Defaults to zero.
* @param maximumOutput The maximum output of the loop. Can be null, and if it is, no maximum output is used.
* @param deadband The deadband around the setpoint, in degrees, within which no output is given to the
* motors. Defaults to zero.
* @param inverted Whether the loop is inverted. Defaults to false.
* @param kP Proportional gain. Defaults to zero.
* @param kI Integral gain. Defaults to zero.
* @param kD Derivative gain. Defaults to zero.
* @param subsystem The drive to execute this command on.
* @param oi The OI controlling the robot.
* @param snapPoints The points to snap the PID controller input to.
* @param autoshiftComponent The helper object for autoshifting.
* @param toleranceBuffer How many consecutive loops have to be run while within tolerance to be considered on
* target. Multiply by loop period of ~20 milliseconds for time. Defaults to 0.
* @param absoluteTolerance The maximum number of degrees off from the target at which we can be considered within
* tolerance.
* @param minimumOutput The minimum output of the loop. Defaults to zero.
* @param maximumOutput The maximum output of the loop. Can be null, and if it is, no maximum output is used.
* @param deadband The deadband around the setpoint, in degrees, within which no output is given to the
* motors. Defaults to zero.
* @param inverted Whether the loop is inverted. Defaults to false.
* @param kP Proportional gain. Defaults to zero.
* @param kI Integral gain. Defaults to zero.
* @param kD Derivative gain. Defaults to zero.
* @param subsystem The drive to execute this command on.
* @param oi The OI controlling the robot.
* @param snapPoints The points to snap the PID controller input to.
* @param autoshiftComponent The helper object for autoshifting.
* @param highGearAngularCoefficient The coefficient to multiply the loop output by in high gear. Defaults to 1.
*/
@JsonCreator
public FieldOrientedUnidirectionalDriveCommandShifting(@JsonProperty(required = true) double absoluteTolerance,
Expand All @@ -65,11 +72,13 @@ public FieldOrientedUnidirectionalDriveCommandShifting(@JsonProperty(required =
@NotNull @JsonProperty(required = true) T subsystem,
@NotNull @JsonProperty(required = true) OIFieldOriented oi,
@Nullable List<AngularSnapPoint> snapPoints,
@NotNull @JsonProperty(required = true) AutoshiftComponent autoshiftComponent) {
@NotNull @JsonProperty(required = true) AutoshiftComponent autoshiftComponent,
@Nullable Double highGearAngularCoefficient) {
//Assign stuff
super(absoluteTolerance, toleranceBuffer, minimumOutput, maximumOutput, deadband, inverted, kP, kI, kD, subsystem, oi, snapPoints);
this.subsystem = subsystem;
this.autoshiftComponent = autoshiftComponent;
this.highGearAngularCoefficient = highGearAngularCoefficient != null ? highGearAngularCoefficient : 1;
}

/**
Expand All @@ -83,6 +92,16 @@ protected void execute() {
super.execute();
}

/**
* Give the correct output to the motors based on the PID output and velocity input.
*
* @param output The output of the angular PID loop.
*/
@Override
protected void usePIDOutput(double output) {
super.usePIDOutput(output * (subsystem.getGear() == Shiftable.gear.HIGH.getNumVal() ? highGearAngularCoefficient : 1));
}

/**
* Log when this command ends
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import org.jetbrains.annotations.Nullable;
import org.usfirst.frc.team449.robot.drive.unidirectional.DriveUnidirectional;
import org.usfirst.frc.team449.robot.jacksonWrappers.YamlSubsystem;
import org.usfirst.frc.team449.robot.other.Logger;
import org.usfirst.frc.team449.robot.oi.unidirectional.tank.OITank;
import org.usfirst.frc.team449.robot.other.Logger;
import org.usfirst.frc.team449.robot.subsystem.interfaces.navX.SubsystemNavX;
import org.usfirst.frc.team449.robot.subsystem.interfaces.navX.commands.PIDAngleCommand;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.usfirst.frc.team449.robot.Robot;
import org.usfirst.frc.team449.robot.drive.unidirectional.DriveUnidirectional;
import org.usfirst.frc.team449.robot.jacksonWrappers.YamlSubsystem;
import org.usfirst.frc.team449.robot.other.Clock;
import org.usfirst.frc.team449.robot.other.Logger;
import org.usfirst.frc.team449.robot.subsystem.interfaces.navX.SubsystemNavX;
import org.usfirst.frc.team449.robot.subsystem.interfaces.navX.commands.PIDAngleCommand;
Expand Down Expand Up @@ -112,7 +112,7 @@ protected void usePIDOutput(double output) {
@Override
protected void initialize() {
//Set up start time
this.startTime = Robot.currentTimeMillis();
this.startTime = Clock.currentTimeMillis();
this.setSetpoint(setpoint);
//Make sure to enable the controller!
this.getPIDController().enable();
Expand All @@ -126,7 +126,7 @@ protected void initialize() {
@Override
protected boolean isFinished() {
//The PIDController onTarget() is crap and sometimes never returns true because of floating point errors, so we need a timeout
return this.getPIDController().onTarget() || Robot.currentTimeMillis() - startTime > timeout;
return this.getPIDController().onTarget() || Clock.currentTimeMillis() - startTime > timeout;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.usfirst.frc.team449.robot.Robot;
import org.usfirst.frc.team449.robot.drive.unidirectional.DriveUnidirectional;
import org.usfirst.frc.team449.robot.jacksonWrappers.YamlSubsystem;
import org.usfirst.frc.team449.robot.other.Clock;
import org.usfirst.frc.team449.robot.other.Logger;
import org.usfirst.frc.team449.robot.subsystem.interfaces.navX.SubsystemNavX;

Expand Down Expand Up @@ -59,7 +59,7 @@ public NavXTurnToAngleRelative(@JsonProperty(required = true) double absoluteTol
@Override
protected void initialize() {
//Setup start time
this.startTime = Robot.currentTimeMillis();
this.startTime = Clock.currentTimeMillis();
Logger.addEvent("NavXRelativeTurnToAngle init.", this.getClass());
//Do math to setup the setpoint.
this.setSetpoint(clipTo180(((SubsystemNavX) subsystem).getGyroOutput() + setpoint));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import org.jetbrains.annotations.Nullable;
import org.usfirst.frc.team449.robot.drive.unidirectional.DriveUnidirectional;
import org.usfirst.frc.team449.robot.jacksonWrappers.YamlSubsystem;
import org.usfirst.frc.team449.robot.other.Logger;
import org.usfirst.frc.team449.robot.oi.unidirectional.OIUnidirectional;
import org.usfirst.frc.team449.robot.other.BufferTimer;
import org.usfirst.frc.team449.robot.other.Logger;
import org.usfirst.frc.team449.robot.subsystem.interfaces.navX.SubsystemNavX;
import org.usfirst.frc.team449.robot.subsystem.interfaces.navX.commands.PIDAngleCommand;

Expand Down Expand Up @@ -175,6 +175,11 @@ protected void usePIDOutput(double output) {
//Process the output (minimumOutput, deadband, etc.)
output = processPIDOutput(output);

//Deadband if we're stationary
if(oi.getLeftOutput() == 0 || oi.getRightOutput() == 0){
output=deadbandOutput(output);
}

//Adjust the heading according to the PID output, it'll be positive if we want to go right.
subsystem.setOutput(oi.getLeftOutput() - output, oi.getRightOutput() + output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import org.usfirst.frc.team449.robot.components.AutoshiftComponent;
import org.usfirst.frc.team449.robot.drive.shifting.DriveShiftable;
import org.usfirst.frc.team449.robot.drive.unidirectional.DriveUnidirectional;
import org.usfirst.frc.team449.robot.generalInterfaces.shiftable.Shiftable;
import org.usfirst.frc.team449.robot.jacksonWrappers.YamlSubsystem;
import org.usfirst.frc.team449.robot.other.Logger;
import org.usfirst.frc.team449.robot.oi.unidirectional.OIUnidirectional;
import org.usfirst.frc.team449.robot.other.BufferTimer;
import org.usfirst.frc.team449.robot.other.Logger;
import org.usfirst.frc.team449.robot.subsystem.interfaces.navX.SubsystemNavX;

/**
Expand All @@ -32,6 +33,11 @@ public class UnidirectionalNavXShiftingDefaultDrive<T extends YamlSubsystem & Dr
@NotNull
protected final AutoshiftComponent autoshiftComponent;

/**
* The coefficient to multiply the loop output by in high gear.
*/
private final double highGearAngularCoefficient;

/**
* Default constructor
*
Expand All @@ -55,6 +61,7 @@ public class UnidirectionalNavXShiftingDefaultDrive<T extends YamlSubsystem & Dr
* @param subsystem The drive to execute this command on.
* @param oi The OI controlling the robot.
* @param autoshiftComponent The helper object for autoshifting.
* @param highGearAngularCoefficient The coefficient to multiply the loop output by in high gear. Defaults to 1.
*/
@JsonCreator
public UnidirectionalNavXShiftingDefaultDrive(@JsonProperty(required = true) double absoluteTolerance,
Expand All @@ -69,11 +76,13 @@ public UnidirectionalNavXShiftingDefaultDrive(@JsonProperty(required = true) dou
@NotNull @JsonProperty(required = true) BufferTimer driveStraightLoopEntryTimer,
@NotNull @JsonProperty(required = true) T subsystem,
@NotNull @JsonProperty(required = true) OIUnidirectional oi,
@NotNull @JsonProperty(required = true) AutoshiftComponent autoshiftComponent) {
@NotNull @JsonProperty(required = true) AutoshiftComponent autoshiftComponent,
@Nullable Double highGearAngularCoefficient) {
super(absoluteTolerance, toleranceBuffer, minimumOutput, maximumOutput, deadband, maxAngularVelToEnterLoop,
inverted, kP, kI, kD, driveStraightLoopEntryTimer, subsystem, oi);
this.autoshiftComponent = autoshiftComponent;
this.subsystem = subsystem;
this.highGearAngularCoefficient = highGearAngularCoefficient != null ? highGearAngularCoefficient : 1;
}

/**
Expand Down Expand Up @@ -105,4 +114,14 @@ protected void interrupted() {
Logger.addEvent("ShiftingUnidirectionalNavXArcadeDrive Interrupted! Stopping the robot.", this.getClass());
subsystem.fullStop();
}

/**
* Give the correct output to the motors based on whether we're in free drive or drive straight.
*
* @param output The output of the angular PID loop.
*/
@Override
protected void usePIDOutput(double output) {
super.usePIDOutput(output * (subsystem.getGear() == Shiftable.gear.HIGH.getNumVal() ? highGearAngularCoefficient : 1));
}
}
Loading

0 comments on commit dd1d21f

Please sign in to comment.