## Gather Data

A series of tests were done to determine what the actual fluid rate was for a given control value (1 - 255). The data was accumulated over a wide range of control values. I tried to run at the same control values several times so that there was some redundant data.

I could not run the pump at very low values since the motor would stall. I also found that if the pump was left alone overnight, the first few runs the next day would stall. This occurred more often at lower rates, but could fail even at higher rates. To overcome this, I "loosened up" the pump by running it for a few minutes at the highest rate possible. This is a mechanical problem, most likely caused by the choice of tubing material not being pliable enough.

These tests were done with a Ruby script which would:

- tare the scale
- choose a control value
- run until 10mL or more had been delivered
- read the scale
- calculate the actual rate in mL/hr
- save the control value and actual rate as a pair

Eventually I removed the taring of the scale and simply read the initial value of the scale. I also added delays between operations to allow the scale to "settle down".

Periodically the scale would suddenly dip by a 0.5 to 1.0g or so and then rebound to it's former value. Is there something "wrong" with the scale?

## Calculate Rate to Control Value Function

Once I had the raw data, I used linear regression to find the coefficients for a polynomial function that translated a given rate (in mL/hour) into a control value. I used a spreadsheet to plot and graph the data. Generally speaking the control value to actual rate relationship was nearly linear. At the highest rate, the fluid rate dropped off slightly. I tried various types of fit, e.g. linear, 2nd order, 3rd order and higher, to see which was the best. LibreOffice (open source spreadsheet) can calculate the R2 factor and 2nd order gave the best fit.

## Testing and Results

Then I wrote a Ruby script to test the polynomial. I chose some simple rates, say 100 mL/hr and ran it for a specific time, say 30 minutes. The scale should show, in this case, 50g (== 50 mL).

The initial runs were not good. I traced the problem down to some bad raw data, e.g. partial runs, runs done without the "loosening up", etc. I cleared out the raw data and re-ran the tests in a more controlled manner.

After re-calculating the coefficients, it performed quite well given the simplicity of the system. At various rates, it was accurate, at others it was off by as much as 10 - 15%. It was generally consistent too. Running a test, over multiple runs, at the same rate would give roughly the same results.