Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Robots 2.21 KB | None | 0 0
  1. #pragma config(Sensor, dgtl1,  EncR,           sensorQuadEncoder)
  2. #pragma config(Sensor, dgtl3,  EncL,           sensorQuadEncoder)
  3. #pragma config(Sensor, dgtl11, Sonar,          sensorSONAR_cm)
  4. #pragma config(Motor,  port1,           RightMotor,    tmotorVex393_HBridge, openLoop, reversed, driveRight)
  5. #pragma config(Motor,  port2,           ARM,           tmotorVex393_MC29, openLoop)
  6. #pragma config(Motor,  port3,           Claw,          tmotorServoStandard, openLoop)
  7. #pragma config(Motor,  port10,          LeftMotor,     tmotorVex393_HBridge, openLoop, reversed, driveLeft)
  8. //*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
  9.  
  10. void ResetEncoders()
  11. { SensorValue[EncL] = 0;
  12.     SensorValue[EncR] = 0;
  13. }
  14.  
  15.  
  16. void DriveForwardUntilWall()
  17. {
  18.   while(SensorValue[Sonar] >= 30) {
  19.     motor[LeftMotor] = 60;
  20.     motor[RightMotor] = 60;}
  21. }
  22. void TurnRight(){
  23.  
  24.         while(SensorValue[EncR] < 270 || SensorValue[EncL] > -270)
  25. {
  26.         if(SensorValue[EncR] < 270) //PosEnc forward shaft rotation
  27. {
  28.         motor[RightMotor] = 63;
  29. }
  30.     else
  31. {
  32.         motor[RightMotor] = 0;
  33. }
  34.  
  35. if(SensorValue[EncL] > -270) //NegEnc reversed shaft rotation
  36. {
  37.  motor[LeftMotor] = -63;
  38. }
  39. else
  40. {
  41.  motor[LeftMotor] = 0;
  42. }
  43. }
  44.  
  45. void TurnLeft(){
  46.  
  47.         while(SensorValue[EncL] < -270 || SensorValue[EncR] > 270)
  48. {
  49.         if(SensorValue[EncL] < 270) //PosEnc forward shaft rotation
  50. {
  51.         motor[LeftMotor] = 63;
  52. }
  53.     else
  54. {
  55.         motor[LeftMotor] = 0;
  56. }
  57.  
  58. if(SensorValue[EncR] > -270) //NegEnc reversed shaft rotation
  59. {
  60.  motor[RightMotor] = -63;
  61. }
  62. else
  63. {
  64.  motor[RightMotor] = 0;
  65. }
  66. }
  67.  
  68.  
  69. }
  70.  
  71. void Stop(){
  72.   motor[LeftMotor] = 0;
  73.   motor[RightMotor] = 0;
  74.   }
  75.  
  76. task main(){
  77.         if (vexRT[Btn5U] == 1){
  78.             ResetEncoders();
  79.         wait1Msec(5000);
  80.         DriveForwardUntilWall();
  81.         ResetEncoders();
  82.         wait1Msec(5000);
  83.         TurnLeft();
  84.         Stop();
  85.         ResetEncoders();
  86.         DriveForwardUntilWall();
  87.         TurnRight();
  88.         Stop();
  89.         DriveForwardUntilWall();
  90.         TurnRight();
  91.         Stop();
  92.         ResetEncoders();
  93.         DriveForwardUntilWall();
  94.     return;
  95.     }
  96.         else{
  97.             setMotor(port3, vexRT[Ch2]/2);
  98.             if (vexRT[Btn8D] == 1){
  99.             arcadeControl(Ch3, Ch4, 18);
  100.             }
  101.             }
  102.     armControl(port2, Btn7U, Btn7D, 75);
  103.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement