# history

## Recommended Posts

i have a regulator that regulates the rotational speed of something, then i want the speed to be close enough to the set point for 10 points of history, then save some values to "fake" channels and then add 200 to the set point

So, i guess what i need is a function that looks up the history of a channel, lets say mychann(0,10), and if all those values are in a specified range, then i want to do something like myvar= myvar +200...

##### Share on other sites

I'm assuming the question is how to process the history. You can get the last 10 points of a channel just by doing:

myChan[0,9]

You could then process that using a for() loop, but its usually better to avoid for loops because they don't scale well (i.e. they are slow when the size of the loop grows). So while it would probably be ok for 10 iterations, if you did, say, 1000, then it'd be kind of slow. Therefore its better to try and use built in DF functions for processing arrays. For checking a range you can use search:

if (search((myChan[0,9] &gt; HiPoint) &amp;&amp; (myChan[0,9] &lt; LoPoint)) == -1)
myVar += 200
endif

Note how the search is the inverse of what you described. It is looking for any value outside of your range. If it doesn't find anything that matches (meaning everything is inside the range) it returns -1. Otherwise it returns the index of the first point outside the range.

##### Share on other sites

now i have tried this:

While (Regulator==1)

If(search((Rollerspeed[0,40] &gt;(setspeed+200)) &amp;&amp; (Rollerspeed[0,40] &lt; (setspeed-200))) == -1)

setspeed += 300

endif

delay(0.5)

endwhile

But it seems to be inverted some how. When rollerspeed is outside the range it adds 300... i want it to add when its inside of range.