Advertisement
Trainlover08

Untitled

Feb 19th, 2025
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. class Drive_PID_Tuner {
  2. public:
  3.     Drive_PID_Tuner (pros::Controller* controller, lemlib::PID* pid);
  4.     void print_values ();
  5.     void change_values ();
  6.    
  7.     pros::Controller* controller;
  8.     lemlib::PID* pid;
  9. };
  10.  
  11. void Drive_PID_Tuner::print_values () {
  12.     this->controller->print(0, 0, "P: %f", this->pid->p_gain);
  13.     this->controller->print(1, 0, "I: %f", this->pid->i_gain);
  14.     this->controller->print(2, 0, "D: %f," this->pid->d_gian);
  15. }
  16.  
  17. void Drive_PID_Tuner::change_values () {
  18.     double p = this->pid->p_gain;
  19.     double i = this->pid->i_gain;
  20.     double d = this->pid->d_gain;
  21.     if (this->controller->get_digital(pros::E_CONTROLLER_DIGITAL_UP)) {
  22.         p += 0.1;
  23.         pros::delay(100);
  24.     } else if (this->controller->get_digital(pros::E_CONTROLLER_DIGITAL_DOWN)) {
  25.         p -= 0.1;
  26.         pros::delay(100);
  27.     } else if (this->controller->get_digital(pros::E_CONTROLLER_DIGITAL_Y)) {
  28.         i += 0.01;
  29.         pros::delay(100);
  30.     } else if (this->controller->get_digital(pros::E_CONTROLLER_DIGITAL_X)) {
  31.         i -= 0.01;
  32.         pros::delay(100);
  33.     } else if (this->controller->get_digital(pros::E_CONTROLLER_DIGITAL_A)) {
  34.         d += 1.0;
  35.         pros::delay(100);
  36.     } else if (this->controller->get_digital(pros::E_CONTROLLER_DIGITAL_B)) {
  37.         d -= 1.0;
  38.         pros::delay(100);
  39.     }
  40.     if (p < 0.0) p = 0.0;
  41.     if (i < 0.0) i = 0.0;
  42.     if (d < 0.0) d = 0.0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement