fossasia / pslab-python

Python Library for PSLab Desktop: https://pslab.io
GNU General Public License v3.0
1.62k stars 227 forks source link

feat: Improved algorithm for measuring capacitance #227

Closed AsCress closed 1 month ago

AsCress commented 1 month ago

Fixes #226 Improves the algorithm for measuring capacitance, making it akin to the one implemented in pslab-android.

Changes

Screenshots / Recordings

I tested with a PSLab V6 device, with the library installed on Windows. Here are the results:

Screenshot 2024-07-06 143259

Screenshot 2024-07-06 143357

Unfortunately, I couldn't test further due to the limited availability of capacitors.

@bessman I noticed that the time the PSLab device takes to calculate capacitance has now reduced. I haven't touched _measure_rc_capacitance. You were right, it doesn't work quite well, and the same issue exists in Android. I'll sort that out in Android first, and then address it here. Also, this is my first time writing something in Python :)). I have tried to observe the files and followed a similar pattern. Do inform me if I have done something wrong (not followed conventions of the language or something).

AsCress commented 1 month ago

@bessman Can I get some guidance regarding the failed CI ? Thanks.

bessman commented 1 month ago

I'm travelling today and won't be able to look this over properly until tonight. But regarding the CI, the tests fail because the recorded serial traffic no longer matches the calls made to the device.

The traffic needs to be re-recorded. To do this, you need to install pytest, and then check if the relevant tests pass when run against a real device. Do this by running pytest --integration tests/test_multimeter.py.

If the tests pass, record the serial traffic with pytest --record tests/test_multimeter.py. Then commit the updated traffic logs.

If the tests don't pass, we can take a look at it together tomorrow.

The linting fails because the file multimeter.py does not adhere to the project style, which is black. Install black and run black pslab/instrument/multimeter.py, which will automatically format the file to the correct style.

bessman commented 1 month ago

Also, note the docstring at the top of test_multimeter.py:

"""Tests for PSL.multimeter.

When integration testing, connect:
    PV1 -> 10K resistor -> VOL
    RES -> 10K resistor -> GND
    CAP -> 1 nF capacitor -> GND
"""
AsCress commented 1 month ago

@bessman Thank you so much !! I'll surely do this things.

AsCress commented 1 month ago

@bessman Done everything you said. The tests were passing ! I have recorded the data and commited. The CI passes now. It can also be noted in test_capacitance_measurement.json that we now require much less iterations for the measuring job.

AsCress commented 1 month ago

@bessman Tested this today thoroughly. I tried some other improvements / workarounds but this one seems the best to me. I guess this is now ready for a final review from your side.

AsCress commented 1 month ago

@bessman I have done all the changes and re-recorded the tests.

bessman commented 1 month ago

Thanks!