001/** 002 * Copyright 2024 The Space Cookies : Girl Scout Troop #62868 and FRC Team #1868 003 * Open Source Software; you may modify and/or share it under the terms of 004 * the 3-Clause BSD License found in the root directory of this project. 005 */ 006 007package tagalong.controls; 008 009import edu.wpi.first.math.controller.ProfiledPIDController; 010import edu.wpi.first.math.trajectory.TrapezoidProfile; 011import tagalong.TagalongConfiguration; 012 013/** 014 * PID wrapper class for coefficients that are generically reused in multiple 015 * controllers. 016 */ 017public class PIDConstants { 018 /** 019 * Proportional, integral, and derivative coefficient 020 */ 021 public final double p, i, d; 022 023 /** 024 * 025 * @param p Proportional coefficient 026 * @param i Integral coefficient 027 * @param d Derivative coefficient 028 */ 029 public PIDConstants(double p, double i, double d) { 030 this.p = p; 031 this.i = i; 032 this.d = d; 033 } 034 035 /** 036 * 037 * @return PID values converted to an un-profiled PID controller 038 */ 039 public PIDConstants getUnprofiledController() { 040 return new PIDConstants(p, i, d); 041 } 042 043 /** 044 * 045 * @param constraints Profile constraints 046 * @return PID values converted to an profiled PID controller 047 */ 048 public ProfiledPIDController getProfiledController(TrapezoidProfile.Constraints constraints) { 049 return new ProfiledPIDController( 050 p, 051 i, 052 d, 053 new TrapezoidProfile.Constraints(constraints.maxVelocity, constraints.maxAcceleration), 054 TagalongConfiguration.LOOP_PERIOD_S 055 ); 056 } 057}