Log in

View Full Version : How do you make a PID move a motor in Java?


Maxchrist
12-02-2014, 16:11
Hi we are trying to get a motor to move with a potentiometer to specific positions, and we are attempting to use a PID controller to do so. We have tried using .setSetpoint(), but we do not know what that value actually means and how to make the motor move, if that is the right way to do it. If someone could help us out it would be great. Thank you.

cgmv123
12-02-2014, 16:26
Did you enable the PIDController?

Maxchrist
12-02-2014, 16:31
well we are not entirely sure how to set it up, can you maybe show us a sample or something?

cgmv123
12-02-2014, 16:35
well we are not entirely sure how to set it up, can you maybe show us a sample or something?

If you set the setpoint with:
pidController.setSetpoint(setpoint);

then you need to enable the controller with:
pidController.enable();

I'm not as familiar with PID controllers as I'd like to be, but here is the API if that helps: http://www.wbrobotics.com/javadoc/edu/wpi/first/wpilibj/PIDController.html

TFleig78
12-02-2014, 16:40
The PID controller needs an input (use the method returnPIDInput()). This comes from a sensor, such as a gyro or potentiometer. You then use the usePIDOutput() method to move one or multiple motors in order to make the input value reach the setpoint. You need to enable the pid with enable().
This video explains the PID subsystem really well:

http://www.youtube.com/watch?v=j2Xz8bRRcF0

Maxchrist
12-02-2014, 16:52
Thank you so much, i think that will help, I will update this when we figure out if it works