Go to Post My rule of thumb is that any team who's won four World Championships can count their chickens whenever they want. :p - Karthik [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-21-2016, 03:48 PM
Jtbillick Jtbillick is offline
Registered User
FRC #4780
 
Join Date: Jan 2015
Location: Ohio
Posts: 18
Jtbillick is an unknown quantity at this point
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.
Reply With Quote
  #2   Spotlight this post!  
Unread 02-21-2016, 06:45 PM
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
  #3   Spotlight this post!  
Unread 02-21-2016, 08:41 PM
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,999
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Servo Help

Quote:
Originally Posted by Jtbillick View Post
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?


Reply With Quote
  #4   Spotlight this post!  
Unread 02-22-2016, 07:41 AM
Jtbillick Jtbillick is offline
Registered User
FRC #4780
 
Join Date: Jan 2015
Location: Ohio
Posts: 18
Jtbillick is an unknown quantity at this point
Re: Servo Help

The part number is spg5685a-4507a90 and it is changing the position of our shooter
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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