Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Servo Help (http://www.chiefdelphi.com/forums/showthread.php?t=144354)

Jtbillick 02-21-2016 03:48 PM

Servo Help
 
Hello,
My team is trying to program a servo so when you press a joystick button it goes to a certain angle. I looked and the wpilib page and I saw the "exampleServo.set(0.5);" example code, but I'm not sure how to use a joystick button with that. I have tried various ways, but nothing has worked. Can anyone help me?
We are using a servo from ServoCity that turns 90°. It's plugged into a pwm port on the roboRio.

pblankenbaker 02-21-2016 06:45 PM

Re: Servo Help
 
Try adding the following code to your Robot.java file in the robotInit() method (change the value of PWM_SERVO to match the PWM port you used for your servo):

Code:

   
    // Set this to the PWM port you plugged your servo into on the roboRIO
    public static final int PWM_SERVO = 8;
   
    // Servo you want to control (give it a name related to its purpose instead of servo)
    private Servo servo;
   
    public void robotInit() {
            // Construct an instance of your servo (change the name so it is meaningful to its purpose)
            servo = new Servo(PWM_SERVO);
            LiveWindow.addActuator("Name of Subsystem", "Servo Name", servo);

        // rest of your robotInit follows ...
    }

Deploy the code and then put your driver station in "Test" mode instead of "Teleop" mode. You should see a control for your servo appear on the smart dash board with a slider. Move the slider around to find the value you want it to go to when the user presses a button.

Next, in your code where you handle the button press, use the servo "set" method with the value determined from test mode to make the servo go to the proper position. Something like the following:

Code:

servo.set(VALUE_FROM_TEST_MODE);
Hope that helps.

Ether 02-21-2016 08:41 PM

Re: Servo Help
 
Quote:

Originally Posted by Jtbillick (Post 1543765)
My team is trying to program a servo so when you press a joystick button it goes to a certain angle.

We are using a servo from ServoCity that turns 90°.

What is the part number of the servo, and what is it actuating?



Jtbillick 02-22-2016 07:41 AM

Re: Servo Help
 
The part number is spg5685a-4507a90 and it is changing the position of our shooter


All times are GMT -5. The time now is 08:59 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi