{"id":4774,"date":"2021-03-25T10:24:21","date_gmt":"2021-03-25T14:24:21","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/?p=4774"},"modified":"2021-03-30T09:32:12","modified_gmt":"2021-03-30T13:32:12","slug":"assignment-14-elise-and-kanvi","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/4774\/assignment-14-elise-and-kanvi\/","title":{"rendered":"Assignment 14 &#8211; Elise and Kanvi"},"content":{"rendered":"\n<p>The mechanism for our flower involves a sine servo motion with green lights when at rest. The servo then reacts to a loud noise such as a snap if our test video as well as with a jolt in motion to close the flower. The Red LED lights turn on, and a high-pitched tone pursues for a second or two. After about 10 seconds, the servo returns back to its peaceful state.<\/p>\n\n\n\n<p>Our sketch describes the minimal mechanics and intended response outcomes. With a loud noise on Kanvi&#8217;s side, the motion of Elise&#8217;s motor would jolt towards a stop to close the petals or vice versa. The jolt with be the servo going back to starting position such that the tendons attached will overlap with the petals.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"768\" src=\"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-content\/uploads\/2021\/03\/IMG_4827-1024x768.jpg\" alt=\"\" class=\"wp-image-4777\" srcset=\"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-content\/uploads\/2021\/03\/IMG_4827-1024x768.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-content\/uploads\/2021\/03\/IMG_4827-300x225.jpg 300w, https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-content\/uploads\/2021\/03\/IMG_4827-768x576.jpg 768w, https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-content\/uploads\/2021\/03\/IMG_4827-1536x1152.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-content\/uploads\/2021\/03\/IMG_4827-2048x1536.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-content\/uploads\/2021\/03\/IMG_4827-973x730.jpg 973w, https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-content\/uploads\/2021\/03\/IMG_4827-508x381.jpg 508w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Proof-of-concept sketch<\/figcaption><\/figure>\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=\"IMG 4829\" width=\"620\" height=\"349\" src=\"https:\/\/www.youtube.com\/embed\/c7LuIrYKyNc?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><figcaption>The prototyped mechanism<\/figcaption><\/figure>\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=\"IMG 4830\" width=\"620\" height=\"349\" src=\"https:\/\/www.youtube.com\/embed\/CiznKgwVxpo?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><figcaption>Self-transmission to be tested with Kanvi<\/figcaption><\/figure>\n\n\n\n<p><em>Changes to be made in the future<\/em><\/p>\n\n\n\n<p>Right now, our code uses the &#8220;loud_noise&#8221; function provided in the cp library but this isn&#8217;t sensitive enough for our purpose. We will be working on finding the perfect sound level to make the reaction of the flower more meaningful. <\/p>\n\n\n\n<p>We also have not tested our code transmitting across the mqtt bridge but it works with Elise&#8217;s transmitting to self.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><code><em><span class=\"has-inline-color has-black-color\">import time\nimport math\nimport board\nimport pwmio\nfrom adafruit_circuitplayground import cp\nfrom adafruit_motor import servo\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=1000, max_pulse=2000)\n\nphase_angle = 0.0\nphase_rate  = 2*math.pi \/ 6.0  # one cycle per six seconds, in radians\/second\nnext_servo_update = time.monotonic_ns()\nnext_status_update = time.monotonic_ns()\n\nwhile True:\n    now = time.monotonic_ns()\n    \n    if cp.loud_sound():\n        actuator.angle = 0\n        cp.pixels.fill((255, 0, 0))\n        cp.play_tone(1000,.2)\n        cp.play_tone(1200, .2)\n        cp.play_tone(1400, .2)\n        time.sleep(10)\n\n    elif now &gt;= next_servo_update:\n        cp.pixels.fill((0, 255, 0))\n        next_servo_update += 20000000  # 20 msec in nanoseconds (50 Hz update)\n        actuator.angle = 90 + 90 * math.sin(phase_angle)\n        phase_angle += phase_rate * 0.020\n\n    # If the time has arrived to display the status:\n    if now &gt;= next_status_update:\n        next_status_update += 500000000  # 0.5 sec in nanoseconds (2 Hz update)\n        print(actuator.angle)<\/span><\/em><\/code><\/strong><\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The mechanism for our flower involves a sine servo motion with green lights when at rest. The servo then reacts to a loud noise such as a snap&#8230;<\/p>\n","protected":false},"author":84,"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\/4774"}],"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\/84"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/comments?post=4774"}],"version-history":[{"count":11,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/posts\/4774\/revisions"}],"predecessor-version":[{"id":4821,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/posts\/4774\/revisions\/4821"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/media?parent=4774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/categories?post=4774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2021\/wp-json\/wp\/v2\/tags?post=4774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}