{"id":398,"date":"2013-02-17T20:10:28","date_gmt":"2013-02-18T04:10:28","guid":{"rendered":"http:\/\/micromouseusa.com\/?p=398"},"modified":"2013-02-25T16:41:34","modified_gmt":"2013-02-26T00:41:34","slug":"always-the-first-function-to-test-when-mouse-is-constructed","status":"publish","type":"post","link":"http:\/\/micromouseusa.com\/?p=398","title":{"rendered":"always the first function to test when mouse is constructed"},"content":{"rendered":"<p>I got my mouse constructed recently, everything were fine except the external crystal wasn&#8217;t oscillating, so I used internal crystal instead.<\/p>\n<p><a href=\"http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0902_resize.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-404\" alt=\"IMG_0902_resize\" src=\"http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0902_resize.jpg\" width=\"1280\" height=\"853\" srcset=\"http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0902_resize.jpg 1280w, http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0902_resize-300x199.jpg 300w, http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0902_resize-1024x682.jpg 1024w, http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0902_resize-450x300.jpg 450w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/a> <a href=\"http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0907_resize.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-403\" alt=\"IMG_0907_resize\" src=\"http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0907_resize.jpg\" width=\"1280\" height=\"853\" srcset=\"http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0907_resize.jpg 1280w, http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0907_resize-300x199.jpg 300w, http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0907_resize-1024x682.jpg 1024w, http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0907_resize-450x300.jpg 450w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/a> <a href=\"http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0917_resize.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-402\" alt=\"IMG_0917_resize\" src=\"http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0917_resize.jpg\" width=\"1280\" height=\"853\" srcset=\"http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0917_resize.jpg 1280w, http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0917_resize-300x199.jpg 300w, http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0917_resize-1024x682.jpg 1024w, http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0917_resize-450x300.jpg 450w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/a> <a href=\"http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0922_resize.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-405\" alt=\"IMG_0922_resize\" src=\"http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0922_resize.jpg\" width=\"1280\" height=\"853\" srcset=\"http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0922_resize.jpg 1280w, http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0922_resize-300x199.jpg 300w, http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0922_resize-1024x682.jpg 1024w, http:\/\/micromouseusa.com\/wp-content\/uploads\/2013\/02\/IMG_0922_resize-450x300.jpg 450w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/a><\/p>\n<p>There is always an first function you want to test on your mouse after all devices are properly settled. My favorite function is the one that makes mouse keep distance with wall by using 2 front sensors, also it&#8217;s the easiest function for me to write. Here is the code for this function:<\/p>\n<p><span style=\"color: #ffff99;\">void adjuster(void)<\/span><br \/>\n<span style=\"color: #ffff99;\"> {<\/span><br \/>\n<span style=\"color: #ffff99;\"> int curt = micros();\/\/start to track time in order to make one adjust every 1000us<\/span><br \/>\n<span style=\"color: #ffff99;\"> readSensor();<\/span><br \/>\n<span style=\"color: #ffff99;\"> setLeftPwm((2900- LFSensor));\/\/set left motor speed<\/span><br \/>\n<span style=\"color: #ffff99;\"> setRightPwm((2500 &#8211; RFSensor));\/\/set right motor speed<\/span><br \/>\n<span style=\"color: #ffff99;\"> TIM2-&gt;CNT=25000;\/\/keep resetting encoder counts prevent overflow<\/span><br \/>\n<span style=\"color: #ffff99;\"> TIM3-&gt;CNT=25000;<\/span><br \/>\n<span style=\"color: #ffff99;\"> elapseMicros(1000, curt);\/\/elapse 1000 micro seconds<\/span><br \/>\n<span style=\"color: #ffff99;\"> }<\/span><\/p>\n<p>I also took a video to DEMO this function:<\/p>\n<p><iframe loading=\"lazy\" width=\"584\" height=\"329\" src=\"http:\/\/www.youtube.com\/embed\/6PKUbhkdqWk?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>once you have this function working, PID is usually the next to test since we will be able to write a similar function to make mouse stop if there is a wall to the front when mouse is moving forward with PID. I will talk about how to write a simple PID by utlizing 2 side sensors next time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I got my mouse constructed recently, everything were fine except the external crystal wasn&#8217;t oscillating, so I used internal crystal instead. There is always an first function you want to test on your mouse after all devices are properly settled. &hellip; <a href=\"http:\/\/micromouseusa.com\/?p=398\">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":[7],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/micromouseusa.com\/index.php?rest_route=\/wp\/v2\/posts\/398"}],"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=398"}],"version-history":[{"count":6,"href":"http:\/\/micromouseusa.com\/index.php?rest_route=\/wp\/v2\/posts\/398\/revisions"}],"predecessor-version":[{"id":408,"href":"http:\/\/micromouseusa.com\/index.php?rest_route=\/wp\/v2\/posts\/398\/revisions\/408"}],"wp:attachment":[{"href":"http:\/\/micromouseusa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/micromouseusa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/micromouseusa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}