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

Dp sensor o2 compensation #396

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Dp sensor o2 compensation #396

wants to merge 9 commits into from

Conversation

Reznic
Copy link
Collaborator

@Reznic Reznic commented May 12, 2020

The differential pressure sensor driver uses Bernoulli's equation, to cast the dp measurement into flow.
This calculation depends on the flowing gas density, and is currently calibrated for the density of air.
But, as oxygen percentage rises, the density rises too, which should result in lower flow values.

In this issue, the measured oxygen saturation is passed to the differential pressure driver, which calculates the new density, and the compensation for corrected flow.

algo.py Outdated
Comment on lines 498 to 502
try:
self._flow_sensor.set_o2_compensation(o2_saturation_percentage)
except Exception as e:
self.log.exception(e)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not good.
A flow sensor should behave as a flow sensor.
NullDriver should behave like magic mock in this case and simply do nothing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done
Now I check if the relevant method exists in the driver class..
(There are other flow sensors which do not need this compensation)

@@ -38,8 +43,26 @@ def set_calibration_offset(self, offset):
def get_calibration_offset(self):
return self._calibration_offset

def set_o2_compensation(self, o2_percentage):
# update compensation only when o2 changes more than 5%
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't explain what, explain why

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

(1 - o2_percentage) * self.DENSITY_REST_OF_GASSES)

self._o2_compensation_ratio = sqrt(self.DENSITY_AIR / corrected_density)
log.debug(f"HSC pressure sensor updated comensation ratio "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use f-string in log messages, use % format specifiers and pass the format arguments to the logging function in order to take advantage of the deferred formatting by the logging module.

This is PyLint warning logging-not-lazy (W1201).
See This section

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done
Good point. thanks

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

Successfully merging this pull request may close these issues.

2 participants