Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. //Overloaded drive method to allow for no input (drive until hit wall), one input (inches), or two inputs (inches and power)
  2.  
  3. void Drive() {
  4. reset();
  5. left_motor.SetPercent(MOTOR_CORRECTION*DEFAULT_MOTOR_POWER);
  6. right_motor.SetPercent(DEFAULT_MOTOR_POWER);
  7. //using large number for isStall since there is no set distance
  8. while((top_right_micro.Value() || top_left_micro.Value()) && !isStall(10000)) {
  9. LCD.WriteRC(left_encoder.Counts(), 4, 5);
  10. LCD.WriteRC(right_encoder.Counts(), 5, 5);
  11. }
  12. reset();
  13. }
  14.  
  15. void Drive(float inches) {
  16. reset();
  17. float start = TimeNow();
  18. left_motor.SetPercent(MOTOR_CORRECTION*DEFAULT_MOTOR_POWER);
  19. right_motor.SetPercent(DEFAULT_MOTOR_POWER);
  20. while ( right_encoder.Counts() <= DRIVE_CORRECTION * COUNTS_PER_INCH * inches && TimeNow() - start < 10 && !isStall(DRIVE_CORRECTION * COUNTS_PER_INCH * inches)) {
  21. LCD.WriteRC(left_encoder.Counts(), 4, 5);
  22. LCD.WriteRC(right_encoder.Counts(), 5, 5);
  23. }
  24. reset();
  25. }
  26.  
  27. void Drive(int inches, int motorPower) {
  28. reset();
  29. float start = TimeNow();
  30. left_motor.SetPercent(MOTOR_CORRECTION * motorPower);
  31. right_motor.SetPercent(motorPower);
  32. while (right_encoder.Counts() <= DRIVE_CORRECTION * COUNTS_PER_INCH * inches && TimeNow() - start < 5 && !isStall(DRIVE_CORRECTION * COUNTS_PER_INCH * inches)) {
  33. LCD.WriteRC(left_encoder.Counts(), 4, 5);
  34. LCD.WriteRC(right_encoder.Counts(), 5, 5);
  35. }
  36. reset();
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement