Shop OBEX P1 Docs P2 Docs Learn Events
Variable Repeat — Parallax Forums

Variable Repeat

T ChapT Chap Posts: 4,223
edited 2006-11-08 08:02 in Propeller 1
Xrun80 :=  some serial incoming integer that changes

repeat    Xrun80
    'some stuff
    Xrun80 := (some formula of a newly received number added to Xrun80)
    term.dec(Xrun80)   ' changes as input is received




I could be issing this somehow but the Xrun80 is showing as is should, it changes as new info received. However, the repeat is sticking with the first value received no matter what.

Any suggestions on how to update a repeat variable?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-11-08 04:46
    The repeat is behaving as it should.· The number of times through the loop is set on entry for this syntax.·
    What do you actually·want to use for the number of times through the loop?· Do you want to stop when Xrun80 reaches a particular value?· In that case, using "repeat until Xrun80 == 0" might be what you want.· You could still decrement Xrun80 within the repeat loop which would probably give you what you want.
    ·
  • T ChapT Chap Posts: 4,223
    edited 2006-11-08 05:05
    Thanks Mike, the loop is the main run loop for the motor steps. This loop sits betweeb several other loops with fixed lengths(XaccelLoop, XdecelLoop, XexitLoop if direction changed).

    What I want to do is, while the main loop is running the motor to a destination X, if new position is rec'd, update the repeat loop to reflect the change. Xrun80 means 80% of the total length of travel. 10% goes to the accel loop length (with <# 500 max). 10% is the ramp down. So the 80% main run is able to be changed. If the direction is changed, the main loop exits to a ramp down. The nice thing about this approach is, the longer the length of travel, the smaller the rampup pauses get, meaing that for a long move, the speed increases, for short moves, the speed is low as the accel loop only had 10% of X to use, so it added less is that makes sense.

    To answer your question though finally, I want to use (X(new pos) - Xcurrent pos)) - (X/10 +x/10). In other words, the New minus the Current - 20%. I have everything done except the repeat loop that can auto-adjust on incoming positions. Took about 20 hours to get the ramping just right and to be able to alter the motion without stopping or noticing anything being added. What happens now is that the last phase of the move(decel) is picking up any update in position and adding it to it's ramp down iteration size. The Xrun80 never hits 0 in this context. Not sure how to implement that. I was thinking for tring for next. The method didn't work as suggested btw.

    Post Edited (originator99) : 11/8/2006 5:10:39 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2006-11-08 07:36
    Well, you'll have to decide exactly what your termination condition is and simply use that in a "repeat while" or "repeat until" statement. If you don't know the condition until the end of the loop, you can put the "while" or "until" clause at the end.
  • T ChapT Chap Posts: 4,223
    edited 2006-11-08 08:02
    Yes you are right. I have tried a lot of combos of formulas for until and while. It's hard to explain all the parameters. X can be "0" if the user chooses, so using X in the Repeat While formula (X - X/10) caused problems( the loop quits). I tried minimum and max limits but that adds in other problems. X can change, so the repeat value has to be able to be updated plus or minus. Not to mention, the loop has to function in relationship with a loop before and after, that all derive from the same X value. I'll just make "0" not an option and simplify things.

    Post Edited (originator99) : 11/8/2006 8:54:17 AM GMT
Sign In or Register to comment.