Announcement

Collapse
No announcement yet.

Creating an accumulator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating an accumulator

    I have data coming in at a regular rate.

    I want to take the first 10 values of this data and store them. Each time an additional value comes in, I want to remove the oldest value, and put the newest value in it's place.

    I believe the correct way to do this is to implement a 10 value array. Use a counter that is reset to zero each time it counts to 10 (since zero would be the first value, 9 would be the last), and simply fill in the values in the array using the counter as the index (counting once each time a new value comes in).

    I will probably create a global variable as the array, rather than using a shift register since I'm not currently running in a loop - plus I want to pass these values from auton into teleop.

    Is this the correct way to go about creating an accumulator?

  • #2
    Re: Creating an accumulator

    That sounds like a good description of a circular buffer implementation.

    You could also use the Rotate 1D Array function to move everything down (or up) one position and Replace the last (or first) element with your new data. This would avoid the need for an index variable.

    Comment


    • #3
      Re: Creating an accumulator

      That makes sense.

      Let me ask a second question then:

      I was also using the index value for another reason. I have a single global variable that I add each value to. I use the index to pull the oldest value from the array and subtract that value from the global: that way my global is always a summation of all the elements in the array, and I don't have to waste time in a loop to add them all together each time I want the result.

      Is there a better way to do that as well?

      Comment


      • #4
        Re: Creating an accumulator

        I think you want to use a FIFO or Queue. You can find the Queue Pallette under Data Communication -> Queue Operations.

        This will do a lot of what you want without having to make your own circular buffer, but it might prevent you from getting access to the entire thing at once (I couldn't figure out how to do it). It shouldn't be too hard to {get data; add data to your global; enqueue data in your queue; dequeue old data from queue; subtract old data from global}

        EDIT - I just realized that I don't know how to initialize a queue. You might need to enqueue 10 '0's before you begin. Does any one know a better method?
        Last edited by EVanWyk; 03-12-2009, 04:15 PM.

        Comment


        • #5
          Re: Creating an accumulator

          Let's take a step back and ask why you want this accumulator. Is it so you have each of the last ten values available individually, or is it just a means to compute a running average?

          If all you want is to filter the data to reduce transient response, you might be better off using a built-in LabVIEW filtering VI instead of building your own.

          Comment


          • #6
            Re: Creating an accumulator

            Originally posted by Alan Anderson View Post
            Let's take a step back and ask why you want this accumulator. Is it so you have each of the last ten values available individually, or is it just a means to compute a running average?

            If all you want is to filter the data to reduce transient response, you might be better off using a built-in LabVIEW filtering VI instead of building your own.
            In answer to that (and in answer to my own question):

            We are modifying our traction control. Without going into the nitty gritty, our traction control program sampled once every so-many-milliseconds. We based the "so many milliseconds" on how long it took to get a good decent number of ticks to calculate speed.

            However, this means you can calculate perhaps 10 times a second as a result of the speed at which you get encoder ticks (I wanted at least 30 to calculate a reasonably accurate velocity).

            I had the idea, however, that instead of doing in discrete increments of .1 seconds, if we kept an array of the values, then every time we got a new value we could remove the oldest and recalculate. This resulted in going from .1 seconds per calculation (again - the amount of time we estimated it took to get enough ticks to get a stable velocity) to .01 seconds - an order of magnitude more often.

            As a result, we did it this way:

            Created the array with 10 elements. We wait to turn traction on until we've filled the array. After that, each time a new value comes in (every .01 seconds), we add the newest distance value, and knock the oldest off.

            We calculate the total value of the array (to get total distance moved) by using the sum all elements in the mathematical menu. We then divide that by the time it takes to accumulate those 10 - 10 x .01 seconds to get velocity.

            We then use the velocity to feed into a best-fit 2nd order equation to determine the pwm value that will create that velocity. (Equation generated through experimenting with the robot then plotted in excel).

            Finally, we apply a percentage to that equation to determine the maximum and minimum value for the joysticks at any given speed.

            Anyway - thanks a ton Alan. You're initial help got us going in this direction and I think it's blossomed into a very good plan.
            Last edited by Tom Line; 03-12-2009, 09:39 PM.

            Comment


            • #7
              Re: Creating an accumulator

              In that case, you may want to consider Pt by Pt Mean with a sample length of 10. Functions -> Signal Processing -> Pt by Pt -> Probability and Statistics -> Mean PtbyPt.

              Comment

              Working...
              X