{"action":"created","issue":{"url":"https://api.github.com/repos/betaflight/betaflight/issues/4736","repository_url":"https://api.github.com/repos/betaflight/betaflight","labels_url":"https://api.github.com/repos/betaflight/betaflight/issues/4736/labels{/name}","comments_url":"https://api.github.com/repos/betaflight/betaflight/issues/4736/comments","events_url":"https://api.github.com/repos/betaflight/betaflight/issues/4736/events","html_url":"https://github.com/betaflight/betaflight/issues/4736","id":280833270,"number":4736,"title":"Gyro overflow slew filter only works in 32KHz mode","user":{"login":"etracer65","id":17088539,"avatar_url":"https://avatars1.githubusercontent.com/u/17088539?v=4","gravatar_id":"","url":"https://api.github.com/users/etracer65","html_url":"https://github.com/etracer65","followers_url":"https://api.github.com/users/etracer65/followers","following_url":"https://api.github.com/users/etracer65/following{/other_user}","gists_url":"https://api.github.com/users/etracer65/gists{/gist_id}","starred_url":"https://api.github.com/users/etracer65/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etracer65/subscriptions","organizations_url":"https://api.github.com/users/etracer65/orgs","repos_url":"https://api.github.com/users/etracer65/repos","events_url":"https://api.github.com/users/etracer65/events{/privacy}","received_events_url":"https://api.github.com/users/etracer65/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":52,"created_at":"2017-12-10T18:53:26Z","updated_at":"2017-12-16T17:11:19Z","closed_at":null,"author_association":"NONE","body":"@martinbudden @mikeller @gke \r\n\r\nTL;DR: The gyro overflow slew filter hasn't been actually doing anything for the majority of the users with the affected ICM206xx gyros.\r\n\r\nThe story:\r\n\r\nI got out my \"Drill of Doom\" yaw spin rig to do some testing and thought I was losing my mind.  Testing with an ICM20608G gyro showed that the slew filter wasn't preventing the gyro inversion.  I knew it *was* working and even as recently as issue https://github.com/betaflight/betaflight/issues/4407 and PR4412 as this was the fix to add MPU6500 to the conditional compilation (ICM20608G is detected as MPU6500).  I tested the fix (I swear I did!) and everything was good.  So why wasn't it working now?\r\n\r\nSo I tested many versions back through earlier commits trying to find the problem.  All the way back to the original slew filter implementation in 3.2.0RC5 and still it wasn't working.\r\n\r\nThrough debugging and modifying the code I determined that the `gyroSlewLimiter()` function in gyro.c was in fact being called - it just wasn't catching the gyro overflow.  So I became suspicious of the +-16384 (1<<14) threshold for triggering.  After some spin runs where I captured raw gyro values I began to see that the raw gyro values were more \"smoothly\" moving between +32767 and -32768 with intermediate values in between.  The steps weren't enough to trigger the slew filter!\r\n\r\nSo why is this happening now?  Then I remembered that previously I did all the testing with 32KHz gyro mode enabled because we wanted to capture the most granular gyro data.  However these tests I was running with 32KHz off and the gyro/pid at 8/8K.  So I switched back to 32KHz mode and ran at 328K and the slew filter started  working again!  The raw gyro values were flipping from +32767 to -32768 is one sample like before.  Next I tested with 32KHz enabled but with the gyro/pid at 8/8K.  Again the slew filter worked as expected.\r\n\r\nSo looking deeper at the raw gyro data it appears when the gyro is not in 32K mode there is additional filtering or a lowpass stage in the gyro that is smoothing the data.  This can be seen in the log where rather than flipping from +32767 to -32768, it goes:\r\n32768, 19595, 12524, 6220, -5250, -10255, -19344, -24054, -29021, -32768\r\n\r\nThis can be seen in the log: icm20608g-bf322-8k-raw.BBL from sample 28503 to 28516.\r\n\r\nSo looking at how the data is behaving I'm not sure how the current slew filter design can be reconciled to work.  The data appears to be too smoothed to allow effective detection by a magnitude change from one sample to the next.  Simply changing the detection threshold from 16384 to a smaller number doesn't look viable.  Too small a number and you get false detection.\r\n\r\n**Perhaps we need to shift to comparing multiple samples or even a magnitude change *over a defined time period*.**  Like if the raw gyro value exceeds a magnitude change of over X in Y time then consider that invalid data.\r\n\r\nAlternately, the ICM206xx gyros could be *forced* to run in 32KHz mode to disable the internal filtering (gyro/pid loop could still be allowed lower values as this works properly).  This would allow the slew filter to start working again.  However this would probably have noise/tuning ramifications.\r\n\r\nThe attached zip file has a bunch of logs with different settings.  Each \"flight\" has a slow ramp to overflow and a faster spin up for comparison.  Every one is an overflow situation.\r\n\r\n`icm20608g-bf322-8k-notch.BBL     -- 32K off, 8/8K debug_mode = notch -- FAIL`\r\n`icm20608g-bf322-8k-raw.BBL       -- 32K off, 8/8K debug_mode = raw   -- FAIL`\r\n`icm20608g-bf322-32k-notch.BBL    -- 32K on, 32/8K debug_mode = notch`\r\n`icm20608g-bf322-32k-raw.BBL      -- 32K on, 32/8K debug_mode = raw`\r\n`icm20608g-bf322-32k@8k-notch.BBL -- 32K on, 8/8K debug_mode = notch`\r\n`icm20608g-bf322-32k@8k-raw.BBL   -- 32K on, 8/8K debug_mode = raw`\r\n\r\nYou can probably ignore the \"notch\" versions as the debug data is after the slew filter.  So in cases where the slew filter is working it's not very informative.  But in cases where it's not you can see the intermediate gyro values in dps rather than the raw ADC values.\r\n\r\nThese logs are all with stable 3.2.2, target AIRBOTF4 and gyro ICM20608G.\r\n\r\n[slew_filter_testing.zip](https://github.com/betaflight/betaflight/files/1545940/slew_filter_testing.zip)\r\n"},"comment":{"url":"https://api.github.com/repos/betaflight/betaflight/issues/comments/352196458","html_url":"https://github.com/betaflight/betaflight/issues/4736#issuecomment-352196458","issue_url":"https://api.github.com/repos/betaflight/betaflight/issues/4736","id":352196458,"user":{"login":"ledvinap","id":2318015,"avatar_url":"https://avatars2.githubusercontent.com/u/2318015?v=4","gravatar_id":"","url":"https://api.github.com/users/ledvinap","html_url":"https://github.com/ledvinap","followers_url":"https://api.github.com/users/ledvinap/followers","following_url":"https://api.github.com/users/ledvinap/following{/other_user}","gists_url":"https://api.github.com/users/ledvinap/gists{/gist_id}","starred_url":"https://api.github.com/users/ledvinap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ledvinap/subscriptions","organizations_url":"https://api.github.com/users/ledvinap/orgs","repos_url":"https://api.github.com/users/ledvinap/repos","events_url":"https://api.github.com/users/ledvinap/events{/privacy}","received_events_url":"https://api.github.com/users/ledvinap/received_events","type":"User","site_admin":false},"created_at":"2017-12-16T17:11:19Z","updated_at":"2017-12-16T17:11:19Z","author_association":"NONE","body":"@martinbudden : Hitting quad arm with small hammer should provide some estimate of angular acceleration involved in crash. My wild guess is that angular acceleration will be order of magnitude lower.\r\nImpact interval on golf ball is about 0.5ms ... "}}
{"actor":{"display_login":"ledvinap"}}