Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compressor class added #144

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
42 changes: 42 additions & 0 deletions src/main/java/frc/team3128/commands/CmdElevator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package frc.team3128.commands;
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.wpilibj.AnalogPotentiometer;
import edu.wpi.first.wpilibj.motorcontrol.PWMTalonFX;
import edu.wpi.first.wpilibj.motorcontrol.PWMTalonSRX;
import edu.wpi.first.wpilibj.motorcontrol.PWMVictorSPX;
import edu.wpi.first.wpilibj2.command.PIDSubsystem;

public class CmdElevator extends PIDSubsystem{

private PIDController m_controller;

public CmdElevator(PIDController controller) {
super(controller); //add num later on
m_controller = controller;

}

// important ID elements
public static final double Bottom = 1.00;
public static final double Stow = 1.00;
public static final double Table_Height = 1.00;

private AnalogPotentiometer pot;
private PWMTalonSRX motor;

// @Override
// public void initialize(){

// }
protected void useOutput(double output, double setpoint) {
// TODO Auto-generated method stub

}

@Override
protected double getMeasurement() {
// TODO Auto-generated method stub
return pot.get();
}

}
118 changes: 118 additions & 0 deletions src/main/java/frc/team3128/subsystems/Compressor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package frc.team3128.subsystems;
//import javax.management.DescriptorKey;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.CompressorConfigType;
import edu.wpi.first.wpilibj.PneumaticsBase;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
//import frc.team3128.Constants.CompressorConstants;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.util.AllocationException;


public class Compressor extends Object implements AutoCloseable, Sendable {

private PneumaticsBase m_module;
// private boolean pressureSwitch = false;
// public boolean enabled = true;
// public boolean closedLoop = true;



public Compressor(int mod, PneumaticsModuleType modType){
// module = mod;
// m_module = modType;

m_module = PneumaticsBase.getForType(mod, modType);

if (!m_module.reserveCompressor()){
m_module.close();
throw new AllocationException("Compressor already allocated");
}

m_module.enableCompressorDigital();

HAL.report(tResourceType.kResourceType_Compressor, mod + 1);
SendableRegistry.addLW(this, "Compressor", mod);
}

public Compressor(PneumaticsModuleType modType){
this(PneumaticsBase.getDefaultForType(modType), modType);
}

// public void close(PneumaticsModuleType mod) throws Exception{
// Compressor com = new Compressor(mod);
// com.close();
// }



public void close(){ //throws exception needed?
m_module.close();
SendableRegistry.remove(this);
m_module.unreserveCompressor();
m_module = null;
}

@Deprecated(since="2022", forRemoval = true)
public void stop(){
//setClosedLoop(false);
disable(); //defined later
}

@Deprecated(since="2022", forRemoval = true)
public void start(){
//setClosedLoop(true);
enableDigital(); //defined later
}

public boolean enabled(){
return m_module.getCompressor();
}

public boolean getPressureSwitchValue(){
return m_module.getPressureSwitch();
}

public double getCurrent(){
return m_module.getCompressorCurrent();
}

public double getAnalogVoltage(){
return m_module.getAnalogVoltage(0);
}

public double getPressure(){
return m_module.getPressure(0);
}

public void disable(){
m_module.disableCompressor();
}

public void enableDigital(){
m_module.enableCompressorDigital();
}

public void enableAnalog(double minPressure, double maxPressure){
m_module.enableCompressorAnalog(minPressure, maxPressure);
}

public void enableHybrid(double minPressure, double maxPressure){
m_module.enableCompressorHybrid(minPressure, maxPressure);
}

public CompressorConfigType getConfigType(){
return m_module.getCompressorConfigType();
}

@Override
public void initSendable(SendableBuilder builder){
builder.setSmartDashboardType("Compressor");
builder.addBooleanProperty("Enabled", this::enabled, null);
builder.addBooleanProperty("Pressure Switch", this::getPressureSwitchValue, null);
}

}