Servo Motors

Hello, my team this year is using a servo with a piece of metal attached that pivots. I have some simple code written here that should work but it does not.
if(stickL.getRawButton(5)){
servo.set(.5);
} else if(stickL.getRawButton(3)){
servo.set(-5);
} else {
servo.set(0);
}

As soon as we enable, the servo goes at full speed to its max point and when we disable it goes back to the starting position.

1 Like

On line 4, it says servo.set(-5);. I personally haven’t used servo’s much, but according to the WPILib docs it says that .set() doesn’t accept negative numbers. Also, you are giving it a 5, not a .5, so it would try to go to 500% of it’s max point, which could explain your issue.

No sorry I was writing that on my phone it is -.5. But you can use negatives in a set method because that puts it into reverse but I am not sure how to program servos with FRC as I have only used them with Arduino.

http://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/wpilibj/Servo.html#set(double)

In the Servo Class it states that set is only 0 to 1.0 representing the full range from left to right. The value you are passing does not represent direction or speed, but position.

Oh ok thank you so much!

No problem. Beyond this, it would help far more in troubleshooting if you could post the entirety of your code.

I’ll give the same answer I gave when you asked the same question yesterday.

Haha thanks yeah I didn’t know someone else on my team asked the same question😂. That solves one problem but now it’s still turning on at TeleOp enable.

1 Like

When the robot switches to Teleop Enable, what does the servo do?

It makes sense that the servo would go to a requested position then because the roboRIO doesn’t send PWM signals when disabled. So when it first gets enabled, it goes to the default position or the position it was last commanded to.