Skip to content
This repository was archived by the owner on Nov 27, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import frc.lib5k.utils.RobotLogger;
import frc.lib5k.utils.RobotLogger.Level;
import frc.robot.autonomous.Chooser;
import frc.robot.autonomous.helpers.CurrentSpiking;
import frc.robot.commands.DriveControl;
import frc.robot.commands.OperatorControl;
import frc.robot.subsystems.CellSuperstructure;
Expand Down Expand Up @@ -53,11 +54,11 @@ public class Robot extends TimedRobot {
private CommandBase m_autonomousCommand;
private DriveControl m_driveControl;
private OperatorControl m_operatorControl;

private Chooser m_autonChooser;

private boolean m_lastUserState = false;

private CurrentSpiking m_currentSpike;
/**
* This function is run when the robot is first started up and should be used
* for any initialization code.
Expand Down Expand Up @@ -116,6 +117,10 @@ public void robotInit() {

// Report Lib5k
RR_HAL.reportFRCVersion("Java", RR_HAL.getLibraryVersion());

// Creates current spike
m_currentSpike = new CurrentSpiking(1, 2);

}

@Override
Expand All @@ -127,6 +132,9 @@ public void robotPeriodic() {

}

// Checks for current spiking
m_currentSpike.hitTargetSpike(2);

}

@Override
Expand All @@ -140,7 +148,7 @@ public void simulationPeriodic() {
@Override
public void autonomousInit() {
logger.log("Robot", "Autonomous started");

// Determine correct autonomous command to run
m_autonomousCommand = m_autonChooser.generateAutonomousCommand();

Expand Down Expand Up @@ -176,6 +184,7 @@ public void autonomousPeriodic() {

// Run all scheduled WPILib commands
CommandScheduler.getInstance().run();

}

@Override
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/frc/robot/RobotConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,10 @@ public static class Pneumatics {
public static final int PCM_CAN_ID = 8;
}

public static class Power{

// PDP CAN ID
public static final int PDP_CAN_ID = 10;
}

}
61 changes: 61 additions & 0 deletions src/main/java/frc/robot/autonomous/helpers/CurrentSpiking.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package frc.robot.autonomous.helpers;


import edu.wpi.first.wpilibj.PowerDistributionPanel;
import frc.robot.RobotConstants;
import edu.wpi.first.wpilibj.Timer;

public class CurrentSpiking{

PowerDistributionPanel powerDistributionPanel = new PowerDistributionPanel(RobotConstants.Power.PDP_CAN_ID);
private int channel;
private double targetSpike;
private Timer timer = new Timer();
private boolean isNew = true;
private double totalCurrent;

public CurrentSpiking(int channel, double targetSpike){
this.channel = channel;
this.targetSpike = targetSpike;
}

public double getChannelCurrent(int channel){
return powerDistributionPanel.getCurrent(channel);
}

public void setTargetSpike(double targetSpike){
this.targetSpike = targetSpike;
}

public double getAverage(int... args){
totalCurrent = 0;
for(int arg : args){
totalCurrent += getChannelCurrent(arg);
}

return totalCurrent / args.length;
}


public boolean hitTargetSpike(double seconds){
if(getChannelCurrent(channel) >= targetSpike){
if(isNew){
timer.reset();
timer.start();
isNew = false;
}

if(timer.hasElapsed(seconds)){
return true;
}
}else{
isNew = true;
}

return false;
}




}