Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Perl meets Real World

mackee
August 29, 2014

Perl meets Real World

YAPC::Asia 2014 2014-08-29 by @mackee_w

mackee

August 29, 2014
Tweet

More Decks by mackee

Other Decks in Programming

Transcript

  1. Perl meets Real World
    2014-08-29 YAPC::Asia 2014

    View full-size slide

  2. @mackee_w a.k.a Ϛίϐʔ
    • ໘ന๏ਓΧϠοΫ ٕज़෦
    • αʔόαΠυΤϯδχΞ(Perl)
    • ιʔγϟϧήʔϜͷ։ൃ/ӡ༻
    • ࠓ࡞͍ͬͯΔήʔϜ͸ࣄલొ࿥ड෇த

    View full-size slide

  3. WebΤϯδχΞ͕
    Կނϋʔυ΢ΣΞ͔ʁ

    View full-size slide

  4. ڈ೥গ͚ͩ͠ϋʔυ΢ΣΞͷ
    ࢓ࣄΛͨ͠
    • ઇࢁͰϥδίϯϔϦΛඈ͹͢࢓ࣄ
    • Webͷٕज़͔͠ແ͔ͬͨ
    • ௐ΂ͨΒ࠷ۙͷϋʔυ͸͍͢͜͝ͱʹͳͬ
    ͍ͯͨ

    View full-size slide

  5. ࢖ٕͬͨज़
    • RaspberryPi
    • Arduino
    • OpenCV
    • Ansible

    View full-size slide

  6. ϋʔυ΢ΣΞ
    શ෦ҰൠతʹೖखՄೳ

    View full-size slide

  7. ιϑτ΢ΣΞ
    “Web”ʹ΋௨ͣΔٕज़ͨͪ

    View full-size slide

  8. ۤ࿑΋͚͋ͬͨΕͲ
    ָ͔ͬͨ͠ͷͰ”ํ๏”ͷ
    Ұ෦Λ঺հ͠·͢

    View full-size slide

  9. ࠓ೔࿩͢͜ͱ
    • RaspberryPiͱArduino
    • Φʔϓϯιʔεϋʔυ΢ΣΞ
    • Perl͚ͩͰωΪΛৼΔ
    • ࣗ࡞ϋʔυ΢ΣΞͱະདྷ

    View full-size slide

  10. ࠓ೔࿩͞ͳ͍͜ͱ
    • ϋϯμ෇͚ʢձ৔͔Β͓ͦΒౖ͘ΒΕΔʣ
    • ճ࿏ઃܭʢཁ๬͕͋Ε͹ผͷػձʹʣ
    • ΨνͷArduinoʢ͍ͨΒ࠙਌ձͱ͔Ͱʣ
    • ͦͷଞΨνిࢠ޻࡞

    View full-size slide

  11. ୈҰষ
    Raspberry PiͱArduino

    View full-size slide

  12. Raspberry Pi
    http://commons.wikimedia.org/wiki/File:Raspberry_Pi_Photo.jpg

    View full-size slide

  13. • ARM 700MHz
    • 512MB RAM(Model B)
    • SD CARD
    • 100BASE-TX LAN
    • USB2.0 x 2
    • HDMI and RCA VIDEO
    • Audio
    • Power by USB

    View full-size slide

  14. Q. Ͱɺ͜ΕͰPerl͸ಈ͘ͷʁ

    View full-size slide

  15. A. ΋ͪΖΜಈ͖·͢ʂ

    View full-size slide

  16. ී௨ͷLinux͕ಈ͘
    • Raspbian (DebianͷRasPi޲͚ΧελϜ)
    • NOOBS(for beginner)
    • Pidora(FedoraͷRasPi޲͚ΧελϜ)

    View full-size slide

  17. ͦ΋ͦ΋ͷRasPiͷ໨త
    • খதֶੜ΍ൃల్্ࠃ޲͚ͷITڭҭ
    • RCAϏσΦδϟοΫ͕෇͍͍ͯΔͷ΋ൃల్্
    ࠃͷϒϥ΢ϯ؅ςϨϏͰ࢖͏ͨΊ
    • MinecraftͷRasPi൛ͱ͔΋͋ͬͯPythonͰΧελ
    ϚΠζͰ͖ͨΓ͢Δ

    View full-size slide

  18. kano
    ࢠڙ޲͚ͷΦʔϧΠϯϫϯͷPCΩοτ
    https://www.kickstarter.com/projects/alexklein/kano-a-computer-anyone-can-make

    View full-size slide

  19. ͔͠͠େਓ΋஫໨༷ͯ͠ʑͳ
    ϓϩδΣΫτ͕ڵͬͨ

    View full-size slide

  20. RaspberryPiΛ࢖ͬͨϓϩδΣΫτ

    View full-size slide

  21. Raspberry Pi͸
    Կނ஫໨/׆༻͞Ε͔ͨ

    View full-size slide

  22. ·͍͋ΖΜͳཧ༝͸͋Δ
    • ͍҆ (B/B+͕4000ԁఔ౓)
    • ΫϨδοτΧʔυαΠζ
    • ଞʹ΋طʹಉछͷ΋ͷ͸͋ͬͨ
    • ؀ڥ͕੔͍ͬͯΔ(ग़͕ࣗॳ৺ऀ޲͚)
    • ࡞ྫ͕ଟ͍

    View full-size slide

  23. GPIO - ݱ࣮ੈքʹհೖ͢ΔͨΊͷखஈ

    View full-size slide

  24. ిؾΛݟฉ͖͠ɺ͠Ό΂Δ
    • ϞʔλʔͳͲͷۦಈػثͷಈ࡞ -> ࢛ࢶ
    • ηϯαʔͰͷपғঢ়گͷݕ஌ -> ޒײ

    View full-size slide

  25. ిؾͱ͍͏࠷΋௿ϨΠϠʔΛ
    खܰʹѻ͑Δͷ͕RasPi

    View full-size slide

  26. Arduinoͷ࿩

    View full-size slide

  27. • ిؾΛѻ͏͜ͱʹಛԽ
    • 8bit ϚΠίϯΛ౥ࡌ
    • ॲཧೳྗ͸ඇৗʹখ͍͞
    • USB͸ೖྗઐ༻
    • ྫ֎΋͋Δ
    • LinuxͳͲ౸ఈಈ͔ͳ͍
    • ௚઀ϐϯΛૢ࡞͢Δ

    View full-size slide

  28. Q. Ͱɺ͜ΕͰPerl͸ಈ͘ͷʁ

    View full-size slide

  29. A. (‘A`) ಈ͔ͳ͍ɻɻɻ

    View full-size slide

  30. ϋʔυ΢ΣΞ୯ମͰ͸ඇྗ͕ͩ
    ΤίγεςϜ͕ڧྗ

    View full-size slide

  31. Arduino IDE
    Arduinoʹඞཁͳ΋ͷΛશͯ٧ΊࠐΜͩιϑτ΢ΣΞ

    View full-size slide

  32. γʔϧυ
    ਌ُࢠُํࣜͰ֦ு͢ΔΞλονϝϯτ

    View full-size slide

  33. ϥΠϒϥϦ΍ArduinoΛલఏͱͨ͠Ωοτ

    View full-size slide

  34. ๻͸͜͏࢖͍෼͚Δ

    View full-size slide

  35. RaspberryPiͰ΍Γ͍ͨ͜ͱ
    • ը૾ॲཧͱ͔Τϯίʔυͱ͔ॏ͍ͨॲཧ
    • ෳࡶͳΞϧΰϦζϜΛཁ͢Δ΋ͷ
    • PC޲͚ͷϥΠϒϥϦ͕͙͢ಈ͖΍͍͢
    • ௒؆୯ͳΦϯΦϑఔ౓ͷϋʔυ΢ΣΞ੍ޚ

    View full-size slide

  36. ArduinoͰ΍Γ͍ͨ͜ͱ
    • ࣗ࡞ͷిࢠ෦඼ͳͲͱ࿈ܞ͢Δέʔε
    • Arduino޲͚ϥΠϒϥϦ͕͢Ͱʹ͋Δ৔߹
    • PWM੍ޚͳͲͷߴ଎ʹΦϯɾΦϑΛ΍Δ৔߹
    • RasPiͩͱ͜͏͍͏͜ͱΛ΍ΔͱCPUΛΊͬ
    ͪΌ৯͏

    View full-size slide

  37. ීஈ͸2ͭΛ૊Έ߹ΘͤΔ͜ͱ
    ͕ଟ͍Ͱ͕͢ɺͦΕ͸ޙͷষͰ

    View full-size slide

  38. ୈೋষ
    Φʔϓϯϋʔυ΢ΣΞ

    View full-size slide

  39. ΦʔϓϯιʔεϥΠηϯε
    • ࣗ༝ͳ࠶൦෍͕Մೳ
    • ιʔείʔυ͕ೖखͰ͖Δ
    • ೿ੜ෺Λ࡞ͬͯ΋ྑ͍
    • ͦͷଞϥΠηϯε͕ܧঝ͞ΕΔͱ͔

    View full-size slide

  40. ϋʔυ΢ΣΞʹ͓͚Δ
    Φʔϓϯιʔεͱ͸

    View full-size slide

  41. ϋʔυ΢ΣΞͷιʔε
    • ϑΝʔϜ΢ΣΞ
    • ճ࿏ਤ
    • ෦඼৘ใ
    • ج൘഑ஔਤ

    View full-size slide

  42. Arduinoͷྫ

    View full-size slide

  43. ճ࿏ਤ(Arduino Unoͷ৔߹)
    http://arduino.cc/en/Main/ArduinoBoardUno

    View full-size slide

  44. ج൘഑ஔਤ΋Eagleͱ͍͏
    ճ࿏ਤ/ج൘ΤσΟλͷܗࣜͰ
    ൦෍͞Ε͍ͯΔ

    View full-size slide

  45. ͭ·Γ؆୯ʹArduinoΛ
    ࣗ࡞͢Δ͜ͱ͕ग़དྷΔ

    View full-size slide

  46. ݱʹΫϩʔϯ͕͍ͬͺ͍ଘࡏ͢Δ

    View full-size slide

  47. ArduinoΛࣗ࡞͢ΔϝϦοτ
    • ػೳͷ௥Ճ
    • Ϟʔλʔ੍ޚճ࿏Λ૊ΈࠐΉͱ͔
    • ϑοτϓϦϯτͷݮগ
    • ΊͬͪΌখ͍͞ػثʹੵΈ͍ͨ
    • ArduinoͷΤίγεςϜͷԸܙΛड͚ΒΕΔ

    View full-size slide

  48. ϋʔυΛΦʔϓϯʹ͢Δ͜ͱ
    • ϋοΫΛଅ͢
    • ΤίγεςϜ͕ൃల͠΍͍͢
    • ྲྀߦΔͱ໛଄඼͕ͨ͘͞Μग़ͯ͘Δ
    • Arduino΍RasPi͸໊લΛ࢖͏ͷΛϥΠη
    ϯεͰ੍ݶ͍ͯ͠Δ

    View full-size slide

  49. ΦʔϓϯʹͳΕ͹ϋʔυ΢ΣΞ
    Ͱ΋ϚογϡΞοϓ(ࢮޠ)
    ग़དྷΔͱ͍͏͜ͱͰ͢Ͷ

    View full-size slide

  50. ୈࡾষ
    Perl͚ͩͰωΪΛৼΔ

    View full-size slide

  51. ωΪΛৼΔͱ͸ʁʁʁ
    • ݩʑχίχίಈըͷॳԻϛΫಈըͰωΪΛ
    ৼΔ΋ͷ͕͋Δ
    • χίχίٕज़෦Ͱೖ໳ಈըͰΑ͘୊ࡐʹͳ
    Δ
    • ͍ΖΜͳ΋ͷͰωΪΛৼ͍ͬͯΔ

    View full-size slide

  52. ҎԼͷറΓͰ࡞Δ
    • ϋϯμ෇͚ͳ͠ ϒϨουϘʔυͳ͠
    • Arduinoݴޠ͸ॻ͔ͳ͍
    • Perl͸ॻ͘(YAPCͳͷͰ)

    View full-size slide

  53. ࡐྉ
    • Raspberry Pi Model B
    • Arduino Leonardo(Ոʹ͋ͬͨ)
    • GROVE System

    View full-size slide

  54. GROVE Systemͱ͸

    View full-size slide

  55. ͜͏͍͏ͪͬͪΌ͍෦඼͕͋ͬͯ

    View full-size slide

  56. ͜͏͍͏γʔϧυΛArduinoʹࡌ͚ͬͯ

    View full-size slide

  57. ͜Μͳ͔Μ͡Ͱͭͳ͛ͯ࢖͏

    View full-size slide

  58. ࢖͏ͨΊͷϥΠϒϥϦ΋طʹ
    ׬උ͞Ε͍ͯΔ

    View full-size slide

  59. Step 1
    Raspberry PiͱArduinoͰ
    ͓͠Ό΂Γ͢Δ

    View full-size slide

  60. Firmata͍ͬͯ͏ͷΛ࢖͍·͢
    • Firmata͸Arduinoͱ͔ͷϚΠίϯͱPCؒ
    Ͱ͓͠Ό΂Γ͢ΔͨΊͷϓϩτίϧ
    • ͓खܰಋೖՄೳ

    View full-size slide

  61. ࠓ౓͸FirmataͰLEDΛޫΒ͢

    View full-size slide

  62. PerlͰFirmataΛ͠Ό΂Δ

    View full-size slide

  63. ArduinoʹFirmataͷ
    εέονΛॻ͖ࠐΉ

    View full-size slide

  64. ϋʔυͷ΄͏ͷ४උ
    • ArduinoͱGROVE Base ShieldΛ઀ଓ
    • γʔϧυͷD4ʹLEDϞδϡʔϧΛ઀ଓ
    • ArduinoͱRaspberry PiΛͭͳ͛Δ

    View full-size slide

  65. Step 2
    αʔϘϞʔλΛ࢖͏

    View full-size slide

  66. GROVEͷαʔϘϞʔλ
    D3ʹͭͳ͍ͩ

    View full-size slide

  67. Step 3
    WebΞϓϦԽ͢Δ

    View full-size slide

  68. Amon2Ͱ࡞Δ

    View full-size slide

  69. WebΞϓϦͷػೳ
    • WebSocketͰ֯౓৘ใΛड৴
    • ͦͷ஋ΛRedisʹॻ͖ࠐΉ

    View full-size slide

  70. ผϓϩηεͷϫʔΧʔ
    • ແݶϧʔϓͰRedisͷ஋Λ؂ࢹ
    • มԽ͕͋Ε͹FirmataͰArduinoʹૹ৴

    View full-size slide

  71. ࠷ऴষ
    ࣗ࡞ϋʔυ΢ΣΞͱະདྷ

    View full-size slide

  72. ϋʔυ΢ΣΞΛࣗ෼Ͱ࡞ΕΔ
    ࣌୅͸࣮֬ʹདྷ͍ͯΔ
    • 3DϓϦϯλͱ͔ੲ͸ߟ͑ΒΕͳ͔ͬͨ
    • ᝑମΛ͔ͬ͜ྑ͘࡞Δ໰୊͕ૉૣ͘ղܾ
    • ϋʔυ΢ΣΞΛखചΓ͢Δ࣌୅ʹͳͬͨ
    • Make Fairͱ͔Ͷ

    View full-size slide

  73. IRKit
    http://getirkit.com/

    View full-size slide

  74. IRKit
    • த਎͸Arduinoޓ׵ج൘
    • ͢΂ͯΦʔϓϯ
    • ճ࿏ઃܭ΍ᝑମͷઃܭΛݸਓͰߦ͏

    View full-size slide

  75. ϋʔυ΢ΣΞΛ͕ͬͭΓ΍Β
    ͣʹ࡞ΕΔ࣌୅
    • ࣗ෼ͷख׳ΕͨݴޠͰهड़Ͱ͖Δ
    • ϋϯμ෇͚ෆཁ
    • εςοϓΞοϓ͢ΔͱϒϨουϘʔυ΍
    ϋϯμ෇͚͕ඞཁʹͳΔ͚ΕͲ

    View full-size slide

  76. ·ͩ·ͩ଍Γͳ͍͜ͱ
    (๻͕஌Βͳ͍͚͔ͩ΋)
    • ΤϯδχΞϦϯάͱͯ͠ͷ࢓૊ΈԽ
    • PerlͰݴ͏CPANΈ͍ͨͳ΍ͭ
    • ษڧձɺϫʔΫγϣοϓ
    • ςετ؀ڥ

    View full-size slide

  77. ϋʔυ΢ΣΞͳਓͱग़ձ͍͍ͨʂ
    • Webͷਓͱ͸Α͘ձ͏͚ΕͲɺ͜͏͍͏͜
    ͱ΍͍ͬͯΔਓͳ͔ͳ͔ग़ձΘͳ͍
    • ͍ͨΒ঺հͯ͠ཉ͍͠͠ɺ͋ͳ͕ͨͦ͏Ͱ
    ͋Ε͹༑ͩͪʹͳ͍ͬͯͩ͘͞

    View full-size slide

  78. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide

  79. ࣭ٙԠ౴΍
    ͕࣌ؒ༨ͬͨΒ΍Δ༻

    View full-size slide

  80. γϦΞϧΛແઢԽ
    • XBee/XBee WiFi΍ͦͷଞແઢLANϞδϡʔϧ
    • γϦΞϧΛZigBee΍WiFiʹม׵Ͱ͖Δ
    • ٕదʹ஫ҙ
    • ւ֎੡Ϟδϡʔϧ͸ి೾๏ͰҾ͔͔ͬΔͱ
    ͔͋Δ

    View full-size slide

  81. Raspberry Piઐ༻Χϝϥ
    • খ͍͍ͦͦ҆͜͜͞͠(2000ԁ୆)
    • ͨͩ͠RasPiઐ༻
    • RasPiΛϥΠϒΧϝϥͱ͔ʹग़དྷΔ
    • ϔϦͰ΋࢖͍·ͨ͠ʢখ͍͞͠USB৯Θͳ͍

    View full-size slide