linux-surface / iptsd

Userspace daemon for Intel Precise Touch & Stylus
GNU General Public License v2.0
86 stars 39 forks source link

Basic detection is a lot less smooth than advanced detection #111

Closed danielzgtg closed 1 year ago

danielzgtg commented 1 year ago

When using Detection = basic, scrolling feels very uncomfortable. It's smooth with Detection = advanced but that uses 45% CPU instead of 2%. Surely we can apply some smoothing to the basic algorithm without too much code or time complexity.

Expected Behavior (advanced)

It's smooth:

https://user-images.githubusercontent.com/25646384/220851382-babe11ac-5e51-4049-8323-89269f89a7db.mp4

The only other config edit was that I had to change PositionThresholdMin from 0.2 to 0.1 so it feels responsive when turning around when scrolling. I'm quite happy that it detected all my fingers all the time without me having to edit any threshold settings.

Actual Behavior (basic)

It's not smooth.

https://user-images.githubusercontent.com/25646384/220851485-826a6601-9cf3-4753-98b6-5757651fca07.mp4

You may want to play at a slower speed, step frame by frame, or play both at the same time. Another thing is that I don't get dizzy when watching other people play video games at low framerates, but I will get dizzy if it's me at the mouse and keyboard.

StollD commented 1 year ago

After looking at some plottings of scrolling I think this has to do with how the pixels of the heatmap are weighted when determining the center of the contact. The coordinates will often stick to the pixel with the highest value, until the value of the pixel below or above is higher, instead of gradually shifting towards that pixel.

I tried to disable the weighting for calculating the center of the contact but that didn't work that well either.

Some (very) stupid temporal averaging seems to improve scrolling so I will look into properly integrating that. My preference would be fixing the blob detection, but sadly I have no idea how.

StollD commented 1 year ago

I have some experimental code that combines the cluster search of the basic method with the gaussian fitting of the advanced method. For me this greatly improves the smoothness.

https://github.com/linux-surface/iptsd/tree/basic-gaussian

It is currently not finetuned at all, so the palm rejection is probably a bit off by default, and I haven't used it extensively yet. But I think the overall idea is good.

danielzgtg commented 1 year ago

Thank you for the code. It fixes most of the stuttering problems!

One thing I liked from the advanced detector is that it got rid of accidental clicks when scrolling. In this code, it still randomly clicks links on the webpage halfway while I'm dragging on them. It's the same amount of pressure as I used for the advanced detector, and I think it might have something to do with how close I'm to touchscreen pixel edges or corners. I will either have to make sure to always press harder or I could play with the thresholds in the config.

I also got [15:59:01.941] [warning] invalid equation system once. It was probably after I placed both palms on the screen and the CPU rose to 7%. Otherwise, CPU is normally 2%.

I'm wonder whether this new code can still be called "basic". As coding continues, it seems less and less basic and more like "regular" or "normal". I wonder whether the new code should be a separate detector, or if not whether that should be renamed.

StollD commented 1 year ago

One thing I liked from the advanced detector is that it got rid of accidental clicks when scrolling. In this code, it still randomly clicks links on the webpage halfway while I'm dragging on them. It's the same amount of pressure as I used for the advanced detector, and I think it might have something to do with how close I'm to touchscreen pixel edges or corners. I will either have to make sure to always press harder or I could play with the thresholds in the config.

The thresholds are a complete guess by me right now, so that is definitly possible. Calibrating iptsd might also help a bit.

I also noticed that Firefox will ignore that you are scrolling and treat the contact as a click if it is moving too slow. Idk if that might be the case here.

I also got [15:59:01.941] [warning] invalid equation system once. It was probably after I placed both palms on the screen and the CPU rose to 7%. Otherwise, CPU is normally 2%.

Yeah, it seems somewhat related to noise, because adding gaussian blurring made it occur less often. But when I blur the heatmap as strongly as the advanced detector, there are all sorts of other detection issues.

I'm wonder whether this new code can still be called "basic". As coding continues, it seems less and less basic and more like "regular" or "normal". I wonder whether the new code should be a separate detector, or if not whether that should be renamed.

I thought about that too. Another idea might be to just remove the advanced detector at some point when it is no longer required for handling the edge cases like noisy data, which the new code could already handle very well in my tests.

StollD commented 1 year ago

Since the basic and advanced algorithms have been removed with iptsd 1.2.0 and the new algorithm does not have the smoothness issue, I am closing this.