Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. #pragma config(Motor, port1, leftMotor, tmotorVex393, openLoop, reversed)
  2. #pragma config(Motor, port6, clawMotor, tmotorVex269, openLoop, reversed)
  3. #pragma config(Motor, port7, armMotor, tmotorVex393, openLoop, reversed)
  4. #pragma config(Motor, port10, rightMotor, tmotorVex393, openLoop)
  5.  
  6. //--------------------------------------------| FUNCTIONS |-------------------------------------------
  7. void forward(int forwardTime)
  8. {
  9. motor[rightMotor] = 75;
  10. motor[leftMotor] = 75;
  11. wait1Msec(forwardTime);
  12.  
  13. motor[rightMotor] = 0;
  14. motor[leftMotor] = 0;
  15. wait1Msec(1000);
  16. }
  17. void backward(int backwardTime)
  18. {
  19. motor[rightMotor] = -75;
  20. motor[leftMotor] = -75;
  21. wait1Msec(backwardTime);
  22.  
  23. motor[rightMotor] = 0;
  24. motor[leftMotor] = 0;
  25. wait1Msec(1000);
  26. }
  27. void rightTurn(int rightTurnTime)
  28. {
  29. motor[rightMotor] = -75;
  30. motor[leftMotor] = 75;
  31. wait1Msec(rightTurnTime);
  32.  
  33. motor[rightMotor] = 0;
  34. motor[leftMotor] = 0;
  35. wait1Msec(1000);
  36. }
  37.  
  38. void leftTurn(int leftTurnTime)
  39. {
  40. motor[rightMotor] = 75;
  41. motor[leftMotor] = -75;
  42. wait1Msec(leftTurnTime);
  43.  
  44. motor[rightMotor] = 0;
  45. motor[leftMotor] = 0;
  46. wait1Msec(1000);
  47. }
  48. //----------------------------------------------------------------------------------------------------
  49.  
  50. //============================================| TASK ONE |============================================
  51. task One()
  52. {
  53. forward(1000);
  54. backward(1000);
  55. rightTurn(1000);
  56. leftTurn(1000);
  57. }
  58.  
  59. //====================================================================================================
  60.  
  61. //+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
  62. task main ()
  63. {
  64. int threshold = 15; // helps to eliminate 'noise' from a joystick that isn't perfectly at (0,0)
  65. // feel free to change this to match your needs.
  66.  
  67. while(1 == 1)
  68. {
  69. if(abs(vexRT[Ch3]) > threshold) // If the left joystick is greater than or less than the threshold:
  70. {
  71. motor[leftMotor] = (vexRT[Ch3]); // Left Joystick Y value.
  72. }
  73. else // If the left joystick is within the threshold:
  74. {
  75. motor[leftMotor] = 0; // Stop the left motor (cancel noise)
  76. }
  77.  
  78. if(abs(vexRT[Ch2]) > threshold) // If the right joystick is greater than or less than the threshold:
  79. {
  80. motor[rightMotor] = (vexRT[Ch2]); // Right Joystick Y value.
  81. }
  82. else // If the right joystick is within the threshold:
  83. {
  84. motor[rightMotor] = 0; // Stop the right motor (cancel noise)
  85. }
  86.  
  87. // Raise, lower or do not move arm
  88. if(vexRT[Btn5U] == 1) //If button 5U is pressed...
  89. {
  90. motor[armMotor] = 127; //...raise the arm.
  91. }
  92. else if(vexRT[Btn5D] == 1) //Else, if button 5D is pressed...
  93. {
  94. motor[armMotor] = -127; //...lower the arm.
  95. }
  96. else if(vexRT[Btn7U] == 1) //If Left D-Pad is pressed up...
  97. {
  98. motor[armMotor] = 25; //...raise the arm at half speed.
  99. }
  100. else if(vexRT[Btn7D] == 1) //If Left D-Pad is pressed down...
  101. {
  102. motor[armMotor] = -20; //...lower the arm at half speed.
  103. }
  104. else //Else (neither button is pressed)...
  105. {
  106. motor[armMotor] = 0; //...stop the arm.
  107. }
  108.  
  109. // Open, close or do not more claw
  110. if(vexRT[Btn6U] == 1) //If Button 6U is pressed...
  111. {
  112. motor[clawMotor] = 127; //...close the gripper.
  113. }
  114. else if(vexRT[Btn6D] == 1) //Else, if button 6D is pressed...
  115. {
  116. motor[clawMotor] = -127; //...open the gripper.
  117. }
  118. else if(vexRT[Btn8U] == 1) //If Left D-Pad is pressed up...
  119. {
  120. motor[clawMotor] = 35; //...close the gripper at half speed.
  121. }
  122. else if(vexRT[Btn8D] == 1) //If Left D-Pad is pressed down...
  123. {
  124. motor[clawMotor] = -20; //...open the gripper at half speed.
  125. }
  126. else //Else (neither button is pressed)...
  127. {
  128. motor[clawMotor] = 0; //...stop the gripper.
  129. }
  130. }
  131. }
  132. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement