Chief Delphi

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

Mr.Roboto3335 09-02-2013 10:39

Servo programming
 
I'm having trouble trying to program a servo. Everytime I press the button that should make it rotate it does nothing. Any help would be appreciated.

/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Servo;
import edu.wpi.first.wpilibj.SimpleRobot;

/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the SimpleRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the manifest file in the resource
* directory.
*/
public class RobotTemplate extends SimpleRobot {

Servo servo = new Servo(5);
Joystick joystick = new Joystick(1);

/**
* This function is called once each time the robot enters autonomous mode.
*/
public void autonomous() {

}

/**
* This function is called once each time the robot enters operator control.
*/
public void operatorControl() {

if(joystick.getRawButton(3))
{
servo.set(1);
}
else if(joystick.getRawButton(4))
{
servo.set(-1);
}

}

/**
* This function is called once each time the robot enters test mode.
*/
public void test() {

}
}

joelg236 09-02-2013 11:28

Re: Servo programming
 
Code:

public void operatorControl() {

if(joystick.getRawButton(3))
{
servo.set(1);
}
else if(joystick.getRawButton(4))
{
servo.set(-1);
}

}

This should be running in a loop. Like this
Code:

while(isOperatorControl()) {
    // Code here
}


Mr.Roboto3335 09-02-2013 11:33

Re: Servo programming
 
You are absolutely correct. I forgot that statement. Servo still won't work. It doesn't even default when I reset the robot. Wiring?

Joe Ross 09-02-2013 11:43

Re: Servo programming
 
Also, Servo.set() takes a value from 0 to 1, rather then -1 to 1 like a motor.

You can also use code tags to keep your formatting when posting code.

Did you install the servo jumper in the digital sidecar?

Mr.Roboto3335 09-02-2013 11:48

Re: Servo programming
 
Quote:

Originally Posted by Joe Ross (Post 1230453)
Also, Servo.set() takes a value from 0 to 1, rather then -1 to 1 like a motor.

You can also use code tags to keep your formatting when posting code.

Did you install the servo jumper in the digital sidecar?

No I did not... Found and inserted the jumper and is now working. Thank you!

tmccalister 17-02-2013 19:24

Re: Servo programming
 
What is a servo jumper? If you could help me with that just pm me. Thanks :)

Ether 17-02-2013 19:28

Re: Servo programming
 
Quote:

Originally Posted by tmccalister (Post 1235220)
What is a servo jumper? If you could help me with that just pm me. Thanks :)

Jump to 0:24 in this video:

http://www.youtube.com/watch?v=RF104...me0nC_xUILWCam



tmccalister 18-02-2013 18:36

Re: Servo programming
 
Quote:

Originally Posted by Ether (Post 1235223)

What does it look like?

Ether 18-02-2013 21:02

Re: Servo programming
 
Quote:

Originally Posted by tmccalister (Post 1235857)
What does it look like?

It looks like the picture in the 2013 Kit of Parts black tote checklist revB.




All times are GMT -5. The time now is 10:07.

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