-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Conversation
algo.py
Outdated
try: | ||
self._flow_sensor.set_o2_compensation(o2_saturation_percentage) | ||
except Exception as e: | ||
self.log.exception(e) | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
drivers/hsc_pressure_sensor.py
Outdated
@@ -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% |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
drivers/hsc_pressure_sensor.py
Outdated
(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 " |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Good point. thanks
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.