Guest User

Untitled

a guest
Jan 18th, 2023
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. package frc.robot.math;
  2.  
  3. public class SensorProfile {
  4. public final double unitsPerRevolution;
  5. public final int velocityRate;
  6.  
  7. public SensorProfile(int unitsPerRevolution) {
  8. this(unitsPerRevolution, 1);
  9. }
  10.  
  11. public SensorProfile(int unitsPerRevolution, double gearRatio) {
  12. this(unitsPerRevolution, 100, gearRatio);
  13. }
  14.  
  15. public SensorProfile(int unitsPerRevolution, int velocityRate, double gearRatio) {
  16. this.unitsPerRevolution = unitsPerRevolution * gearRatio;
  17. this.velocityRate = velocityRate;
  18. }
  19.  
  20. /**
  21. * Units to Revolutions
  22. * @param ticks Change in sensor position in sensor units
  23. * @return Change in sensor position in revolutions
  24. */
  25. public double uToRev(double ticks) {
  26. return (double) ticks / unitsPerRevolution;
  27. }
  28.  
  29. /**
  30. * Revolutions to Units
  31. * @param revolutions Change in sensor position in revolutions
  32. * @return Change in sensor position in sensor units
  33. */
  34. public double revToU(double revolutions) {
  35. return revolutions * unitsPerRevolution;
  36. }
  37.  
  38. /**
  39. * Units to Radians
  40. * @param ticks Change in sensor position in sensor units
  41. * @return Change in sensor position in radians
  42. */
  43. public double uToRad(double ticks) {
  44. return uToRev(ticks) * Math.PI * 2;
  45. }
  46.  
  47. /**
  48. * Radians to Units
  49. * @param radians Change in sensor position in radians
  50. * @return Change in sensor position in sensor units
  51. */
  52. public double radToU(double radians) {
  53. return revToU(radians / Math.PI / 2);
  54. }
  55.  
  56. /**
  57. * Units to Revolutions Per Second
  58. * @param ticksPerRate Change in sensor position (ticks) per unit of time (ms)
  59. * @return Change in sensor position in terms of revolutions per second (RPS)
  60. */
  61. public double uToRPS(double ticksPerRate) {
  62. return ticksPerRate * (1000.0 / velocityRate) * (1.0 / unitsPerRevolution);
  63. }
  64.  
  65. /**
  66. * Units to Revolutions Per Minute
  67. * @param ticksPerRate Change in sensor position (ticks) per unit of time (ms)
  68. * @return Change in sensor position in terms of revolutions per minute (RPM)
  69. */
  70. public double uToRPM(double ticksPerRate) {
  71. return uToRPS(ticksPerRate) * 60;
  72. }
  73.  
  74. /**
  75. * Revolutions Per Second to Units
  76. * @param rps Change in sensor position in terms of revolutions per second (RPS)
  77. * @return Change in sensor position (ticks) per unit of time (ms)
  78. */
  79. public double rpsToU(double rps) {
  80. return (rps * (velocityRate / 1000.0)) * unitsPerRevolution;
  81. }
  82.  
  83. /**
  84. * Revolutions Per Minute to Units
  85. * @param rpm Change in sensor position in terms of revolutions per minute (RPM)
  86. * @return Change in sensor position (ticks) per unit of time (ms)
  87. */
  88. public double rpmToU(double rpm) {
  89. return rpsToU(rpm / 60);
  90. }
  91.  
  92. /**
  93. * Units to Radians Per Second
  94. * @param ticksPerRate Change in sensor position (ticks) per unit of time (ms)
  95. * @return Change in sensor position in terms of radians per second (RPS)
  96. */
  97. public double uToRadPerSec(double ticksPerRate) {
  98. return uToRPS(ticksPerRate) * Math.PI * 2;
  99. }
  100.  
  101. /**
  102. * Radians Per Second to Units
  103. * @param radiansPerSecond Change in sensor position in terms of radians per second (RPS)
  104. * @return Change in sensor position (ticks) per unit of time (ms)
  105. */
  106. public double radPerSecToU(double radiansPerSecond) {
  107. return rpsToU(radiansPerSecond / Math.PI / 2);
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment