Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Position and velocity PIDControllers using same encoder (http://www.chiefdelphi.com/forums/showthread.php?t=151887)

GeeTwo 15-10-2016 20:42

Re: Position and velocity PIDControllers using same encoder
 
Quote:

Originally Posted by Oblarg (Post 1611863)
I considered constructing two encoders on the same pins, but I strongly suspect this will throw an error. Will have to check.

Again, it's a matter of weighing the ugly, but perhaps you could free the encoder you aren't using (if I understand correctly, setting the variable(s) referencing it to null and possibly running garbage collection will accomplish this), then initiate the new one.

Oblarg 15-10-2016 20:43

Re: Position and velocity PIDControllers using same encoder
 
Quote:

Originally Posted by GeeTwo (Post 1611945)
Again, it's a matter of weighing the ugly, but perhaps you could free the encoder you aren't using (if I understand correctly, setting the variable(s) referencing it to null and possibly running garbage collection will accomplish this), then initiate the new one.

If I were never going to use them at the same time, this would probably work - but, as mentioned earlier in the thread, the notion is to run a cascading control loop on a turret where the position controller outputs to a velocity controller using the same encoder.

calcmogul 15-10-2016 21:06

Re: Position and velocity PIDControllers using same encoder
 
Quote:

Originally Posted by GeeTwo (Post 1611945)
Again, it's a matter of weighing the ugly, but perhaps you could free the encoder you aren't using (if I understand correctly, setting the variable(s) referencing it to null and possibly running garbage collection will accomplish this), then initiate the new one.

Doing this between two PIDController Notifiers, which are real-time processes, isn't a good idea since the garbage collector introduces a lot of non-determinism and delays. If they are running at low enough sample rates, it might work, but there's no guarantee. Forcing the garbage collector to run would also collect any other garbage lying around the Notifiers don't care about.

I thought of another option that avoids needing to do any trickery with multiple Encoder objects. You could inherit from the PIDController class with two classes called PositionPIDController and VelocityPIDController. They would both override calculate(), call m_pidInput.setPIDSourceType() with the PIDSourceType they each want to use, then call the base class calculate().

As a side note, you may need to synchronize access to the Encoder instance in calculate() since the PIDController instances are sharing it.

Joe Ross 26-12-2016 16:54

Re: Position and velocity PIDControllers using same encoder
 
Quote:

Originally Posted by Oblarg (Post 1611867)
Yeah, but you can't send the same encoder object to two separate PIDController objects and have it be a kRate source for one of them and kPosition source for another. Hence the wrapper idea, which is ugly but would probably work.

Here's a wrapper that 2485 wrote that does this.

https://github.com/team2485/frc-2016...dDistance.java


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

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