Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Compensation Formula #225

Closed
airgradienthq opened this issue Aug 25, 2024 · 1 comment
Closed

Check Compensation Formula #225

airgradienthq opened this issue Aug 25, 2024 · 1 comment

Comments

@airgradienthq
Copy link
Owner

From our forum:
https://forum.airgradient.com/t/pms5003-cf-1-or-cf-atm-data/2298/6

Hi @Achim_AirGradient just a note here - as I was looking for the newly introduced compensated code in the arduino github repo, I found that you have a recent implementation in here (arduino/src/PMS/PMS.cpp at master · airgradienthq/arduino · GitHub).

However, I am afraid this may face the exact same bugs that I had in my original implementation, and then fixed today (as described in my previous post).

Firstly, the pm25 input argument for that function is an integer, and that is then used for some divisions (e.g. pm25 / 20). I believe for the division to work correctly, the pm25 should be float instead.

Similarly, with hardcoded values in other divisions, e.g. “3/2” in line 292 and “21/5” in line 296. The divisions numerators should be float as well (e.g. replace 3 with 3. , and 21 with 21.) to work as expected.

Finally, the cast of the result back to int may not be rounded properly. For example, the expected result 20.89 for input values of PM2.5=33 and RH=40 would be returned as 20 instead of 21. As discussed here: floating point - C++: How to round a double to an int? - Stack Overflow

At least these are the things I had to fix to make my implementation work, and seem to be similar in the github arduino code too. I’m not that familiar with C++, and may therefore be overlooking some details in the github implementation though. But I thought it would be worth to report it to you to double check.

PS: After sending it, I noticed there may be at least another issue with the arduino code in particular. For example, line 296 seems to be missing a power of 2 on a pm25 reference:

(8.84f * (1.e-4) * pm25* (pm25/50 - 21/5))

@pnt325 please check implementation.

@pnt325
Copy link
Collaborator

pnt325 commented Aug 26, 2024

@airgradienthq Correct the formula implement has missing pow of 2 some where.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants