Class RobotComponents

java.lang.Object
org.firstinspires.ftc.teamcode.subsystems.pid.RobotComponents

public class RobotComponents extends Object
Initialize a motor as a RobotComponent with its values for PID functionality and extra features
  • Constructor Summary

    Constructors
    Constructor
    Description
    RobotComponents(com.qualcomm.robotcore.hardware.DcMotorEx motor, double ticks_per_rotation, double p, double i, double d, double f)
    Constructor for RobotComponents
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Get the current encoder target
    double
    Get the number of encoder ticks per degree
    void
    incrementTarget(double increment)
    Modify the encoder target by a set value rather than resetting it, positive to increase, negative to decrease
    boolean
    motorCloseEnough(int range)
    Returns true if the motor's current encoder position is within the specified range of currentTarget and false otherwise (e.g.
    void
    Sends power to the RobotComponent's motor to smoothly and automatically reach currentTarget (or whatever its called, might be different) using the PID loop.
    void
    setTarget(double newTarget)
    Set the encoder target to a new value

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RobotComponents

      RobotComponents(com.qualcomm.robotcore.hardware.DcMotorEx motor, double ticks_per_rotation, double p, double i, double d, double f)
      Constructor for RobotComponents
      Parameters:
      motor - Motor Declaration
      ticks_per_rotation - Value of ticks for specific motor RPM. Can be found on the manufacture's website (GoBuilda, Rev, etc)
      p - The Proportional Value tuned after F (if applicable) until the motor can barely get to its target position. Typically under 0.1, but may be higher.
      i - The Integral Value tuned last, only if steady state error continues. Typically relatively unnecessary unless extreme precision is needed and typically of a value in the tenths of decimals. Be sure to re-tune D afterwards.
      d - The Derivative Value tuned after P, this value helps reduce oscillation in reaching a target and should result in a smoothed out curve when going to a target. Extremely small and sensitive, typically around 0.001. Re-tune after adjusting I.
      f - The Feed-forward value, tuned before anything else by increasing until the motor can hold itself against gravity at any position. Only use if you want a motor to hold its position against gravity and never use on locking systems like worm gears (in this case, set to 0)! Value is variable based on necessary motor power, but should be low (under 0.1) to avoid motor overheating and power draw.
  • Method Details

    • getTicksPerDegree

      public double getTicksPerDegree()
      Get the number of encoder ticks per degree
    • getTarget

      public double getTarget()
      Get the current encoder target
    • setTarget

      public void setTarget(double newTarget)
      Set the encoder target to a new value
      Parameters:
      newTarget - The new encoder target value
    • incrementTarget

      public void incrementTarget(double increment)
      Modify the encoder target by a set value rather than resetting it, positive to increase, negative to decrease
      Parameters:
      increment - The value to increment (positively or negatively) the current encoder target
    • moveUsingPID

      public void moveUsingPID()
      Sends power to the RobotComponent's motor to smoothly and automatically reach currentTarget (or whatever its called, might be different) using the PID loop. Must be called every code loop!
    • motorCloseEnough

      public boolean motorCloseEnough(int range)
      Returns true if the motor's current encoder position is within the specified range of currentTarget and false otherwise (e.g. true for a pos of 167 with a target of 170 and a range of 5, false for the same conditions and a pos of 200)
      Parameters:
      range - The permissible range of encoder positions relative to the current target (e.g. target of 170 with a range of 5 will accept positions from 165 to 175)