Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. void liftClaw(int16 dist, int dir) {
  2.     int32 pdist = 0;
  3.     int32 psdist = 0; // starting distance
  4.    
  5.     int32 pdistSE = dist*PULLEY_DIST_COEFF; // Xdist converted to QuadDec counter value
  6.    
  7.     int done=0;
  8.    
  9.     // start shaft encoders
  10.     psdist = (getDistance(2,0)); // get right starting dist
  11.    
  12.     // set speed
  13.     if (dir) {
  14.         PWM_2_WriteCompare(pllspeed);
  15.     } else {
  16.         PWM_2_WriteCompare(pllspeed/2);
  17.     }
  18.    
  19.     // set direction
  20.     A5_Write(!dir);
  21.     A6_Write(dir);
  22.    
  23.     // poll SEs every 20ms, when both shaft encoders read X distance, stop
  24.     while (!done) {
  25.  
  26. //        CyDelay(5); // the smaller this value, the more often the SEs are polled and hence the more accurate the distance
  27.        
  28.         // get relative pulley travel distance
  29.         pdist = (getDistance(2,psdist));
  30.        
  31.         if (!DRIVESILENT) {
  32.             UART_1_PutString("\nPdist = ");
  33.             printNumUART(pdist);
  34.         }
  35.        
  36.         /* When pulley reaches target distance, stop it */
  37.         if (abs(pdist)>=pdistSE) {
  38.             A5_Write(0);
  39.             A6_Write(0);
  40.             done=1;
  41.         }
  42.     }
  43.    
  44.     CyDelay(10);
  45.    
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement