| 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.
|