YWLAElektraBots

Compressor.class

Jan 26th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.00 KB | None | 0 0
  1. /*----------------------------------------------------------------------------*/
  2. /* Copyright (c) 2016-2018 FIRST. All Rights Reserved.                        */
  3. /* Open Source Software - may be modified and shared by FRC teams. The code   */
  4. /* must be accompanied by the FIRST BSD license file in the root directory of */
  5. /* the project.                                                               */
  6. /*----------------------------------------------------------------------------*/
  7.  
  8. package edu.wpi.first.wpilibj;
  9.  
  10. import edu.wpi.first.wpilibj.hal.CompressorJNI;
  11. import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
  12. import edu.wpi.first.wpilibj.hal.HAL;
  13. import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
  14.  
  15. /**
  16.  * Class for operating a compressor connected to a PCM (Pneumatic Control Module). The PCM will
  17.  * automatically run in closed loop mode by default whenever a {@link Solenoid} object is created.
  18.  * For most cases, a Compressor object does not need to be instantiated or used in a robot program.
  19.  * This class is only required in cases where the robot program needs a more detailed status of the
  20.  * compressor or to enable/disable closed loop control.
  21.  *
  22.  * <p>Note: you cannot operate the compressor directly from this class as doing so would circumvent
  23.  * the safety provided by using the pressure switch and closed loop control. You can only turn off
  24.  * closed loop control, thereby stopping the compressor from operating.
  25.  */
  26. public class Compressor extends SendableBase implements Sendable {
  27.   private int m_compressorHandle;
  28.   private byte m_module;
  29.  
  30.   /**
  31.    * Makes a new instance of the compressor using the provided CAN device ID.  Use this constructor
  32.    * when you have more than one PCM.
  33.    *
  34.    * @param module The PCM CAN device ID (0 - 62 inclusive)
  35.    */
  36.   public Compressor(int module) {
  37.     m_module = (byte) module;
  38.  
  39.     m_compressorHandle = CompressorJNI.initializeCompressor((byte) module);
  40.  
  41.     HAL.report(tResourceType.kResourceType_Compressor, module);
  42.     setName("Compressor", module);
  43.   }
  44.  
  45.   /**
  46.    * Makes a new instance of the compressor using the default PCM ID of 0.
  47.    *
  48.    * <p>Additional modules can be supported by making a new instance and {@link #Compressor(int)
  49.    * specifying the CAN ID.}
  50.    */
  51.   public Compressor() {
  52.     this(SensorBase.getDefaultSolenoidModule());
  53.   }
  54.  
  55.   /**
  56.    * Start the compressor running in closed loop control mode.
  57.    *
  58.    * <p>Use the method in cases where you would like to manually stop and start the compressor for
  59.    * applications such as conserving battery or making sure that the compressor motor doesn't start
  60.    * during critical operations.
  61.    */
  62.   public void start() {
  63.     setClosedLoopControl(true);
  64.   }
  65.  
  66.   /**
  67.    * Stop the compressor from running in closed loop control mode.
  68.    *
  69.    * <p>Use the method in cases where you would like to manually stop and start the compressor for
  70.    * applications such as conserving battery or making sure that the compressor motor doesn't start
  71.    * during critical operations.
  72.    */
  73.   public void stop() {
  74.     setClosedLoopControl(false);
  75.   }
  76.  
  77.   /**
  78.    * Get the status of the compressor.
  79.    *
  80.    * @return true if the compressor is on
  81.    */
  82.   public boolean enabled() {
  83.     return CompressorJNI.getCompressor(m_compressorHandle);
  84.   }
  85.  
  86.   /**
  87.    * Get the pressure switch value.
  88.    *
  89.    * @return true if the pressure is low
  90.    */
  91.   public boolean getPressureSwitchValue() {
  92.     return CompressorJNI.getCompressorPressureSwitch(m_compressorHandle);
  93.   }
  94.  
  95.   /**
  96.    * Get the current being used by the compressor.
  97.    *
  98.    * @return current consumed by the compressor in amps
  99.    */
  100.   public double getCompressorCurrent() {
  101.     return CompressorJNI.getCompressorCurrent(m_compressorHandle);
  102.   }
  103.  
  104.   /**
  105.    * Set the PCM in closed loop control mode.
  106.    *
  107.    * @param on if true sets the compressor to be in closed loop control mode (default)
  108.    */
  109.   public void setClosedLoopControl(boolean on) {
  110.     CompressorJNI.setCompressorClosedLoopControl(m_compressorHandle, on);
  111.   }
  112.  
  113.   /**
  114.    * Gets the current operating mode of the PCM.
  115.    *
  116.    * @return true if compressor is operating on closed-loop mode
  117.    */
  118.   public boolean getClosedLoopControl() {
  119.     return CompressorJNI.getCompressorClosedLoopControl(m_compressorHandle);
  120.   }
  121.  
  122.   /**
  123.    * If PCM is in fault state : Compressor Drive is disabled due to compressor current being too
  124.    * high.
  125.    *
  126.    * @return true if PCM is in fault state.
  127.    */
  128.   public boolean getCompressorCurrentTooHighFault() {
  129.     return CompressorJNI.getCompressorCurrentTooHighFault(m_compressorHandle);
  130.   }
  131.  
  132.   /**
  133.    * If PCM sticky fault is set : Compressor is disabled due to compressor current being too
  134.    * high.
  135.    *
  136.    * @return true if PCM sticky fault is set.
  137.    */
  138.   public boolean getCompressorCurrentTooHighStickyFault() {
  139.     return CompressorJNI.getCompressorCurrentTooHighStickyFault(m_compressorHandle);
  140.   }
  141.  
  142.   /**
  143.    * If PCM sticky fault is set : Compressor output appears to be shorted.
  144.    *
  145.    * @return true if PCM sticky fault is set.
  146.    */
  147.   public boolean getCompressorShortedStickyFault() {
  148.     return CompressorJNI.getCompressorShortedStickyFault(m_compressorHandle);
  149.   }
  150.  
  151.   /**
  152.    * If PCM is in fault state : Compressor output appears to be shorted.
  153.    *
  154.    * @return true if PCM is in fault state.
  155.    */
  156.   public boolean getCompressorShortedFault() {
  157.     return CompressorJNI.getCompressorShortedFault(m_compressorHandle);
  158.   }
  159.  
  160.   /**
  161.    * If PCM sticky fault is set : Compressor does not appear to be wired, i.e. compressor is not
  162.    * drawing enough current.
  163.    *
  164.    * @return true if PCM sticky fault is set.
  165.    */
  166.   public boolean getCompressorNotConnectedStickyFault() {
  167.     return CompressorJNI.getCompressorNotConnectedStickyFault(m_compressorHandle);
  168.   }
  169.  
  170.   /**
  171.    * If PCM is in fault state : Compressor does not appear to be wired, i.e. compressor is not
  172.    * drawing enough current.
  173.    *
  174.    * @return true if PCM is in fault state.
  175.    */
  176.   public boolean getCompressorNotConnectedFault() {
  177.     return CompressorJNI.getCompressorNotConnectedFault(m_compressorHandle);
  178.   }
  179.  
  180.   /**
  181.    * Clear ALL sticky faults inside PCM that Compressor is wired to.
  182.    *
  183.    * <p>If a sticky fault is set, then it will be persistently cleared. The compressor might
  184.    * momentarily disable while the flags are being cleared. Doo not call this method too
  185.    * frequently, otherwise normal compressor functionality may be prevented.
  186.    *
  187.    * <p>If no sticky faults are set then this call will have no effect.
  188.    */
  189.   public void clearAllPCMStickyFaults() {
  190.     CompressorJNI.clearAllPCMStickyFaults(m_module);
  191.   }
  192.  
  193.   @Override
  194.   public void initSendable(SendableBuilder builder) {
  195.     builder.setSmartDashboardType("Compressor");
  196.     builder.addBooleanProperty("Enabled", this::enabled, (value) -> {
  197.       if (value) {
  198.         start();
  199.       } else {
  200.         stop();
  201.       }
  202.     });
  203.     builder.addBooleanProperty("Pressure switch", this::getPressureSwitchValue, null);
  204.   }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment