{"id":417,"date":"2013-03-04T10:10:06","date_gmt":"2013-03-04T18:10:06","guid":{"rendered":"http:\/\/micromouseusa.com\/?p=417"},"modified":"2013-03-04T10:45:05","modified_gmt":"2013-03-04T18:45:05","slug":"a-simple-way-to-avoid-post-sensor-reading-fading-issue","status":"publish","type":"post","link":"http:\/\/micromouseusa.com\/?p=417","title":{"rendered":"A simple way to avoid post sensor reading fading issue."},"content":{"rendered":"<p>Since lots of people have this issue when mouse running though the post, the unstable reading makes mouse wobbling around this area. To solve this, you can just simply use your side sensors and diagonal sensors alternatively to avoid the post reading fading issue if your mouse has 6 sensors. However, for a 4 sensor mouse, there is no extra sensor you can use to void post when running by this way. So here is a simpler way to fix this without doing too much extra work.(assume all sensors are un-linearized)<\/p>\n<p><span style=\"color: #ff6600;\">If(leftSensor &gt; leftMiddleValue &amp;&amp; rightSensor &lt; rightMiddleValue)\/\/case 1<\/span><\/p>\n<p><span style=\"color: #ff6600;\">\u00a0\u00a0\u00a0 errorP = leftMiddleValue \u2013 leftSensor;<\/span><\/p>\n<p><span style=\"color: #ff6600;\">Else if(rightSensor &gt; rightMiddleValue &amp;&amp; leftSensor &lt; leftMiddleValue)\/\/case 2<\/span><\/p>\n<p><span style=\"color: #ff6600;\">\u00a0\u00a0\u00a0 errorP = rightSensor \u2013 rightMiddleValue;<\/span><\/p>\n<p><span style=\"color: #ff6600;\">Else \/\/case 3 do nothing, let encoder to align the mouse<\/span><\/p>\n<p><span style=\"color: #ff6600;\">\u00a0\u00a0\u00a0 errorP = 0;<\/span><\/p>\n<p><span style=\"color: #ff6600;\">errorD = errorP \u2013 oldErrorP;<\/span><\/p>\n<p><span style=\"color: #ff6600;\">oldErrorP = errorP;<\/span><\/p>\n<p><span style=\"color: #ff6600;\">totalError = kp*errorP + kd*errorD;<\/span><\/p>\n<p><span style=\"color: #ff6600;\">setLeftPwm(leftBaseSpeed \u2013 totalError);<\/span><\/p>\n<p><span style=\"color: #ff6600;\">setRightPwm(rightBaseSpeed + totalError);<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>the advantage for this code is it only use sensor to alignment when one side is larger than threshold where other side smaller than threshold. So the mouse won\u2019t use sensor value when both sensor smaller than threshold when passing the post, and it automatically goes to case 3 only use encoder to align the mouse. I was inspired from the lecture that Ng Beng Kiat made at the year 2009 in Taiwan and thanks for his help here :).<\/p>\n<p>The disadvantage for this code is if you don&#8217;t have speed profile to make your mouse running straight with encoder feedback, your mouse won&#8217;t be able to align itself when the mouse is away from middle point when there is only one wall available to use. You will need to add more else if case to fix this.<\/p>\n<p>Even thought it will avoid most of the post fading issue but there is still some exceptions. If the post is plastic and the wall is wood, since the reading from plastic post is higher than wood wall, the mouse will still jerk during the process.<\/p>\n<p>Note that if you have rotational speed profile, you only scale and add errorP to the rotational error. If you don\u2019t have any speed profile due to the low resolution of your encoder, you can just simply use the entire code above to make mouse go straight during the wall-to-no-wall or no-wall-to-wall transitions. The method I mentioned <a href=\"http:\/\/micromouseusa.com\/?p=389\">here <\/a>is also valid except you will need more efforts to avoid the post when passing through.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since lots of people have this issue when mouse running though the post, the unstable reading makes mouse wobbling around this area. To solve this, you can just simply use your side sensors and diagonal sensors alternatively to avoid the &hellip; <a href=\"http:\/\/micromouseusa.com\/?p=417\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[11],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/micromouseusa.com\/index.php?rest_route=\/wp\/v2\/posts\/417"}],"collection":[{"href":"http:\/\/micromouseusa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/micromouseusa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/micromouseusa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/micromouseusa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=417"}],"version-history":[{"count":10,"href":"http:\/\/micromouseusa.com\/index.php?rest_route=\/wp\/v2\/posts\/417\/revisions"}],"predecessor-version":[{"id":420,"href":"http:\/\/micromouseusa.com\/index.php?rest_route=\/wp\/v2\/posts\/417\/revisions\/420"}],"wp:attachment":[{"href":"http:\/\/micromouseusa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/micromouseusa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=417"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/micromouseusa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}