Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   PID Positional Control (Java) (http://www.chiefdelphi.com/forums/showthread.php?t=113807)

JohnFogarty 17-02-2013 19:23

PID Positional Control (Java)
 
Hello all.

Recently I've been attempting to write some code to control a motor to travel to setpoint (like spin half a revolution) and then stop. I've been using a quadrature encoder to obtain my distance traveled data. I've had little to no success with either CAN Positional control or using an adapted methods of PID-DEMO and ArmDemo. So my question is are there any teams using Java that would be willing to share their code from past robot arms that had positional control. That would help me a lot I believe.

ProgrammerMatt 18-02-2013 09:39

Re: PID Positional Control (Java)
 
Hi, PID is a great tool, I understand you are using jaguars, you may want to hook the encoders directly into the DSC, When in java use the encoder as a PID source and then start tuning your variables. We have had issues in the past with jaguars we no longer use them.

Above robot init
Code:

Victor motor;
Encoder encoder;
PIDController pid;

In your robot init
Code:

motor = new Victor(1); # or jaguar
encoder = new Encoder(1,2); # A channel B channel
enncoder.setPIDSourceParameter(Encoder.PIDSourceParameter.kDistance);
PID = new PIDController(0.01,0,0.01,encoder,motor);

In teleop ECT
Code:

PID.enable();
PID.setSetpoint(10.0);

Hope this helps, Please don't hesitate to PM me if you need anything,
-Matt

F22Rapture 19-02-2013 00:56

Re: PID Positional Control (Java)
 
Does the setpoint have to be a distance, or can we set the setpoint to a certain number of counts?

Ty Tremblay 19-02-2013 01:08

Re: PID Positional Control (Java)
 
Quote:

Originally Posted by F22Rapture (Post 1236100)
Does the setpoint have to be a distance, or can we set the setpoint to a certain number of counts?

"Distance" is just a descriptor. You can use whatever you want. If you want a certain number of counts just set your "distance per count" to 1.

Basically, distance per count allows you to put units into your PID instead of relying just on counts. You could translate counts into inches, feet, etc.

Edit: Please note this is using WPILib Java. If you're not using WPILib, the lines of code mentioned above won't work out of the box.


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

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