Presentation is loading. Please wait.

Presentation is loading. Please wait.

How to Fix “Glitchy” Servo Code

Similar presentations


Presentation on theme: "How to Fix “Glitchy” Servo Code"— Presentation transcript:

1 How to Fix . . . “Glitchy” Servo Code
Mike Zook 05-Sep-2016

2 Original Code //Partially working method to experiment with the servo, works but is very glitchy public void servoTest2(){ if (gamepad1.a) { if(buttonAPushed) servo1.setPosition(1); buttonAPushed = false; } else if(!buttonAPushed) servo1.setPosition(0); buttonAPushed = true;

3 Original Code Sequence

4 The Glitch The servo position is continuously toggling between 0% and 100% while the Gamepad <A> button is pressed. The Fix Toggle servo position one time per button press.

5 Alternative Sequence

6 Alternative Code public void servoTogglePosition(Servo servo, double dLastServoCommand, bool bGamepadPB, bool bPBPressed) // This method toggles the position of a servo. The servo's range of motion is 0% to 100%. { if (bGamepadPB) if(!bPBPressed) // If true, this is the first scan where gamepad button is pressed. bPBPressed = 1; // Acknowledge gamepad button pressed // Toggle servo position if (dLastServoCommand = 0.0) dLastServoCommand = 1.0; else dLastServoCommand = 0.0; servo.setPosition(dLastServoCommand); } else bPBPressed = 1; // Unacknowledge gamepad button pressed when button released.

7 Something to Think About
How would you change the sequence (and code) to slowly toggle the servo to prevent damage to the servo gears?


Download ppt "How to Fix “Glitchy” Servo Code"

Similar presentations


Ads by Google