Log in

View Full Version : Best way for "servo" from motor & potentiometer?


NinJA999
18-01-2010, 13:54
This year one of our structures on the robot will need precise control over a motor's positioning. We'd like to hook up a potentiometer to the motor and use it like a really high powered servo (an encoder would be another option; however that offers relative rather than absolute positioning). What would the best way to code this be? Should I create a new class which uses a Jaguar and an AnalogChannel and does some fancy PID routines to provide accurate positioning? Am I missing a something in the library which already does this or something similar? (I'm not talking about the built in Servo class -- that's meant for servos connected to the digital sidecar) Any ideas/input would be helpful! Thanks!

Jared Russell
18-01-2010, 14:12
Probably the easiest thing to do would be to make a PIDController object with the PIDSource set to the analog input corresponding to the potentiometer, and the PIDOutput set to the Jaguar/Victor controlling the arm.

Look at the documentation for PIDController to see exactly how to do this.

NinJA999
18-01-2010, 14:50
Do I need to have a tightly controlled time loop to use the PIDController? What's the best way to do that?

Jared Russell
18-01-2010, 14:54
The WPILib implementation of PIDController actually does all of its processing in a separate thread in the background - you just tell it to start (and stop), and where to go to, and it does the rest.

NinJA999
18-01-2010, 16:14
Nice, thanks so much for your help!