Skip to content

Data Members

Tdoe4321 edited this page Apr 9, 2018 · 4 revisions

Overview

This page lists all the Data Members in the Flex() class as well as their intended use:

  • int sensorPin
  • int minInput
  • int maxInput
  • int numReadings
  • int readIndex
  • int smoothingType
  • int weight
  • int* vals
  • int* expVals

int sensorPin

This is the value of the pin that you want to read the data in from the Flex Sensor. If you have your circuit hooked up like so: alt text
Then you would use the value 'A0'

int minInput

The minInput value effects things like the 'isBent()' function. When I used it in my robot hand project, it was useful to have a value that was tied to the Flex object that represented the minimum value I knew it could read. When calling Calibrate(), this minInput value gets overwritten.

int maxInput

The maxInput is nearly the same as the minInput, and is used mainly for clipping values.

int numReadings

This stands for the total 'Number of Readings' that the Flex object will store in the array of values. It directly effects the length of the 'vals' array.

int readIndex

This is the variable, available to all methods, that represents where we are at in the data storage process. When the Flex object takes a new value into the 'vals' array, it stores it at whatever the readIndex currently is. When we go to call getSensorValue() it reads it at the 'vals[readIndex]' location.

int smoothingType

This variable tells the Flex() object what kind of smoothing algorithm you want to use. There are currently four different options available in this library: NONE, AVG, RUN_AVG, and EXP. The last three take the data from the Flex Sensor and smooth it out in some way.

  • NONE
    • Does no averaging or smoothing to the data
  • AVG
    • Takes in a specified number of values, then takes the average all at once
  • RUN_AVG
    • Takes in a 'running' list of values and calculates the average after each new data entered
  • EXP
    • Uses a weighted averaging system to allow the user to tune the system

For more information on all these smoothing algorithms, see this link:
https://www.megunolink.com/articles/3-methods-filter-noisy-arduino-measurements/

int weight

The weight option currently only comes into play with the EXP smoothing type. It lets the function know how much to effect the smoothing curve.

int* vals

This is a pointer to an array of values where your actual data is stored. The 'vals' array is constantly updated when we call updateVal(). The reason for choosing to use an array as opposed to just a standard int was so that I could bundle together the smoothing algorithms into the library. If you don't want to use the smoothing stuff, the size of this array has little effect on the program. It will still update the array, but when you call getSensorValue() it just returns the value at the 'readIndex' you just read into.

int* expVals

This is an array of values that is required in the EXP smoothing type. Because the EXP smoothing type relies on previous values of it's own smoothing curve, I had to add a separate array to keep track of those values.

Clone this wiki locally