Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void liftClaw(int16 dist, int dir) {
- int32 pdist = 0;
- int32 psdist = 0; // starting distance
- int32 pdistSE = dist*PULLEY_DIST_COEFF; // Xdist converted to QuadDec counter value
- int done=0;
- // start shaft encoders
- psdist = (getDistance(2,0)); // get right starting dist
- // set speed
- if (dir) {
- PWM_2_WriteCompare(pllspeed);
- } else {
- PWM_2_WriteCompare(pllspeed/2);
- }
- // set direction
- A5_Write(!dir);
- A6_Write(dir);
- // poll SEs every 20ms, when both shaft encoders read X distance, stop
- while (!done) {
- // CyDelay(5); // the smaller this value, the more often the SEs are polled and hence the more accurate the distance
- // get relative pulley travel distance
- pdist = (getDistance(2,psdist));
- if (!DRIVESILENT) {
- UART_1_PutString("\nPdist = ");
- printNumUART(pdist);
- }
- /* When pulley reaches target distance, stop it */
- if (abs(pdist)>=pdistSE) {
- A5_Write(0);
- A6_Write(0);
- done=1;
- }
- }
- CyDelay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement