{"id":5537,"date":"2022-10-05T14:56:02","date_gmt":"2022-10-05T18:56:02","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/?p=5537"},"modified":"2022-10-05T14:56:03","modified_gmt":"2022-10-05T18:56:03","slug":"motor-marble-run","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/2022\/10\/05\/motor-marble-run\/","title":{"rendered":"Motor Marble Run"},"content":{"rendered":"\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-a66a2192-0fd4-4738-ae47-e3c9637534a0\" href=\"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-content\/uploads\/2022\/10\/base-plate-motor-laser-cut.sldprt\">base-plate-motor-laser-cut<\/a><a href=\"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-content\/uploads\/2022\/10\/base-plate-motor-laser-cut.sldprt\" class=\"wp-block-file__button\" download aria-describedby=\"wp-block-file--media-a66a2192-0fd4-4738-ae47-e3c9637534a0\">Download<\/a><\/div>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-dcdce2b4-a152-40a7-9d40-74a96c4f4e86\" href=\"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-content\/uploads\/2022\/10\/spin-cover-plate-motor-laser-cut.sldprt\">spin-cover-plate-motor-laser-cut<\/a><a href=\"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-content\/uploads\/2022\/10\/spin-cover-plate-motor-laser-cut.sldprt\" class=\"wp-block-file__button\" download aria-describedby=\"wp-block-file--media-dcdce2b4-a152-40a7-9d40-74a96c4f4e86\">Download<\/a><\/div>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-88aae95b-120e-42b0-bbba-dfdd31487d71\" href=\"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-content\/uploads\/2022\/10\/top-plate-motor-laser-cut.sldprt\">top-plate-motor-laser-cut<\/a><a href=\"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-content\/uploads\/2022\/10\/top-plate-motor-laser-cut.sldprt\" class=\"wp-block-file__button\" download aria-describedby=\"wp-block-file--media-88aae95b-120e-42b0-bbba-dfdd31487d71\">Download<\/a><\/div>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-532fabbc-4514-4dca-9098-68147dde9438\" href=\"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-content\/uploads\/2022\/10\/side-stand-motor-laser-cut.sldprt\">side-stand-motor-laser-cut<\/a><a href=\"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-content\/uploads\/2022\/10\/side-stand-motor-laser-cut.sldprt\" class=\"wp-block-file__button\" download aria-describedby=\"wp-block-file--media-532fabbc-4514-4dca-9098-68147dde9438\">Download<\/a><\/div>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-693d3518-3406-491d-b4c4-091a700ec52d\" href=\"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-content\/uploads\/2022\/10\/spinner-motor-laser-cut.sldprt\">spinner-motor-laser-cut<\/a><a href=\"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-content\/uploads\/2022\/10\/spinner-motor-laser-cut.sldprt\" class=\"wp-block-file__button\" download aria-describedby=\"wp-block-file--media-693d3518-3406-491d-b4c4-091a700ec52d\">Download<\/a><\/div>\n\n\n\n<p>Intent: the marble is placed at one end, it is moved by the spinner 180 degrees into the narrow path. The marble moves through the narrow path by the speed applied<\/p>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-9a320ded-76f8-4a7f-8e57-e5b6521a0a1d\" href=\"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-content\/uploads\/2022\/10\/IMG-8392.mov\">IMG-8392<\/a><a href=\"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-content\/uploads\/2022\/10\/IMG-8392.mov\" class=\"wp-block-file__button\" download aria-describedby=\"wp-block-file--media-9a320ded-76f8-4a7f-8e57-e5b6521a0a1d\">Download<\/a><\/div>\n\n\n\n<p>print(&#8220;Hello World!&#8221;)<\/p>\n\n\n\n<p>print(&#8220;Starting dual_spin script.&#8221;)<\/p>\n\n\n\n<p>import math, time<br>import board<br>import pwmio<\/p>\n\n\n\n<p>class DRV8833():<br>def <strong>init<\/strong>(self, AIN1=board.GP18, AIN2=board.GP19, BIN2=board.GP20, BIN1=board.GP21, pwm_rate=20000):<br># Create a pair of PWMOut objects for each motor channel.<br>self.ain1 = pwmio.PWMOut(AIN1, duty_cycle=0, frequency=pwm_rate)<br>self.ain2 = pwmio.PWMOut(AIN2, duty_cycle=0, frequency=pwm_rate)<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n    self.bin1 = pwmio.PWMOut(BIN1, duty_cycle=0, frequency=pwm_rate)\n    self.bin2 = pwmio.PWMOut(BIN2, duty_cycle=0, frequency=pwm_rate)\n\ndef write(self, channel, rate):\n    &quot;&quot;&quot;Set the speed and direction on a single motor channel.\n\n    :param channel:  0 for motor A, 1 for motor B\n    :param rate: modulation value between -1.0 and 1.0, full reverse to full forward.&quot;&quot;&quot;\n\n    # convert the rate into a 16-bit fixed point integer\n    pwm = min(max(int(2**16 * abs(rate)), 0), 65535)\n\n    if channel == 0:\n        if rate &lt; 0:\n            self.ain1.duty_cycle = pwm\n            self.ain2.duty_cycle = 0\n        else:\n            self.ain1.duty_cycle = 0\n            self.ain2.duty_cycle = pwm\n    else:\n        if rate &lt; 0:\n            self.bin1.duty_cycle = pwm\n            self.bin2.duty_cycle = 0\n        else:\n            self.bin1.duty_cycle = 0\n            self.bin2.duty_cycle = pwm\n<\/pre>\n\n\n<h1>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/h1>\n\n\n\n<h1>Create an object to represent a dual motor driver.<\/h1>\n\n\n\n<p>print(&#8220;Creating driver object.&#8221;)<br>driver = DRV8833()<\/p>\n\n\n\n<p>print(&#8220;Starting main script.&#8221;)<br>while True:<br># initial pause<br>time.sleep(2.0)<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nprint(&quot;Testing motor A.&quot;)\ndriver.write(0, 0.75)\ntime.sleep(2.0)\n\ndriver.write(0, 0.0)\ntime.sleep(2.0)\n\ndriver.write(0, 0.75)\ntime.sleep(2.0)\n\ndriver.write(0, 0.0)\ntime.sleep(2.0)\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>Intent: the marble is placed at one end, it is moved by the spinner 180 degrees into the narrow path. The marble moves through the narrow path by&#8230;<\/p>\n","protected":false},"author":56,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/posts\/5537"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/users\/56"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/comments?post=5537"}],"version-history":[{"count":1,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/posts\/5537\/revisions"}],"predecessor-version":[{"id":5544,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/posts\/5537\/revisions\/5544"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/media?parent=5537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/categories?post=5537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/tags?post=5537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}