Advertisement
Trainlover08

Vex Transmission 0.2 GPT response

Jun 3rd, 2023 (edited)
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.09 KB | None | 0 0
  1. #include <iostream>
  2. #include "vex.h"
  3.  
  4. using namespace vex;
  5.  
  6. int Laxle_speed = 0;
  7. int Raxle_speed = 0;
  8. int Left_Bank_rpm = 0;
  9. int Right_Bank_rpm = 0;
  10. int Left_Bank_power = 0;
  11. int Right_Bank_power = 0;
  12. int gear = 1;
  13. bool PTOtoggle = true;
  14.  
  15. vex::solenoid Solenoid[] = { vex::solenoid(A), vex::solenoid(B), vex::solenoid(C), vex::solenoid(D), vex::solenoid(E), vex::solenoid(F) };
  16. bool solenoidStates[] = { false, false, false, false, false, false };
  17.  
  18. void Gear1() {
  19.     solenoidStates[0] = true;
  20.     solenoidStates[1] = true;
  21.     gear = 1;
  22. }
  23.  
  24. void Gear2() {
  25.     solenoidStates[1] = true;
  26.     solenoidStates[2] = true;
  27.     gear = 2;
  28. }
  29.  
  30. void Gear3() {
  31.     solenoidStates[2] = true;
  32.     solenoidStates[3] = true;
  33.     gear = 3;
  34. }
  35.  
  36. void Gear4() {
  37.     solenoidStates[3] = true;
  38.     solenoidStates[4] = true;
  39.     gear = 4;
  40. }
  41.  
  42. void Aux1() {
  43.     solenoidStates[4] = true;
  44.     solenoidStates[5] = true;
  45.     gear = -1;
  46. }
  47.  
  48. void Aux2() {
  49.     solenoidStates[5] = true;
  50.     gear = -2;
  51. }
  52.  
  53. void Aux3() {
  54.     for (int i = 0; i < 6; i++) {
  55.         solenoidStates[i] = false;
  56.     }
  57.     gear = -3;
  58. }
  59.  
  60. void UpShift() {
  61.     if (PTOtoggle == false) {
  62.         if (gear <= 1) {
  63.             Gear2();
  64.         } else if (gear == 2) {
  65.             Gear3();
  66.         } else if (gear == 3) {
  67.             Gear4();
  68.         }
  69.     } else {
  70.         if (gear == -3) {
  71.             Aux2();
  72.         } else if (gear == -2) {
  73.             Aux1();
  74.         }
  75.     }
  76.     this_thread::sleep_for(500);
  77. }
  78.  
  79. void DownShift() {
  80.     if (PTOtoggle == false) {
  81.         if (gear == 2) {
  82.             Gear1();
  83.         } else if (gear == 3) {
  84.             Gear2();
  85.         } else if (gear == 4) {
  86.             Gear3();
  87.         }
  88.     } else {
  89.         if (gear == -2) {
  90.             Aux3();
  91.         } else if (gear => -1) {
  92.             Aux2();
  93.         }
  94.     }
  95.     this_thread::sleep_for(500);
  96. }
  97.  
  98. int main() {
  99.     // Initializing the VEX Brain
  100.     vex::brain Brain;
  101.  
  102.     // Set the motor brake mode to hold
  103.     vex::motor LeftMotor = vex::motor(vex::PORT1, vex::gearSetting::ratio18_1, true);
  104.     vex::motor RightMotor = vex::motor(vex::PORT2, vex::gearSetting::ratio18_1);
  105.  
  106.     // Create a drive base with two motors
  107.     motor_group driveBase = motor_group(LeftMotor, RightMotor);
  108.  
  109.     // Configure the controller
  110.     controller Controller = controller(primary);
  111.  
  112.     vex::Gif gif("world.gif", 120, 0);
  113.  
  114.     UpShift(2);
  115.     PTOtoggle = false;
  116.     UpShift();
  117.  
  118.     while (true) {
  119.         if (Brain.Controller1.ButtonR1.pressing()) {
  120.             UpShift();
  121.         }
  122.  
  123.         if (Brain.Controller1.ButtonR2.pressing()) {
  124.             DownShift();
  125.         }
  126.  
  127.         if (Brain.Controller1.ButtonB.pressing()) {
  128.             PTOtoggle = !PTOtoggle;
  129.         }
  130.  
  131.         // Get joystick positions
  132.         int RightStickY = Controller.Axis2.position(percentUnits::pct);
  133.         int RightStickX = Controller.Axis1.position(percentUnits::pct);
  134.  
  135.         // Calculate motor velocities based on joystick inputs
  136.         double y = 0;
  137.         double x = RightStickX;
  138.  
  139.         if (x < 0) {
  140.             x = -x;
  141.         }
  142.  
  143.         if (0 <= x && x < 60) {
  144.             y = pow(1.04029, x * 1.284467);
  145.         } else if (60 <= x && x < 80) {
  146.             y = 0.75 * x - 25;
  147.         } else if (80 <= x && x <= 108) {
  148.             y = 1.0357 * x - 47.85714857;
  149.         } else if (x > 108) {
  150.             y = 63 + pow(1.232099, x - 108);
  151.         } else if (x >= 128) {
  152.             y = 128;
  153.         }
  154.  
  155.         if (RightStickX < 0) {
  156.             y = -y;
  157.         }
  158.  
  159.         double steerX = RightStickX;
  160.         double rightWheels = y - steerX;
  161.         double leftWheels = y + steerX;
  162.  
  163.         // Set the motor velocities
  164.         driveBase.setVelocity(rightWheels, percentUnits::pct);
  165.         driveBase.setVelocity(leftWheels, percentUnits::pct);
  166.  
  167.         // Run the motors
  168.         driveBase.spin(forward);
  169.  
  170.         // Print GIF frame index on the Brain screen
  171.         Brain.Screen.printAt(5, 230, "frame %3d", gif.getFrameIndex());
  172.  
  173.         // Delay for smooth GIF playback
  174.         this_thread::sleep_for(10);
  175.     }
  176. }
  177.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement