mattallen37 wrote:
I like my method better. It's a lot more simple,
You are free to like whatever you want, of course. Simplicty is a big advantage of your method, yes. If you capsulate the other way into a method, however, you can use it just as easily.
mattallen37 wrote:
and should require much less CPU time.
You're free to test it, but as of now, if you just use this
Code: Select all
until(PosRegComplete(OUT_A, 5, Position));
the complete opposite is true: You have a busy loop, using up the maximum amount of CPU. If you don't include a Wait() statement, there is no way to use up more CPU than in this loop. Seriously.
This method could also fail. I don't know how much overshooting / oscillating the new APR does, but in certain cases, there could be a varying load on the motors. If during the final "braking approach", let's say just 10 degrees before the target (TachoLimit), there was a huge increase in motor load, the PID regulation might need some time to regulate this. And in that case, your PosRegComplete() call would return true, while in reality, the APR is still trying to move the motor to the correct postion. Have a look at this picture, blue line:
http://www.mindstorms.rwth-aachen.de/tr ... tateEx.png
I know that APR doesn't produce such big oscillations anymore, but who says this couldn't occur? So if you exit your "wait until finished" loop the first time the TachoCount passes the target tolerance zone, you might exit too early.
If the RUNSTATE == IDLE (i.e. != RUNNING) thing works, this will be the best option, since in that case the APR clearly says: "Ok, I'm done regulating, motor is free again."