-
Notifications
You must be signed in to change notification settings - Fork 2
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
Moving from Calibration to Volume mode loses focus #142
Comments
This is a long known and very annoying bug. Let's try to debug from the basics. Why would it change focus only when switching to Volumetric? Is it because calibration parameters are stored and referenced in different classes within |
Thank you @diegoasua for your suggestion and help! The next thing i'll try to do is to compare the I suspect part of the difference in the focus could be due to a mismatch in these two parameters, but it's just a supposition (based also on the fact that most other variables either do not change/impact the actual result or they impact it in ways which don't seem relatable to the actual problem, as far as for my testing) |
That's a good place to start. I'd also follow the tracks of pressing the |
So, the comparison between the wave part and the piezo values seem to explain the problem -> even though I'm not sure where to fix and what causes it. Here's the image comparing the two: As you can see the actual values written in the piezo are correct, while the wave_part is offset of 11 up. Since the wave part is used to calculate the sync for the lateral and frontal beams I'd say it's the root cause of the defocusing. Now the problems remains to understand how and why this offset is added to the wave. |
is this number independent on the specified scanning range/the piezo positions used for the calibration? |
I've updated the previous image since there was an error (the offset is 11 not 21) I've also performed other tests (all were done with the same calibration points):
So this offset is dependent of both the range and frequency. Update: |
Could this be a timing issue? I/O to the NI card not fast enough and that causes the offset? I can't think of anything else. Scanning buffers are accelerated with Numba JIT compilation. That being said there are known speed limits to python when running on edge even if jitted. @vigji do you agree? |
@fedem-p what happens with constant frequency and piezo range but different offsets? |
This is the results with constant range but different start/end positions for the scanning:
Is this what you meant @vigji ? |
It still changes a lot even with all conditions being the same except the starting angle of the galvos. That's 0.5 offset change between conditions. To me this smells even more like hardware + timing, nothing to do with the code itself (other than inherent speed of Python) |
Can you make even larger changes? Like, 0-40 or 360-400? |
Updated range:
|
So, the only reassuring thing I'm seeing is that it is very linear over all quantities (frequency, range, scanning starting point). I think this makes the hardware + timing hp unlikely, @diegoasua. Although I'm still very puzzled, as this is so linear on all dimensions maybe we can just try to calculate a parameter-dependent offset. Incredibly annoying and ugly, but maybe as we do it we realise what the underlying problem could be :) |
I'll have a more detailed look on the weekend |
Haven't found a smart way to combine all the parameters in order to calculate the offset, but I have this other (equally not ideal) solution: We can actually compute the shift at run time -> at the moment it slows down the code by roughly 1ms Here's the code: wave_part = self.recorded_signal.read(i_sample, self.n_samples)
off = np.mean((np.array(wave_part[4000:8000]) - np.array(temp1[4000:8000])))
wave_part = wave_part - off The main problem with this solution are the hard-coded values -> the goal would be to find the part of the wave which is actually parallel with the piezo expected value. |
So my diagnosis is as follows: For the planar mode and calibration the set piezo position, i.e. the values written to the NI card is used. In the volume mode, the read piezo position is used, and by the interface in ( I think the piezo controller might even have a hardware knob to adjust this directly (which you could then fix live with an oscilloscope), but I might also be mistaken. |
I know this is probably related to #103 and #104, But I though it would have been good to have a single thread to discuss this specific problem.
Expected Behavior
After correctly calibrating the scanners, if mode is switched to planar or volume the preview should remain in focus.
Actual behavior
After correctly calibrating the scanners, if switching mode to planar the live view is in focus as expected.
However, the focus is lost in the volumetric mode.
Exploration of exact behavior of the scanners
I've spent quite some time reading the commands sent to piezo and lateral scanner to further understand what caused this problem.
In this image there are plotted the piezo values against the lateral scanning.
The legend is explained as follows:
Ideally the part of the wave of the piezo vs lateral where we send the camera pulses should match in planar and volumetric mode.
Where is this in the code?
The main place of divergence from planar mode and volumetric mode is inside the scanloops module.
In particular, there are a couple of functions which seem to impact the reading and writing of the piezo.
So far I've mostly looked into the fill_arrays function:
Here there's a thing that's not totally clear to me:
The way the values are written on the piezo (
self.board.z_piezo = self.z_waveform.values(self.shifted_time)
) and then read to get the wave_part (wave_part = self.recorded_signal.read(i_sample, self.n_samples)
)I'm not fully sure of how this two lines relate to each other.
What I found so far is that adding an arbitrary offset to the wavepart seems to get closer to fix the problem,
i.e.
wave_part = self.recorded_signal.read(i_sample, self.n_samples) + 10
Furthermore, the way the waveform for the piezo is generated seems totally correct to me.
Speculation
An hypothesis that I have is that we may need to readjust the minimum/maximum piezo values to account for the part of the wave which is declining towards the minimum. (I haven't manage to test this yet)
Help
I would appreciate any input and clarification in the functioning of the volumetric mode, since maybe I'm missing something that could cause the issue in question.
I'll try to update this thread with what I find next week.
Let me know if you have any ideas regarding this @vilim, @diegoasua and, @vigji
The text was updated successfully, but these errors were encountered: