{"action":"created","comment":{"url":"https://api.github.com/repos/TauLabs/TauLabs/pulls/comments/36781179","id":36781179,"diff_hunk":"@@ -0,0 +1,160 @@\n+/**\n+ ******************************************************************************\n+ * @addtogroup TauLabsLibraries Tau Labs Libraries\n+ * @{\n+ * @addtogroup TauLabsMath Tau Labs math support libraries\n+ * @{\n+ *\n+ * @file       pid.c\n+ * @author     The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.\n+ * @author     Tau Labs, http://taulabs.org, Copyright (C) 2012-2014\n+ * @brief      PID Control algorithms\n+ *\n+ * @see        The GNU Public License (GPL) Version 3\n+ *\n+ *****************************************************************************/\n+/*\n+ * This program is free software; you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License as published by\n+ * the Free Software Foundation; either version 3 of the License, or\n+ * (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful, but\n+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n+ * for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License along\n+ * with this program; if not, write to the Free Software Foundation, Inc.,\n+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n+ */\n+\n+#include <math.h>\n+#include \"misc_math.h\"\n+#include \"cic.h\"\n+\n+\n+//! Store the filter parameter\n+static uint8_t cic_filter_order     = 1;","path":"flight/Libraries/math/cic.c","position":38,"original_position":38,"commit_id":"463e221bf15c90f2478db656fcb6257ab2bda662","original_commit_id":"463e221bf15c90f2478db656fcb6257ab2bda662","user":{"login":"Trex4Git","id":9142182,"avatar_url":"https://avatars.githubusercontent.com/u/9142182?v=3","gravatar_id":"","url":"https://api.github.com/users/Trex4Git","html_url":"https://github.com/Trex4Git","followers_url":"https://api.github.com/users/Trex4Git/followers","following_url":"https://api.github.com/users/Trex4Git/following{/other_user}","gists_url":"https://api.github.com/users/Trex4Git/gists{/gist_id}","starred_url":"https://api.github.com/users/Trex4Git/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Trex4Git/subscriptions","organizations_url":"https://api.github.com/users/Trex4Git/orgs","repos_url":"https://api.github.com/users/Trex4Git/repos","events_url":"https://api.github.com/users/Trex4Git/events{/privacy}","received_events_url":"https://api.github.com/users/Trex4Git/received_events","type":"User","site_admin":false},"body":"I also thought about, but was not sure if we need a cic filter somewhere else.\r\nSo i implemented it like it is done for pid.c/pid.h\r\nSo we just have one CIC filter setup, and can't use different instances. But otherwise we would store the CIC setup for all 3 axes, so some overhead.\r\n\r\nAnd for SmallF1 targets cic.h will not be included, so we don't lose RAM with that on these targets.\r\n\r\nBut if you like to have more modular, i will change this.","created_at":"2015-08-11T18:33:54Z","updated_at":"2015-08-11T18:33:54Z","html_url":"https://github.com/TauLabs/TauLabs/pull/1781#discussion_r36781179","pull_request_url":"https://api.github.com/repos/TauLabs/TauLabs/pulls/1781","_links":{"self":{"href":"https://api.github.com/repos/TauLabs/TauLabs/pulls/comments/36781179"},"html":{"href":"https://github.com/TauLabs/TauLabs/pull/1781#discussion_r36781179"},"pull_request":{"href":"https://api.github.com/repos/TauLabs/TauLabs/pulls/1781"}}},"pull_request":{"url":"https://api.github.com/repos/TauLabs/TauLabs/pulls/1781","id":41974515,"html_url":"https://github.com/TauLabs/TauLabs/pull/1781","diff_url":"https://github.com/TauLabs/TauLabs/pull/1781.diff","patch_url":"https://github.com/TauLabs/TauLabs/pull/1781.patch","issue_url":"https://api.github.com/repos/TauLabs/TauLabs/issues/1781","number":1781,"state":"open","locked":false,"title":"[WIP] Flight: adding gyro down-sampling & additional filtering functionality","user":{"login":"Trex4Git","id":9142182,"avatar_url":"https://avatars.githubusercontent.com/u/9142182?v=3","gravatar_id":"","url":"https://api.github.com/users/Trex4Git","html_url":"https://github.com/Trex4Git","followers_url":"https://api.github.com/users/Trex4Git/followers","following_url":"https://api.github.com/users/Trex4Git/following{/other_user}","gists_url":"https://api.github.com/users/Trex4Git/gists{/gist_id}","starred_url":"https://api.github.com/users/Trex4Git/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Trex4Git/subscriptions","organizations_url":"https://api.github.com/users/Trex4Git/orgs","repos_url":"https://api.github.com/users/Trex4Git/repos","events_url":"https://api.github.com/users/Trex4Git/events{/privacy}","received_events_url":"https://api.github.com/users/Trex4Git/received_events","type":"User","site_admin":false},"body":"Adding different down-sampling methods & filter\r\nOriginal intention was to give the Sparky2 with MPU9250 the possibility to disable the DLPF in the MPU but run at lower rates then 8kHz\r\nEarly discussion and development is in this issue: https://github.com/TauLabs/TauLabs/issues/1730\r\nThere are also performance measurements regarding the CPU load and theoretical investigations on the filter. \r\n\r\nAlso its interesting if we can reduce the noise in gyro signal, or get less delay.\r\nThe way it currently works in Taulabs is that for higher Gyro rates, the gyro LPF has a wider passband and less delay, but more noise gets through the filter.\r\nEspecially the CIC filter can have a good anti-aliasing performance, and it will be interesting to see, if that is useful for us.\r\nBecause i am not sure how good the anti-aliasing filter is in the MPU, especially when the DLPF is disabled. There i posted some delays of the CIC filter and the DLPF in MPU.\r\n\r\nSo one interest of me is also to find a good setup regarding noise reduction, small delay and acceptable CPU load. \r\nWith the settings I implemented at the moment we could do some tests with different setups. It would be nice if some people also have interest in testing and collecting data. Because my quad can't fly at the moment, and i have to fix some things. And i have also not much experience with flying.\r\n\r\nNow the implementation of CIC filter is done, so I started this PR to see if there are principal concerns.\r\nAt the moment its only fully implemented for Quanton, but before enabling the config for other MPU6000 targets or porting the changes also to MP9250 and Sparky2 I want to be sure, if it is OK in principal.\r\n\r\nThe settings are in HwTargetXYZ UAVObject, but only implemented for Quanton at the moment (the other MPU6000  targets run with the shown default config).\r\n\r\n![hw_quanton_downsampling_settings_cut](https://cloud.githubusercontent.com/assets/9142182/9156238/2f70f5b2-3ed3-11e5-9621-2055d2e5e363.png)\r\n\r\nThe settings are grouped under GyroDownSampling:\r\n- Drop: works at the lowest level in the MPU IRQ and just drops unused samples. Should be a replacement for the sample rate divider like in MPU6000, that don't work with MPU9250 when DLPF is disabled. Has the lowest CPU load, \"but highest priority\". So the rest of the system gets the output rate of this. Setting = 1 means use every sample, = 4 means down-sampling by 4 / use every 4th sample. Can be combined with LPF down-sampling\r\n- LPF: works one level above the MPU IRQ, in the MPU task. Uses all samples that are output from the IRQ. So there are more information that we can work with, and that might have an advantage for the control system. But produces higher CPU load. The rest of the system gets  the output rate of this. Setting = 1 means use every sample and do no filte; = 4 means down-sampling by 4.\r\n- LPF_Order: determines the order of the filter that is used for down-sampling. \r\n\t- = 0: simple averaging of the collected samples (boxcar filtering?)\r\n\t- = 1-3: a CIC filter of this order is used\r\n- LPF_DDelay: determines the differential delay if a CIC filter is used. 1 and 2 are supported at the moment\r\n\r\nAt the moment there are so many settings, as still test have to be done as described earlier.\r\nLater they may be reduced, or stay in the  UAVObject, but in GCS there will be a default config for a \"high speed sampling\" mode.\r\n","created_at":"2015-08-09T18:16:58Z","updated_at":"2015-08-11T18:33:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6879d723e51715e56f10a9c5c2a7dc77596e1e0a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/TauLabs/TauLabs/pulls/1781/commits","review_comments_url":"https://api.github.com/repos/TauLabs/TauLabs/pulls/1781/comments","review_comment_url":"https://api.github.com/repos/TauLabs/TauLabs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/TauLabs/TauLabs/issues/1781/comments","statuses_url":"https://api.github.com/repos/TauLabs/TauLabs/statuses/463e221bf15c90f2478db656fcb6257ab2bda662","head":{"label":"Trex4Git:flight_gyro_downsampling","ref":"flight_gyro_downsampling","sha":"463e221bf15c90f2478db656fcb6257ab2bda662","user":{"login":"Trex4Git","id":9142182,"avatar_url":"https://avatars.githubusercontent.com/u/9142182?v=3","gravatar_id":"","url":"https://api.github.com/users/Trex4Git","html_url":"https://github.com/Trex4Git","followers_url":"https://api.github.com/users/Trex4Git/followers","following_url":"https://api.github.com/users/Trex4Git/following{/other_user}","gists_url":"https://api.github.com/users/Trex4Git/gists{/gist_id}","starred_url":"https://api.github.com/users/Trex4Git/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Trex4Git/subscriptions","organizations_url":"https://api.github.com/users/Trex4Git/orgs","repos_url":"https://api.github.com/users/Trex4Git/repos","events_url":"https://api.github.com/users/Trex4Git/events{/privacy}","received_events_url":"https://api.github.com/users/Trex4Git/received_events","type":"User","site_admin":false},"repo":{"id":35729971,"name":"TauLabs","full_name":"Trex4Git/TauLabs","owner":{"login":"Trex4Git","id":9142182,"avatar_url":"https://avatars.githubusercontent.com/u/9142182?v=3","gravatar_id":"","url":"https://api.github.com/users/Trex4Git","html_url":"https://github.com/Trex4Git","followers_url":"https://api.github.com/users/Trex4Git/followers","following_url":"https://api.github.com/users/Trex4Git/following{/other_user}","gists_url":"https://api.github.com/users/Trex4Git/gists{/gist_id}","starred_url":"https://api.github.com/users/Trex4Git/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Trex4Git/subscriptions","organizations_url":"https://api.github.com/users/Trex4Git/orgs","repos_url":"https://api.github.com/users/Trex4Git/repos","events_url":"https://api.github.com/users/Trex4Git/events{/privacy}","received_events_url":"https://api.github.com/users/Trex4Git/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Trex4Git/TauLabs","description":"","fork":true,"url":"https://api.github.com/repos/Trex4Git/TauLabs","forks_url":"https://api.github.com/repos/Trex4Git/TauLabs/forks","keys_url":"https://api.github.com/repos/Trex4Git/TauLabs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Trex4Git/TauLabs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Trex4Git/TauLabs/teams","hooks_url":"https://api.github.com/repos/Trex4Git/TauLabs/hooks","issue_events_url":"https://api.github.com/repos/Trex4Git/TauLabs/issues/events{/number}","events_url":"https://api.github.com/repos/Trex4Git/TauLabs/events","assignees_url":"https://api.github.com/repos/Trex4Git/TauLabs/assignees{/user}","branches_url":"https://api.github.com/repos/Trex4Git/TauLabs/branches{/branch}","tags_url":"https://api.github.com/repos/Trex4Git/TauLabs/tags","blobs_url":"https://api.github.com/repos/Trex4Git/TauLabs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Trex4Git/TauLabs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Trex4Git/TauLabs/git/refs{/sha}","trees_url":"https://api.github.com/repos/Trex4Git/TauLabs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Trex4Git/TauLabs/statuses/{sha}","languages_url":"https://api.github.com/repos/Trex4Git/TauLabs/languages","stargazers_url":"https://api.github.com/repos/Trex4Git/TauLabs/stargazers","contributors_url":"https://api.github.com/repos/Trex4Git/TauLabs/contributors","subscribers_url":"https://api.github.com/repos/Trex4Git/TauLabs/subscribers","subscription_url":"https://api.github.com/repos/Trex4Git/TauLabs/subscription","commits_url":"https://api.github.com/repos/Trex4Git/TauLabs/commits{/sha}","git_commits_url":"https://api.github.com/repos/Trex4Git/TauLabs/git/commits{/sha}","comments_url":"https://api.github.com/repos/Trex4Git/TauLabs/comments{/number}","issue_comment_url":"https://api.github.com/repos/Trex4Git/TauLabs/issues/comments{/number}","contents_url":"https://api.github.com/repos/Trex4Git/TauLabs/contents/{+path}","compare_url":"https://api.github.com/repos/Trex4Git/TauLabs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Trex4Git/TauLabs/merges","archive_url":"https://api.github.com/repos/Trex4Git/TauLabs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Trex4Git/TauLabs/downloads","issues_url":"https://api.github.com/repos/Trex4Git/TauLabs/issues{/number}","pulls_url":"https://api.github.com/repos/Trex4Git/TauLabs/pulls{/number}","milestones_url":"https://api.github.com/repos/Trex4Git/TauLabs/milestones{/number}","notifications_url":"https://api.github.com/repos/Trex4Git/TauLabs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Trex4Git/TauLabs/labels{/name}","releases_url":"https://api.github.com/repos/Trex4Git/TauLabs/releases{/id}","created_at":"2015-05-16T15:56:57Z","updated_at":"2015-06-13T23:33:16Z","pushed_at":"2015-08-09T21:19:19Z","git_url":"git://github.com/Trex4Git/TauLabs.git","ssh_url":"git@github.com:Trex4Git/TauLabs.git","clone_url":"https://github.com/Trex4Git/TauLabs.git","svn_url":"https://github.com/Trex4Git/TauLabs","homepage":"taulabs.org","size":265966,"stargazers_count":1,"watchers_count":1,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"next"}},"base":{"label":"TauLabs:next","ref":"next","sha":"992e7115c98329a1390625a66d16d2cdd071b7ee","user":{"login":"TauLabs","id":3201381,"avatar_url":"https://avatars.githubusercontent.com/u/3201381?v=3","gravatar_id":"","url":"https://api.github.com/users/TauLabs","html_url":"https://github.com/TauLabs","followers_url":"https://api.github.com/users/TauLabs/followers","following_url":"https://api.github.com/users/TauLabs/following{/other_user}","gists_url":"https://api.github.com/users/TauLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/TauLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TauLabs/subscriptions","organizations_url":"https://api.github.com/users/TauLabs/orgs","repos_url":"https://api.github.com/users/TauLabs/repos","events_url":"https://api.github.com/users/TauLabs/events{/privacy}","received_events_url":"https://api.github.com/users/TauLabs/received_events","type":"Organization","site_admin":false},"repo":{"id":6589168,"name":"TauLabs","full_name":"TauLabs/TauLabs","owner":{"login":"TauLabs","id":3201381,"avatar_url":"https://avatars.githubusercontent.com/u/3201381?v=3","gravatar_id":"","url":"https://api.github.com/users/TauLabs","html_url":"https://github.com/TauLabs","followers_url":"https://api.github.com/users/TauLabs/followers","following_url":"https://api.github.com/users/TauLabs/following{/other_user}","gists_url":"https://api.github.com/users/TauLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/TauLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TauLabs/subscriptions","organizations_url":"https://api.github.com/users/TauLabs/orgs","repos_url":"https://api.github.com/users/TauLabs/repos","events_url":"https://api.github.com/users/TauLabs/events{/privacy}","received_events_url":"https://api.github.com/users/TauLabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/TauLabs/TauLabs","description":"","fork":false,"url":"https://api.github.com/repos/TauLabs/TauLabs","forks_url":"https://api.github.com/repos/TauLabs/TauLabs/forks","keys_url":"https://api.github.com/repos/TauLabs/TauLabs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TauLabs/TauLabs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TauLabs/TauLabs/teams","hooks_url":"https://api.github.com/repos/TauLabs/TauLabs/hooks","issue_events_url":"https://api.github.com/repos/TauLabs/TauLabs/issues/events{/number}","events_url":"https://api.github.com/repos/TauLabs/TauLabs/events","assignees_url":"https://api.github.com/repos/TauLabs/TauLabs/assignees{/user}","branches_url":"https://api.github.com/repos/TauLabs/TauLabs/branches{/branch}","tags_url":"https://api.github.com/repos/TauLabs/TauLabs/tags","blobs_url":"https://api.github.com/repos/TauLabs/TauLabs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TauLabs/TauLabs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TauLabs/TauLabs/git/refs{/sha}","trees_url":"https://api.github.com/repos/TauLabs/TauLabs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TauLabs/TauLabs/statuses/{sha}","languages_url":"https://api.github.com/repos/TauLabs/TauLabs/languages","stargazers_url":"https://api.github.com/repos/TauLabs/TauLabs/stargazers","contributors_url":"https://api.github.com/repos/TauLabs/TauLabs/contributors","subscribers_url":"https://api.github.com/repos/TauLabs/TauLabs/subscribers","subscription_url":"https://api.github.com/repos/TauLabs/TauLabs/subscription","commits_url":"https://api.github.com/repos/TauLabs/TauLabs/commits{/sha}","git_commits_url":"https://api.github.com/repos/TauLabs/TauLabs/git/commits{/sha}","comments_url":"https://api.github.com/repos/TauLabs/TauLabs/comments{/number}","issue_comment_url":"https://api.github.com/repos/TauLabs/TauLabs/issues/comments{/number}","contents_url":"https://api.github.com/repos/TauLabs/TauLabs/contents/{+path}","compare_url":"https://api.github.com/repos/TauLabs/TauLabs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TauLabs/TauLabs/merges","archive_url":"https://api.github.com/repos/TauLabs/TauLabs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TauLabs/TauLabs/downloads","issues_url":"https://api.github.com/repos/TauLabs/TauLabs/issues{/number}","pulls_url":"https://api.github.com/repos/TauLabs/TauLabs/pulls{/number}","milestones_url":"https://api.github.com/repos/TauLabs/TauLabs/milestones{/number}","notifications_url":"https://api.github.com/repos/TauLabs/TauLabs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TauLabs/TauLabs/labels{/name}","releases_url":"https://api.github.com/repos/TauLabs/TauLabs/releases{/id}","created_at":"2012-11-08T01:01:18Z","updated_at":"2015-08-11T03:01:29Z","pushed_at":"2015-08-11T17:08:19Z","git_url":"git://github.com/TauLabs/TauLabs.git","ssh_url":"git@github.com:TauLabs/TauLabs.git","clone_url":"https://github.com/TauLabs/TauLabs.git","svn_url":"https://github.com/TauLabs/TauLabs","homepage":"taulabs.org","size":326774,"stargazers_count":254,"watchers_count":254,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":289,"mirror_url":null,"open_issues_count":242,"forks":289,"open_issues":242,"watchers":254,"default_branch":"next"}},"_links":{"self":{"href":"https://api.github.com/repos/TauLabs/TauLabs/pulls/1781"},"html":{"href":"https://github.com/TauLabs/TauLabs/pull/1781"},"issue":{"href":"https://api.github.com/repos/TauLabs/TauLabs/issues/1781"},"comments":{"href":"https://api.github.com/repos/TauLabs/TauLabs/issues/1781/comments"},"review_comments":{"href":"https://api.github.com/repos/TauLabs/TauLabs/pulls/1781/comments"},"review_comment":{"href":"https://api.github.com/repos/TauLabs/TauLabs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/TauLabs/TauLabs/pulls/1781/commits"},"statuses":{"href":"https://api.github.com/repos/TauLabs/TauLabs/statuses/463e221bf15c90f2478db656fcb6257ab2bda662"}}}}