Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode.drive;
  2.  
  3. import com.acmerobotics.dashboard.config.Config;
  4. import com.acmerobotics.roadrunner.control.PIDCoefficients;
  5. import com.acmerobotics.roadrunner.trajectory.constraints.DriveConstraints;
  6. import com.qualcomm.hardware.motors.NeveRest20Gearmotor;
  7. import com.qualcomm.hardware.motors.NeveRest60Gearmotor;
  8. import com.qualcomm.robotcore.hardware.configuration.typecontainers.MotorConfigurationType;
  9.  
  10. /*
  11. * Constants shared between multiple drive types.
  12. *
  13. * TODO: Tune or adjust the following constants to fit your robot. Note that the non-final
  14. * fields may also be edited through the dashboard (connect to the robot's WiFi network and
  15. * navigate to https://192.168.49.1:8080/dash). Make sure to save the values here after you
  16. * adjust them in the dashboard; **config variable changes don't persist between app restarts**.
  17. *
  18. * These are not the only parameters; some are located in the localizer classes, drive base classes,
  19. * and op modes themselves.
  20. */
  21. @Config
  22. public class DriveConstants {
  23.  
  24. /*
  25. * The type of motor used on the drivetrain. While the SDK has definitions for many common
  26. * motors, there may be slight gear ratio inaccuracies for planetary gearboxes and other
  27. * discrepancies. Additional motor types can be defined via an interface with the
  28. * @DeviceProperties and @MotorType annotations.
  29. */
  30. private static final MotorConfigurationType MOTOR_CONFIG =
  31. MotorConfigurationType.getMotorType(NeveRest60Gearmotor.class);
  32.  
  33. /*
  34. * Set the first flag appropriately. If using the built-in motor velocity PID, update
  35. * MOTOR_VELO_PID with the tuned coefficients from DriveVelocityPIDTuner.
  36. */
  37. public static final boolean RUN_USING_ENCODER = true;
  38. public static final PIDCoefficients MOTOR_VELO_PID = null; // P = 20
  39.  
  40. /*
  41. * These are physical constants that can be determined from your robot (including the track
  42. * width; it will be tune empirically later although a rough estimate is important). Users are
  43. * free to chose whichever linear distance unit they would like so long as it is consistently
  44. * used. The default values were selected with inches in mind. Road runner uses radians for
  45. * angular distances although most angular parameters are wrapped in Math.toRadians() for
  46. * convenience. Make sure to exclude any gear ratio included in MOTOR_CONFIG from GEAR_RATIO.
  47. */
  48. public static double WHEEL_RADIUS = 2;
  49. public static double GEAR_RATIO = 1.29; // output (wheel) speed / input (motor) speed
  50. public static double TRACK_WIDTH = 14.8;
  51.  
  52. /*
  53. * These are the feedforward parameters used to model the drive motor behavior. If you are using
  54. * the built-in velocity PID, *these values are fine as is*. However, if you do not have drive
  55. * motor encoders or have elected not to use them for velocity control, these values should be
  56. * empirically tuned.
  57. */
  58. public static double kV = 1.0 / rpmToVelocity(getMaxRpm());
  59. public static double kA = 0;
  60. public static double kStatic = 0;
  61.  
  62. /*
  63. * These values are used to generate the trajectories for you robot. To ensure proper operation,
  64. * the constraints should never exceed ~80% of the robot's actual capabilities. While Road
  65. * Runner is designed to enable faster autonomous motion, it is a good idea for testing to start
  66. * small and gradually increase them later after everything is working. The velocity and
  67. * acceleration values are required, and the jerk values are optional (setting a jerk of 0.0
  68. * forces acceleration-limited profiling).
  69. */
  70. public static DriveConstraints BASE_CONSTRAINTS = new DriveConstraints(
  71. 30.0, 30.0, 0.0,
  72. Math.toRadians(180.0), Math.toRadians(180.0), 0.0
  73. );
  74.  
  75.  
  76. public static double encoderTicksToInches(double ticks) {
  77. return WHEEL_RADIUS * 2 * Math.PI * GEAR_RATIO * ticks / MOTOR_CONFIG.getTicksPerRev();
  78. }
  79.  
  80. public static double rpmToVelocity(double rpm) {
  81. return rpm * GEAR_RATIO * 2 * Math.PI * WHEEL_RADIUS / 60.0;
  82. }
  83.  
  84. public static double getMaxRpm() {
  85. return MOTOR_CONFIG.getMaxRPM() *
  86. (RUN_USING_ENCODER ? MOTOR_CONFIG.getAchieveableMaxRPMFraction() : 1.0);
  87. }
  88.  
  89. public static double getTicksPerSec() {
  90. // note: MotorConfigurationType#getAchieveableMaxTicksPerSecond() isn't quite what we want
  91. return (MOTOR_CONFIG.getMaxRPM() * MOTOR_CONFIG.getTicksPerRev() / 60.0);
  92. }
  93.  
  94. public static double getMotorVelocityF() {
  95. // see https://docs.google.com/document/d/1tyWrXDfMidwYyP_5H4mZyVgaEswhOC35gvdmP-V-5hA/edit#heading=h.61g9ixenznbx
  96. return 32767 / getTicksPerSec();
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement