Jump to content

Help with arrays in PID


Recommended Posts

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
Link to comment
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]
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...