Thread: Servo Help
View Single Post
  #2   Spotlight this post!  
Unread 21-02-2016, 18:45
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 102
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
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.
Reply With Quote