{"id":4914,"date":"2021-04-05T22:00:02","date_gmt":"2021-04-06T02:00:02","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/?p=4914"},"modified":"2021-04-05T22:00:03","modified_gmt":"2021-04-06T02:00:03","slug":"assignment-17-team-pom-pom-%f0%9f%94%a5","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/4914\/assignment-17-team-pom-pom-%f0%9f%94%a5\/","title":{"rendered":"Assignment 17: Team Pom Pom \ud83d\udd25"},"content":{"rendered":"\n<p><strong>Synopsis <\/strong><\/p>\n\n\n\n<p>For this assignment Team Pom Pom tested how the microcontroller&#8217;s movement while attached to the chair affected the wind chimes. It was a great success! When Helen moved her chair and sat in it the small movements triggered the wind chimes to move in a slow and jolted motion. When Helen moved her hair from side to side at a faster pace, the wind chime spun around faster in a smooth and controlled spin cycle. <\/p>\n\n\n\n<p><strong>Video Demo<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"MQTT Test Run! \ud83c\udfc3\u200d\u2640\ufe0f\" width=\"620\" height=\"349\" src=\"https:\/\/www.youtube.com\/embed\/ENHQ1TP0SOs?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><figcaption>Testing the movements of the chair through MQTT and how it affects the wind chimes. <\/figcaption><\/figure>\n\n\n\n<p><strong>Code<\/strong><\/p>\n\n\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&quot;&quot;&quot;\nProject 1: Ambient Proxy Body\n\nTeam Pom Pom\nHelen Yu (heleny1), Celia Kasberg (ckasberg), Elle Smith\n\nWritten by Helen Yu\nLast Updated: 3\/28\/21\n\nSummary: As your partner fidgets in their chair, your wind chimes spin\nin reaction to your partner's presence. Small and slow movements trigger\na sweeping motion in the servo. Fast and sharp movements trigger a stepping\nsweep in the servo.\n\nInputs: Accelerometer\nOutputs: Hobby Servo on SD A5\n&quot;&quot;&quot;\n\n# ----------------------------------------------------------------\n# Import any needed standard Python modules.\nimport time, math, sys\n\n# Import the board-specific input\/output library.\nfrom adafruit_circuitplayground import cp\n\n# Import the low-level hardware libraries.\nimport board\nimport digitalio\nimport analogio\nimport pwmio\n\n# Import the Adafruit helper library.\nfrom adafruit_motor import servo\n\n# Import the runtime for checking serial port status.\nimport supervisor\n\n# ----------------------------------------------------------------\n# Initialize hardware.\n\n# Create a PWMOut object on pad SDA A5 to generate control signals.\npwm = pwmio.PWMOut(board.A5, duty_cycle=0, frequency=50)\n\n# Create a Servo object which controls a hobby servo using the PWMOut.\nactuator = servo.Servo(pwm, min_pulse=50, max_pulse=3000)\n\n# ----------------------------------------------------------------\n# Initialize global variables for the main loop.\n\n# The remote move state can be updated via serial port messages.\nremote_moves = [0, 0, 0, 0, 0]\n\n# Measure the time since the last remote move message, and reset after a period without data.\nremote_moves_timer = False\n\n# Convenient time constant expressed in nanoseconds.\nsecond = 1000000000\n\n# Integer time stamp for the next console output.\nsensing_timer = time.monotonic()\n\n# Integer time stamp for next behavior activity to begin.\nnext_activity_time = time.monotonic_ns() + 2 * second\n\n# Flag to trigger motion.\nsweep_slow = False\nsweep_fast = False\n\nphase_angle = 0.0\nphase_rate  = 2*math.pi \/ 6.0  # one cycle per six seconds, in radians\/second\n\n# Integer time stamp for next servo update.\nnext_servo_update = time.monotonic_ns()\n\n# The serial port output rate is regulated using the following timer variables.\nserial_timer    = 0.0\nserial_interval = 0.5\n\n# ----------------------------------------------------------------\n# Begin the main processing loop.\nwhile True:\n\n    # Read the current integer clock.\n    now = time.monotonic()\n\n    # Measure and define local acceleration\n    x, y, z = cp.acceleration\n    l_x = abs(int(x))\n    l_y = abs(int(y))\n    l_z = abs(int(z))\n    local_moves = l_x, l_y, l_z\n\n    # Check the serial input for new line of remote data\n    if supervisor.runtime.serial_bytes_available:\n        line = sys.stdin.readline()\n        tokens = line.split()\n        if len(tokens) == 5:\n            try:\n                remote_moves = [int(token) &amp;gt; 0 for token in tokens]\n                remote_move_timer = 4.0\n            except ValueError:\n                pass\n\n    #---- periodic console output -----------------------------------\n    # Poll the time stamp to decide whether to emit console output.\n    if now &amp;gt;= sensing_timer:\n        sensing_timer += 100000000 #0.1sec\n\n    if any(local_moves):\n        remote_moves_timer = now + 4000000000 # 4 sec timeout\n\n    if now &amp;gt;= serial_timer:\n        serial_timer += serial_interval\n        moves = [&quot;1&quot; if 1 &lt; l_x &lt; 3 else &quot;0&quot;, &quot;1&quot; if l_y &amp;gt; 1 else &quot;0&quot;, &quot;1&quot; if 1 &lt; l_z &lt; 3 else &quot;0&quot;, &quot;1&quot; if l_x &amp;gt; 3 else &quot;0&quot;, &quot;1&quot; if l_z &amp;gt; 3 else &quot;0&quot;]\n        print(&quot; &quot;.join(moves))\n\n    # If a slow movement has been received, sweep twice at a constant speed\n    if sweep_slow is True:\n        for angle in range(0, 180, 5):\n            actuator.angle = angle\n            time.sleep(0.02)\n        print(&quot;Reversing slow sweep.&quot;)\n        for angle in range(180, 0, -5):\n            actuator.angle = angle\n            time.sleep(0.02)\n        print(&quot;End of slow cycle&quot;)\n        sweep_slow = False\n\n    # If a fast movement has been received, sweep twice in a stepping motion\n    if sweep_fast is True:\n        for angle in range(0, 180, 10):\n            actuator.angle = angle\n            time.sleep(0.2)\n        print(&quot;Reversing fast sweep.&quot;)\n        for angle in range(180, 0, -10):\n            actuator.angle = angle\n            time.sleep(0.2)\n        print(&quot;End of fast cycle&quot;)\n        sweep_fast = False\n\n    if any(remote_moves):\n        # Check whether there was any remote movement\n        if remote_moves[0] or remote_moves[2]:\n            if remote_moves[1]:\n                sweep_slow = True\n                print(&quot;Entering slow cycle.&quot;)\n\n        if remote_moves[3] or remote_moves[4]:\n            if remote_moves[1]:\n                sweep_fast = True\n                print(&quot;Entering fast cycle&quot;)\n\n        remote_moves = [False]*5\n\n    #---- periodic servo motion commands ----------------------------\n    # If the time has arrived to update the servo command signal:\n    if now &amp;gt;= next_servo_update:\n        next_servo_update += 20000000  # 20 msec in nanoseconds (50 Hz update)\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>Synopsis For this assignment Team Pom Pom tested how the microcontroller&#8217;s movement while attached to the chair affected the wind chimes. It was a great success! When Helen&#8230;<\/p>\n","protected":false},"author":77,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/posts\/4914"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/comments?post=4914"}],"version-history":[{"count":8,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/posts\/4914\/revisions"}],"predecessor-version":[{"id":4924,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/posts\/4914\/revisions\/4924"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/media?parent=4914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/categories?post=4914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/tags?post=4914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}