Advertisement
xDefo

g funziona per un pezzo

May 24th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.75 KB | None | 0 0
  1. #pragma config(Sensor, S1,     gyroscope,      sensorEV3_Gyro)
  2. #pragma config(Sensor, S2,     colorSensor,    sensorEV3_Color, modeEV3Color_Color)
  3. #pragma config(Sensor, S3,     frontSensor,    sensorEV3_Ultrasonic)
  4. #pragma config(Sensor, S4,     leftSensor,     sensorEV3_Ultrasonic)
  5. #pragma config(Motor,  motorA,          leftMotor,     tmotorEV3_Large, PIDControl, driveLeft, encoder)
  6. #pragma config(Motor,  motorB,          rightMotor,    tmotorEV3_Large, PIDControl, driveRight, encoder)
  7. #pragma config(Motor,  motorC,          clawLifter,    tmotorEV3_Large, PIDControl, encoder)
  8. #pragma config(Motor,  motorD,          claw,          tmotorEV3_Medium, PIDControl, encoder)
  9. //*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
  10.  
  11. //Il nero lo scarta, il rosso lo mette nella chest a DX e il blu a SX.
  12.  
  13. const int moveforwardVelocity=20;
  14.  
  15. const int claw_Velocity=50;
  16. const int claw_PositionOpen=3*360;
  17. const int claw_PositionClose=-2.5*360;
  18.  
  19. const int clawLifter_Velocity=-50;
  20. const int clawLifter_PositionUp=360;
  21. const int clawLifter_PositionDown=360;
  22.  
  23. const double Front_Object_distance = 10;
  24. const int Left_Object_distance= 38;
  25. const int Blue = 5;
  26. const int Red = 3;
  27.  bool compreso= false;
  28.       bool mainore =false;
  29.       bool maggiore =false;
  30. int tragitto=1;
  31. int oggettipresi=0;
  32. int distans=0;
  33. int contatore = 0;
  34.  
  35. void moveForward(double v){
  36.     if(v>0){
  37.         double n= v/20.4
  38.         moveMotorTarget(motorA,n*360, 20);
  39.         moveMotorTarget(motorB,n*360, 20);
  40.         sleep(n*1000);
  41.     }
  42.     else if(v<0){
  43.         double n= v/20.4
  44.         moveMotorTarget(motorA,n*360, -20);
  45.         moveMotorTarget(motorB,n*360, -20);
  46.         sleep(n*1000);
  47.     }
  48. }
  49.  
  50. void movement (int V1, int V2 ){ // Funzione potenza hai motori;
  51.     motor[motorA]=V1;
  52.     motor[motorB]=V2;
  53.     wait1Msec(1);
  54. }
  55.  
  56. //Funzione che rileva la presenza di oggetti sulla sinistra confrontando la distanza con parametro passato alla funzione
  57. bool objectDetectedLeft(double a){
  58.     if(getUSDistance(leftSensor)<=a){
  59.         return true ;
  60.     }
  61.     else return false;
  62. }
  63.  
  64. //Funzione che rileva la presenza di oggetti  di fronte confrontando la distanza con parametro passato alla funzione
  65. bool objectDetectedFront(double a){
  66.     if(getUSDistance(frontSensor)<=a){
  67.         return true ;
  68.     }
  69.     else return false;
  70. }
  71.  
  72. void openClaw (){ //Funzione apri pinza
  73.     moveMotorTarget(claw,claw_PositionOpen,claw_Velocity);
  74.     sleep(500);
  75. }
  76.  
  77. void closeClaw(){ //Funzione chiudi pinza
  78.     moveMotorTarget(claw,claw_PositionClose,-claw_Velocity);
  79.     sleep(500);
  80. }
  81.  
  82. void liftClaw(){ //Alza braccio
  83.     moveMotorTarget(clawLifter,clawLifter_PositionUp+10,clawLifter_Velocity);
  84.     sleep(500);
  85. }
  86.  
  87. void fallClaw(){ //Abbassa braccio
  88.     moveMotorTarget(clawLifter,clawLifter_PositionDown-50,-clawLifter_Velocity);
  89.     sleep(500);
  90. }
  91.  
  92.  
  93. void turn(int c, int gradi){
  94.     resetGyro(gyroscope);
  95.     switch(c){
  96.         case 1:
  97.         while(getGyroDegrees(gyroscope)<gradi){
  98.         motor[motorA]=-10;
  99.         motor[motorB]=10;
  100.             wait1Msec(1);}
  101.         break;
  102.         case 2:     while(getGyroDegrees(gyroscope)>-gradi){
  103.                 motor[motorA]=10;
  104.         motor[motorB]=-10;
  105.             wait1Msec(1);
  106.             }
  107.             break;}
  108. }
  109.    
  110.  
  111.  
  112. void initialize(){// Funzione di inizializazione
  113.     liftClaw();
  114.     openClaw();
  115.     moveForward(40);
  116.     turn('R',90);
  117.     moveForward(30);
  118.  
  119. }
  120.  
  121. void liftObject(){ // Funzione prendi oggetto
  122.     movement(0,0);
  123.     fallClaw();
  124.     delay(1000);
  125. }
  126.  
  127. void releaseObject(){//Rilascia oggetto
  128.     movement(0,0);
  129.     fallClaw();
  130.     openClaw();
  131.     liftClaw();
  132. }
  133.  
  134.  
  135. task main(){
  136. //closeClaw();
  137.      liftClaw(); //alza pinza funziona
  138.      openClaw(); // apre pinza funziona
  139.      movement(-30,-30);
  140.      wait1Msec(3000);
  141.      movement(0,0);
  142.      wait1Msec(500);
  143.      movement(10,10);
  144.      wait1Msec(4000);
  145.      movement(0,0);
  146.      wait1Msec(500);
  147.      turn(2,90);
  148.      movement(0,0);
  149.      sleep(500);
  150.      movement(-50,-50);
  151.      sleep(2500);
  152.      movement(0,0);
  153.      sleep(500);
  154.      movement(10,10);
  155.      sleep(5500);
  156.     //AVANTI FIN QUANDO NON RILEVA NULLA A SINISTRA
  157.      while(!objectDetectedLeft(Left_Object_distance)){
  158.         movement(20,20);
  159.         sleep(500);
  160.                 movement(0,0);
  161.         sleep(500);
  162.         }
  163. //  UNA VOLTA RILEVATO GIRA A SINISTRA
  164.     moveForward(-6);
  165.     sleep(1000);
  166.     while(!objectDetectedFront(20)){movement(-10,10);delay(100);}
  167.  
  168. while(!objectDetectedFront(Front_Object_distance)){
  169.         movement(10,10);
  170.         sleep(500);
  171.         movement(0,0);
  172.         sleep(500);
  173.     }
  174.     //PRENDE L'OGGETTO
  175.     liftObject();
  176. //giusto
  177.  
  178.     if(getColorName(colorSensor)!= colorBlue && getColorName(colorSensor) != colorRed){
  179.         movement(10,10);
  180.         sleep(350);
  181.         movement(0,0);
  182.         sleep(500);
  183.         closeClaw();
  184.         sleep(1000);
  185.         liftclaw();
  186.         sleep (2000);
  187.         movement(-20,-20);
  188.         delay(4000);
  189.         turn(2,90);
  190.         movement(0,0);
  191.         delay(500);
  192.    
  193.      while(!objectDetectedFront(5))
  194.             {
  195.                         movement(50,50);
  196.  
  197.             }
  198.             openClaw();
  199.             sleep(500);
  200.             closeClaw();
  201.             movement(-10,10);
  202.             sleep(1000);
  203.      
  204.     }
  205.     //funziona
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement