Advertisement
Guest User

Untitled

a guest
Sep 15th, 2021
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.09 KB | None | 0 0
  1. /*----------------------------------------------------------------------------*/
  2. /* */
  3. /* Module: main.cpp */
  4. /* Author: samantha */
  5. /* Created: Tue Sep 14 2021 */
  6. /* Description: V5 project */
  7. /* */
  8. /*----------------------------------------------------------------------------*/
  9.  
  10. // ---- START VEXCODE CONFIGURED DEVICES ----
  11. // Robot Configuration:
  12. // [Name] [Type] [Port(s)]
  13. // leftDrives motor_group 1, 7
  14. // rightDrives motor_group 2, 8
  15. // Controller1 controller
  16. // MOGO motor 6
  17. // IntakeFront motor 5
  18. // IntakeTower motor 4
  19. // Lift motor 3
  20. // ---- END VEXCODE CONFIGURED DEVICES ----
  21.  
  22. #include "vex.h"
  23.  
  24. using namespace vex;
  25.  
  26. competition Competition;
  27.  
  28. //VARIABLES
  29. bool driveSlowToggled;
  30. bool intakeDirToggled;
  31. bool intakeToggled;
  32. int dir;
  33.  
  34. void pre_auton(void) {
  35. // Initializing Robot Configuration. DO NOT REMOVE!
  36. vexcodeInit();
  37. MOGO.setStopping(hold);
  38. Lift.setStopping(hold);
  39. leftDrives.setStopping(coast);
  40. rightDrives.setStopping(coast);
  41. Lift.setPosition(0, degrees);
  42. }
  43.  
  44. /*---------------------------------------------------------------------------*/
  45. /* */
  46. /* Autonomous Task */
  47. /* */
  48. /* This task is used to control your robot during the autonomous phase of */
  49. /* a VEX Competition. */
  50. /* */
  51. /* You must modify the code to add your own robot specific commands here. */
  52. /*---------------------------------------------------------------------------*/
  53.  
  54. void autonomous(void) {
  55.  
  56. }
  57.  
  58. /*---------------------------------------------------------------------------*/
  59. /* */
  60. /* User Control Task */
  61. /* */
  62. /* This task is used to control your robot during the user control phase of */
  63. /* a VEX Competition. */
  64. /* */
  65. /* You must modify the code to add your own robot specific commands here. */
  66. /*---------------------------------------------------------------------------*/
  67.  
  68. //////////////TOGGLERS////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  69.  
  70. //TOGGLE DRIVE SLOW
  71. void bPressed(){
  72. driveSlowToggled = !(driveSlowToggled);
  73. }
  74. //TOGGLE DRIVE REVERSE
  75. void xPressed(){
  76. dir *= -1;
  77. }
  78. //TOGGLE INTAKES
  79. void aPressed(){
  80. intakeToggled = !(intakeToggled);
  81. }
  82. void yPressed(){
  83. intakeDirToggled = !(intakeDirToggled);
  84. }
  85.  
  86. /////////USER CONTROL/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  87.  
  88. void usercontrol(void) {
  89. // User control code here, inside the loop
  90. driveSlowToggled = false;
  91. intakeDirToggled = false;
  92. intakeToggled = false;
  93. dir = 1;
  94. IntakeFront.setVelocity(50, percent);
  95. IntakeTower.setVelocity(100, percent);
  96. MOGO.setVelocity(100, percent);
  97. Lift.setVelocity(100,percent);
  98. while (1) {
  99. //lift Up/down r1/r2
  100. //Intakes - a toggle on/off
  101. //MOGO - l1/l2
  102. //A - Intakes toggle
  103. //B - drive speed toggle
  104. //Y - reverse intake
  105. //X - reverse drive
  106.  
  107. //lift 360 to -10
  108.  
  109. ///////DRIVING///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  110.  
  111. //DRIVE SPEED TOGGLE
  112. Controller1.ButtonB.pressed(bPressed);
  113. //DRIVE DIR TOGGLE
  114. Controller1.ButtonX.pressed(xPressed);
  115. //DRIVING
  116. if (Controller1.Axis2.position(percent) > 15 || Controller1.Axis2.position(percent) < -15) {
  117. if (driveSlowToggled == true){
  118. rightDrives.setVelocity((Controller1.Axis2.position(percent)/2*dir), percent);
  119. }
  120. else{
  121. rightDrives.setVelocity((Controller1.Axis2.position(percent)*dir), percent);
  122. }
  123. rightDrives.spin(forward);
  124. }
  125. else {
  126. rightDrives.stop();
  127. }
  128. if (Controller1.Axis3.position(percent) > 15 || Controller1.Axis3.position(percent) < -15) {
  129. if (driveSlowToggled == true){
  130. leftDrives.setVelocity((Controller1.Axis3.position(percent)/2*dir), percent);
  131. }
  132. else {
  133. leftDrives.setVelocity((Controller1.Axis3.position(percent)*dir), percent);
  134. }
  135. leftDrives.spin(forward);
  136. }
  137. else {
  138. leftDrives.stop();
  139. }
  140.  
  141.  
  142. ////////LIFTS//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  143.  
  144. //Front Lift
  145. if (Controller1.ButtonR1.pressing()){
  146. Lift.spin(reverse);
  147. }
  148. else if (Controller1.ButtonR2.pressing()){
  149. Lift.spin(forward);
  150. }
  151. else {
  152. Lift.stop();
  153. }
  154.  
  155. //BACK LIFT
  156. if (Controller1.ButtonL1.pressing()){
  157. MOGO.spin(reverse);
  158. }
  159. else if (Controller1.ButtonL2.pressing()){
  160. MOGO.spin(forward);
  161. }
  162. else {
  163. MOGO.stop();
  164. }
  165.  
  166. /////////INTAKES////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  167.  
  168. //INTAKES
  169. Controller1.ButtonA.pressed(aPressed);
  170. Controller1.ButtonY.pressed(yPressed);
  171. if (intakeToggled){
  172. if (intakeDirToggled){
  173. IntakeFront.spin(reverse);
  174. IntakeTower.spin(reverse);
  175. }
  176. else {
  177. IntakeFront.spin(forward);
  178. IntakeTower.spin(forward);
  179. }
  180. }
  181. else {
  182. IntakeFront.stop();
  183. IntakeTower.stop();
  184. }
  185.  
  186. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  187.  
  188. wait(20, msec); // Sleep the task for a short amount of time to
  189. // prevent wasted resources.
  190. }
  191. }
  192.  
  193. //
  194. // Main will set up the competition functions and callbacks.
  195. //
  196. int main() {
  197. // Set up callbacks for autonomous and driver control periods.
  198. Competition.autonomous(autonomous);
  199. Competition.drivercontrol(usercontrol);
  200.  
  201. // Run the pre-autonomous function.
  202. pre_auton();
  203.  
  204. // Prevent main from exiting with an infinite loop.
  205. while (true) {
  206. wait(100, msec);
  207. }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement