Advertisement
Trainlover08

Untitled

Oct 10th, 2023
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. #pragma region VEXcode Generated Robot Configuration
  2. // Make sure all required headers are included.
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <stdbool.h>
  6. #include <math.h>
  7. #include <string.h>
  8.  
  9.  
  10. #include "vex.h"
  11.  
  12. using namespace vex;
  13.  
  14. // Brain should be defined by default
  15. brain Brain;
  16.  
  17.  
  18. // START V5 MACROS
  19. #define waitUntil(condition) \
  20. do { \
  21. wait(5, msec); \
  22. } while (!(condition))
  23.  
  24. #define repeat(iterations) \
  25. for (int iterator = 0; iterator < iterations; iterator++)
  26. // END V5 MACROS
  27.  
  28.  
  29. // Robot configuration code.
  30. controller Controller1 = controller(primary);
  31. motor leftMotorA = motor(PORT14, ratio6_1, false);
  32. motor leftMotorB = motor(PORT11, ratio6_1, false);
  33. motor_group LeftDriveSmart = motor_group(leftMotorA, leftMotorB);
  34. motor rightMotorA = motor(PORT17, ratio6_1, true);
  35. motor rightMotorB = motor(PORT19, ratio6_1, true);
  36. motor_group RightDriveSmart = motor_group(rightMotorA, rightMotorB);
  37. drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 219.44, 295, 40, mm, 1);
  38.  
  39. motor cataMotorA = motor(PORT8, ratio36_1, false);
  40. motor cataMotorB = motor(PORT3, ratio36_1, true);
  41. motor_group cata = motor_group(cataMotorA, cataMotorB);
  42.  
  43. motor MotorGroup7MotorA = motor(PORT4, ratio36_1, true);
  44. motor MotorGroup7MotorB = motor(PORT9, ratio36_1, false);
  45. motor_group MotorGroup7 = motor_group(MotorGroup7MotorA, MotorGroup7MotorB);
  46.  
  47. digital_out DigitalOutB = digital_out(Brain.ThreeWirePort.B);
  48. digital_out DigitalOutD = digital_out(Brain.ThreeWirePort.D);
  49.  
  50.  
  51.  
  52. // define variable for remote controller enable/disable
  53. bool RemoteControlCodeEnabled = true;
  54. // define variables used for controlling motors based on controller inputs
  55. bool DrivetrainLNeedsToBeStopped_Controller1 = true;
  56. bool DrivetrainRNeedsToBeStopped_Controller1 = true;
  57.  
  58. // define a task that will handle monitoring inputs from Controller1
  59. int rc_auto_loop_function_Controller1() {
  60. // process the controller input every 20 milliseconds
  61. // update the motors based on the input values
  62. while(true) {
  63. if(RemoteControlCodeEnabled) {
  64.  
  65. // calculate the drivetrain motor velocities from the controller joystick axies
  66. // left = Axis3 + Axis1
  67. // right = Axis3 - Axis1
  68. int drivetrainLeftSideSpeed = Controller1.Axis3.position() + Controller1.Axis1.position();
  69. int drivetrainRightSideSpeed = Controller1.Axis3.position() - Controller1.Axis1.position();
  70.  
  71. // check if the value is inside of the deadband range
  72. if (drivetrainLeftSideSpeed < 5 && drivetrainLeftSideSpeed > -5) {
  73. // check if the left motor has already been stopped
  74. if (DrivetrainLNeedsToBeStopped_Controller1) {
  75. // stop the left drive motor
  76. LeftDriveSmart.stop();
  77. // tell the code that the left motor has been stopped
  78. DrivetrainLNeedsToBeStopped_Controller1 = false;
  79. }
  80. } else {
  81. // reset the toggle so that the deadband code knows to stop the left motor nexttime the input is in the deadband range
  82. DrivetrainLNeedsToBeStopped_Controller1 = true;
  83. }
  84. // check if the value is inside of the deadband range
  85. if (drivetrainRightSideSpeed < 5 && drivetrainRightSideSpeed > -5) {
  86. // check if the right motor has already been stopped
  87. if (DrivetrainRNeedsToBeStopped_Controller1) {
  88. // stop the right drive motor
  89. RightDriveSmart.stop();
  90. // tell the code that the right motor has been stopped
  91. DrivetrainRNeedsToBeStopped_Controller1 = false;
  92. }
  93. } else {
  94. // reset the toggle so that the deadband code knows to stop the right motor next time the input is in the deadband range
  95. DrivetrainRNeedsToBeStopped_Controller1 = true;
  96. }
  97.  
  98. // only tell the left drive motor to spin if the values are not in the deadband range
  99. if (DrivetrainLNeedsToBeStopped_Controller1) {
  100. LeftDriveSmart.setVelocity(drivetrainLeftSideSpeed, percent);
  101. LeftDriveSmart.spin(forward);
  102. }
  103. // only tell the right drive motor to spin if the values are not in the deadband range
  104. if (DrivetrainRNeedsToBeStopped_Controller1) {
  105. RightDriveSmart.setVelocity(drivetrainRightSideSpeed, percent);
  106. RightDriveSmart.spin(forward);
  107. }
  108. }
  109. // wait before repeating the process
  110. wait(20, msec);
  111. }
  112. return 0;
  113. }
  114.  
  115. task rc_auto_loop_task_Controller1(rc_auto_loop_function_Controller1);
  116. #pragma endregion VEXcode Generated Robot Configuration
  117.  
  118. // Include the V5 Library
  119. #include "vex.h"
  120.  
  121. // Allows for easier use of the VEX Library
  122. using namespace vex;
  123.  
  124. float myVariable, no;
  125.  
  126. // "when started" hat block
  127. int whenStarted1() {
  128. Drivetrain.setDriveVelocity(600.0, rpm);
  129. Drivetrain.setTurnVelocity(100.0, percent);
  130. MotorGroup7.setMaxTorque(100, percent);
  131. MotorGroup7.setVelocity(100, percent);
  132. cata.setMaxTorque(100, percent);
  133. cata.setVelocity(100, percent);
  134. bool wingState = false;
  135. while (true) {
  136. DigitalOutB.set(true);
  137. cata.setStopping(hold);
  138. if(Controller1.ButtonDown.pressing()){
  139. cata.spin(reverse);
  140. }
  141. if(Controller1.ButtonUp.pressing()){
  142. cata.spin(forward);
  143. }
  144. if(Controller1.ButtonA.pressing()){
  145. cata.spinFor(forward, 360, degrees);
  146. DigitalOutB.set(true);
  147. wait(250, msec);
  148. } else{
  149. DigitalOutB.set(false);
  150. }
  151. if(Controller1.ButtonLeft.pressing()){
  152. wingState = !wingState;
  153. }
  154. if (wingState == true){
  155. DigitalOutD.set(true);
  156. } else{
  157. DigitalOutD.set(false);
  158. }
  159. wait(5, msec);
  160. }
  161. return 0;
  162. }
  163.  
  164.  
  165. int main() {
  166. // post event registration
  167.  
  168. // set default print color to black
  169. printf("\033[30m");
  170.  
  171. // wait for rotation sensor to fully initialize
  172. wait(30, msec);
  173.  
  174. whenStarted1();
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement