If X == Range
T Chap
Posts: 4,223
I tried .. to check for a range of vlues but it seems this does work in this instance if x == -10 .. 10.
Is there a faster way in spin to check for a value to fall within a range other than resorting to case X, AND, OR, etc?
Is there a faster way in spin to check for a value to fall within a range other than resorting to case X, AND, OR, etc?
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A wise man told me; "All electronics are made to work by magic smoke.
Don't ever let it out as it's·very difficult·to get it back in."
if x => -10 and·x =< 10
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Andy
would be my bet for fastest.
The only way to find out though is to benchmark the various solutions. Just looking at the Spin code or bytecode doesn't give any real indication of how long it's going to take.
In a PID loop that is constantly checking an error, I found that the motor required a certain amount of PWM duty (~35) just to move.When attempting to hit a target position there was always overshoot, and often a toggle back and forth over the target, often attributed to integral windup. So instead of trying to reset the windup at the target number, I reset it withing a range of 5 or so, and am eliminating a lot of oscillation and overshoot. There is already a lot of code in the loop that is adding to the problem, so I am looking for faster ways of doing the same thing, if that is possible.
Post Edited (Originator) : 10/25/2008 5:09:15 PM GMT
The liveband is a range of error values OUTSIDE of which the integrator is frozen. This ensures that you don't get it winding up like mad when the error is large : the P term is supposed to predominate in those conditions.
The deadband is a (much smaller) range around error = 0 : the idea is that once inside this range, the integrator is again frozen. This seems odd as the integrator is there to remove small errors, but if you have some stiction the integrator will see the small error, slowly wind up to the point where the motor will move, cause a jump to the other side of the error and repeat in the opposite direction. However, a dead band like this will also forever stop you quite reaching the setpoint so it's best arranged so that you don't stop integrating until you pass error = 0, then stop the integrator until you get outside the deadband in either direction.
Unfortunately, the simple and elegant P+I+D calculation you thought you had is lost in all these cunning tricks. As with most systems, the 'normal' code is only 1/10 of the whole .. the other 9/10 deals with errors and exceptions.
As far as the liveband and deadband, that is sort of what I am creating, a range in which the accumulator is reset, say within 10 lines, I hit the brakes and kill the PWM with a short pause to insure the motor is stopped, then allow the accumulator to start pushing the motor a little closer to the mark. There are so many factors though, the load, friction, PWM period, all play a role in torque at the low speeds, even with a 10:1 gearbox assisting.
"if you have some stiction the integrator will see the small error, slowly wind up to the point where the motor will move, cause a jump to the other side of the error and repeat in the opposite direction."
This is precisely the issue, it takes a certain amount of duty to get the motor to move, below which you just have some noise. The problem is at a low speed, the motor is either on or off, and wants to jump back and forth over the line unless some measure fades the PWM and lets the motor fall near 0. Another problem at this close point, is that the D starts outputting larger values during oscillation, so realistically, there needs to be a deadband for D as well, else it contributes to the jumping.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 10/25/2008 10:09:37 PM GMT