DeeEmm / DIY-Flow-Bench

Volumetric flow bench based on ESP32 and MAF sensor.
GNU General Public License v3.0
27 stars 10 forks source link

[FEATURE REQUEST] Add additional flow smoothing filters #180

Open DeeEmm opened 1 week ago

DeeEmm commented 1 week ago

Include 'MODE' for averaging function for flow value smoothing

Suggested by @black-top

DeeEmm commented 1 week ago

I've added a data filter drop down to the configuration tab in latest commit

So far all that is functional is Rolling Median smoothing, but it is written to include Cyclical Average and Mode, but the maths for those needs to be written.

DeeEmm commented 1 week ago

Discussion relating to Mode filtering in flow calibration thread

https://github.com/DeeEmm/DIY-Flow-Bench/issues/179#issuecomment-2443394451

DeeEmm commented 1 week ago

I'm going to assign this target to the V3 release, however it will likely be possible to squeeze additional filters in between now and then as the main core filter management code is now in place.

Potential to include filters to truncate and then use standard deviation methods...

Truncated Median Truncated Average Truncated Mode

We can also consider removing larger deviants from the data set...

change > x cfm

In theory if we add a number of (different) filters then hopefully each end user will find one that is suitable for their setup.

DeeEmm commented 1 day ago

From discussion in issue https://github.com/DeeEmm/DIY-Flow-Bench/issues/178#issuecomment-2453430005

Additional flow value manipulation using truncation and rounding...

Changes to javascript.js to truncate displayed values...

var decimalPlacesFlow = 0;
var decimalPlaces = 1;
if (key === 'FLOW' || key === 'AFLOW' || key === 'MFLOW' || key === 'FDIFF'){
  document.getElementById(key).innerHTML = myObj[key].toFixed(decimalPlacesFlow); 
} else {
  document.getElementById(key).innerHTML = myObj[key].toFixed(decimalPlaces); 
}

Okay. so after some experimenting it looks like I can use templating variables in the javascript file which means we can pull these values out into the configuration.

I have also been playing around with the round function to allow us to round to nearest 0.5cfm

round(x * 2.0) / 2.0;

I will package up this up within the configuration settings tab as a new group of settings under the filters

Round to nearest integer Round to nearest 0.5
0/1/2 Decimal places for flow variables 0/1/2 Decimal places for everything else

DeeEmm commented 1 day ago

@black-top from https://github.com/DeeEmm/DIY-Flow-Bench/issues/178#issuecomment-2453379664

I repeated the same test in a few days, and the results looks good. CD flows in 1-2CFM with same calibrations. For cylinder head flow, there are the same problems that we were discussing about filtering. The value fluctuates in the 1–5 CFM range and sometimes in the 5–10 CFM range (with cycle average filter). Maybe turbulence from the cylinder head influences that, but my MAF is far from the cylinder head and 4 or 5 90deg bends, so it should be quite laminar. I was trying to write down minimum values, because it looks like it repeats most accurately. With these results, I think it will be a good option to have at settings to select simple number rounding to a whole number, because the system will probably never be that stable to see less than 1CFM with MAF setup. Also, the"Average Minimum" filter may be worth trying.

@DeeEmm ...

After pondering this last night. I think that this needs further investigation. We should easily be able to get down to sub CFM measurements. We see fractional values in the MAF table and also interpolate the MAF data. If we use simulated input, the readings are very stable, which leads me to think that the fluctuations are external, and potentially hardware related. I think the pulsing that you see when you close off the inlet at 28" is indicative of this. It would be really good to try and isolate the cause.

It would be good to try and pin down the exact cause of the fluctuations. Whilst software filters are an 'easy' solution, they are not taking causality into account. We are only addressing the symptom of the problem and not the problem itself.

Do you have an oscilloscope?. The first step is to determine whether the fluctuations are external to the board. You can monitor the input voltage of the MAF wth a scope to determine this.

Assuming that the fluctuations are external, we then need to determine if they are from the MAF, or as a result of system design, which ideally requires measuring the air flow with a secondary device or monitoring system pressure.

If it is a physical phenomenon, I would expect it to be easily measurable.

If it is not a physical phenomenon, then the solution would be electronic filtering in the form of RC filter(s). There is already a rudimentary RC filter in the design. But the values can easily be tweaked. I think that this would be a more appropriate solution and more robust.

DeeEmm commented 1 day ago

@Black-top I've added the changes to truncate / round the flow values in the GUI to the configuration tab. Let me know how this works for you. You will need to upload both the project and the index.html file

DeeEmm commented 1 day ago

Screenshots...

Screenshot 2024-11-04 at 4 22 34 pm Screenshot 2024-11-04 at 4 22 47 pm
black-top commented 1 day ago

I have been trying to solve those issues since the beginning. The latest iteration has properly shielded cable to MAF, and since rs4 MAF needs 12V and 5V for reference, I made a small pcb based on a speeduino power supply, so a 5V power supply with all filtering and stabilization is connected a few centimeters away from the MAF connector. The 5V is as stable as possible, don't see any variation. I was probing signals with scope and don't see any noise, unless easp32 is connected to the pc, but I connect it only for firmware update, so it is not connected all the time. The MAF signal at the connector, compared to the signal at the PCB is undisturbed. All grounds are connected to the same place, so there are no ground loops. I see some signal pulsating directly from MAF, there is also some small variation in depression. My guess is that air flow is pulsing, and that might be the cause. I think I need to add a manual valve near the pump, for "controlled leak", so the pump will run stable.

I lost track a little bit. I don't need to do code modifications, it is already in the master?

DeeEmm commented 1 day ago

Yes the changes are in master.

Is it worth considering including closed loop control in the V2 release? (#189).

black-top commented 1 day ago

Well, close loop control will be great, but it requires a lot of work, and probably quite complex strategies. Probably one PWM output for vfd and a second pwm output for DBW. Or maybe at first just DBW pwm output, but pump control leave manual, because two control systems might fight each other. Or maybe a simple strategy for vfd just ramp up pump speed open loop and PID only for DBW control.

DeeEmm commented 1 day ago

A very basic implementation might not be too bad. Just controlling the bleed valve, with manual vac motor control. No bells and whistles, just a very basic control.

I'm thinking that if it adds value to the initial release and helps us to produce a more stable / accurate measurements, then it will actually help with validation, which I see as the most important issue at present.

black-top commented 1 day ago

Yes, even basic control setup will be a big step forward and probably will solve some issues with stability.

DeeEmm commented 16 hours ago

I will take a look after I've finished with what I'm currently working on.

black-top commented 3 hours ago

I tested the rounding functions, and it looks like everything is working as intended, didn't find any issues.