Sign in to follow this  
Followers 0
hotbuttmud

Help with arrays in PID

2 posts in this topic

#1 ·  Posted (edited)

I am trying to set up a Proportional, Integral, Derivative program, and I need some help on derivative filtering. I want to add values to the end of an array until there are 20 elements total. From there, I want to use Array Push to keep the last 20 values. Any advise?

One other is, is there a short way to find the average value of those 20 values?

Edited by hotbuttmud

Share this post


Link to post
Share on other sites



Hi hotbuttmud,

well, use _ArrayPush() then.

Define a new array with 20 items (dim $array[20]) and then use _ArrayPush(). Example:

#include <array.au3>

Dim $a[20]

For $i = 0 To 30
    _ArrayPush($a, $i)
    ConsoleWrite(_ArrayToString($a) & @CRLF)
Next

Getting the average out of that array:

$k = 0
For $j = 0 To 19
 $k += $a[$i]
Next
ConsoleWrite("Average:" &  %k / 20)

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0