Advertisement
YWLAElektraBots

PWMSpeedController.class

Jan 26th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. /*----------------------------------------------------------------------------*/
  2. /* Copyright (c) 2008-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. /**
  11.  * Common base class for all PWM Speed Controllers.
  12.  */
  13. public abstract class PWMSpeedController extends SafePWM implements SpeedController {
  14.   private boolean m_isInverted = false;
  15.  
  16.   /**
  17.    * Constructor.
  18.    *
  19.    * @param channel The PWM channel that the controller is attached to. 0-9 are on-board, 10-19 are
  20.    *                on the MXP port
  21.    */
  22.   protected PWMSpeedController(int channel) {
  23.     super(channel);
  24.   }
  25.  
  26.   /**
  27.    * Set the PWM value.
  28.    *
  29.    * <p>The PWM value is set using a range of -1.0 to 1.0, appropriately scaling the value for the
  30.    * FPGA.
  31.    *
  32.    * @param speed The speed value between -1.0 and 1.0 to set.
  33.    */
  34.   @Override
  35.   public void set(double speed) {
  36.     setSpeed(m_isInverted ? -speed : speed);
  37.     feed();
  38.   }
  39.  
  40.   /**
  41.    * Get the recently set value of the PWM.
  42.    *
  43.    * @return The most recently set value for the PWM between -1.0 and 1.0.
  44.    */
  45.   @Override
  46.   public double get() {
  47.     return getSpeed();
  48.   }
  49.  
  50.   @Override
  51.   public void setInverted(boolean isInverted) {
  52.     m_isInverted = isInverted;
  53.   }
  54.  
  55.   @Override
  56.   public boolean getInverted() {
  57.     return m_isInverted;
  58.   }
  59.  
  60.   /**
  61.    * Write out the PID value as seen in the PIDOutput base object.
  62.    *
  63.    * @param output Write out the PWM value as was found in the PIDController
  64.    */
  65.   @Override
  66.   public void pidWrite(double output) {
  67.     set(output);
  68.   }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement