SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
Open the door of embedded systems to IoT (the Internet of things)! 
mruby on LEGO Mindstorms EV3 ® 
Takehiko YOSHIDA 
@chihayafuru
Agenda 
Self-introduction 
What's LEGO Mindstorms 
◦Standard Programming Environment 
◦Extended Programming Environment (ev3dev) 
Can we use mruby in embedded systems? 
◦Example of a light sensor for Mindstorms RCX 
◦APIs for EV3s color sensor implemented with mruby 
Concluding Remarks 
Demonstration of the "RUBY JINJA"
Self-introduction 
I'm from Matsumoto city, Nagano. 
I work in a manufacturer of information- related equipment as a programmer. 
Takehiko YOSHIDA 
@chihayafuru
A hierarchy of 
a Japanese manufacturing industry 
Samurai 
Farmer 
Artisan 
Trader 
Mechanical Engineer 
Electrical Engineer 
Software Engineer
What's LEGO Mindstorms 
Educational Tool>Toy 
STEM education 
◦Science 
◦Technology 
◦Engineering 
◦Mathematics
History of LEGO Mindstorms 
1st gen. 
MindstormsRCX 
2nd gen. 
MindstormsNXT 
3rd gen. 
Mindstorms EV3 
ReleaseDATE 
1998 
2006 
2013 
CPU 
H816MHz 
ARM7 
48 MHz 
ARM9 
300 MHz 
RAM 
32 KB 
64 KB 
16 MB
Standard Firmware Architecture 
OS (Linux) 
System 
Program 
Device driver (kernel module) 
VM (Virtual Machine) 
User 
Program 
Direct 
Command
Extended Firmware 
ev3dev 
◦full Debian 7 (wheezy) Linux Distribution. 
◦customized for the LEGO MINDSTORM EV3 controller. 
◦Bootable from microSD/SDHC card 
Available Programming Language 
C / C++ 
Python 
JavaScript (Node.js) 
Lua 
Go 
Ruby
What's mruby ? 
mruby is the lightweight implementation of Ruby language complying to (part of) the ISO standard. Its syntax is Ruby 1.9 compatible. 
mruby can be linked and embedded into your application. 
https://github.com/mruby/mruby
Can we use "mruby" in embedded systems ? 
Real-time constraint 
•Can mruby meet the deadline ? 
•A process of GC (Garbage Collection) deactivate other interrupts.
An example of a light sensor for1st gen. Mindstorms RCX 
LED Light 
Photo Detector
Circuit diagram of general light sensor 
Signal 
Power 
Common 
Out 
In 
LED 
Photodiode 
(Photo Detector)
Connector of Mindstorms RCX
Circuit diagram of the RCX’s light sensor 
Signal 
Power 
Common 
Out 
In
Waveforms of a signal voltage from the Light Sensor for RCX 
Oscilloscope 
reflected light is strong 
reflected light is weak
delay of programmed cycle
Color Sensor API with mruby for Mindstorms EV3
Initializer of Color sensor 
Ev3Color.new(port) 
port : "in1", "in2", "in3" , "in4"
Connector of Mindstorms EV3
3 modes of Color Sensor 
Ev3Color#mode=(mode) 
EV3Color.Mode.COL-REFLECT 
EV3Color.Mode.COL-AMBIENT 
EV3Color.Mode.RGB-RAW
Evolution of Mindstorms 
Intelligent 
Brick 
Light 
Sensor 
1st gen. 
Mindstorms RCX 
2nd gen. 
Mindstorms NXT 
3rd gen. 
Mindstorms EV3 
ANALOG 
ANALOG 
DIGITAL
Concluding Remarks 
What is mruby suitable for ? 
What is mruby NOT suitable for ?
What is mruby NOT suitable for ? 
Reaching a hardware limit under software control. 
Be willing to work in the background of mechanics and electronics, and struggle with C/C++, assembly language.
What is mrubysuitable for ? 
High-functional / Multi-functional electric devices 
Newly-developed Cloud servicesCreating new value with mashup technology
References 
LEGO Mindstorms® 
http://www.lego.com/en-us/mindstorms/ 
ev3dev 
http://www.ev3dev.org/ 
mruby 
https://github.com/mruby/mruby 
mruby-ev3dev 
https://github.com/chihayafuru/mruby-ev3dev

Más contenido relacionado

Destacado

Implementing HDF5 in MATLAB
Implementing HDF5 in MATLABImplementing HDF5 in MATLAB
Implementing HDF5 in MATLAB
The HDF-EOS Tools and Information Center
 
Implementation of Wireless Channel Model in MATLAB: Simplified
Implementation of Wireless Channel Model in MATLAB: SimplifiedImplementation of Wireless Channel Model in MATLAB: Simplified
Implementation of Wireless Channel Model in MATLAB: Simplified
Rosdiadee Nordin
 
Simulation of A Communications System Using Matlab
Simulation of A Communications System Using MatlabSimulation of A Communications System Using Matlab
Simulation of A Communications System Using Matlab
Polytechnique Montreal
 

Destacado (20)

SPQUE Hoverboard
SPQUE Hoverboard SPQUE Hoverboard
SPQUE Hoverboard
 
RubyKaigi 2014: ServerEngine
RubyKaigi 2014: ServerEngineRubyKaigi 2014: ServerEngine
RubyKaigi 2014: ServerEngine
 
Summer Camp brochure 2017
Summer Camp brochure 2017Summer Camp brochure 2017
Summer Camp brochure 2017
 
"Tomorrow ASEAN Project" Information Booklet (Season 1) - AIESEC in Ho Chi Mi...
"Tomorrow ASEAN Project" Information Booklet (Season 1) - AIESEC in Ho Chi Mi..."Tomorrow ASEAN Project" Information Booklet (Season 1) - AIESEC in Ho Chi Mi...
"Tomorrow ASEAN Project" Information Booklet (Season 1) - AIESEC in Ho Chi Mi...
 
Digital Innovation in Vietnam: is it possible?
Digital Innovation in Vietnam: is it possible?Digital Innovation in Vietnam: is it possible?
Digital Innovation in Vietnam: is it possible?
 
2017 TeenLife Guide to Overnight Summer Programs
2017 TeenLife Guide to Overnight Summer Programs2017 TeenLife Guide to Overnight Summer Programs
2017 TeenLife Guide to Overnight Summer Programs
 
Mathworks case example
Mathworks case exampleMathworks case example
Mathworks case example
 
Industrial projects 2017 by tciap
Industrial projects 2017 by tciap Industrial projects 2017 by tciap
Industrial projects 2017 by tciap
 
組込みシステムでIoTへの扉を開こう! mruby on LEGO Mindstorms EV3 (R)
組込みシステムでIoTへの扉を開こう! mruby on LEGO Mindstorms EV3 (R)組込みシステムでIoTへの扉を開こう! mruby on LEGO Mindstorms EV3 (R)
組込みシステムでIoTへの扉を開こう! mruby on LEGO Mindstorms EV3 (R)
 
Noise detection from the signal matlab code, Signal Diagnosis
Noise detection from the signal matlab code, Signal Diagnosis Noise detection from the signal matlab code, Signal Diagnosis
Noise detection from the signal matlab code, Signal Diagnosis
 
Implementing HDF5 in MATLAB
Implementing HDF5 in MATLABImplementing HDF5 in MATLAB
Implementing HDF5 in MATLAB
 
2017 Project Management Workshop Schedule - Project Management Training - Dco...
2017 Project Management Workshop Schedule - Project Management Training - Dco...2017 Project Management Workshop Schedule - Project Management Training - Dco...
2017 Project Management Workshop Schedule - Project Management Training - Dco...
 
TEEN Online Best Practices 2017
TEEN Online Best Practices 2017TEEN Online Best Practices 2017
TEEN Online Best Practices 2017
 
Dsp lab report- Analysis and classification of EMG signal using MATLAB.
Dsp lab report- Analysis and classification of EMG signal using MATLAB.Dsp lab report- Analysis and classification of EMG signal using MATLAB.
Dsp lab report- Analysis and classification of EMG signal using MATLAB.
 
A2 Exam Project, 2017 Homework B
A2 Exam Project, 2017 Homework BA2 Exam Project, 2017 Homework B
A2 Exam Project, 2017 Homework B
 
Implementation of Wireless Channel Model in MATLAB: Simplified
Implementation of Wireless Channel Model in MATLAB: SimplifiedImplementation of Wireless Channel Model in MATLAB: Simplified
Implementation of Wireless Channel Model in MATLAB: Simplified
 
GCSE FIne Art, Exam project 2017, Beginning and/or end, Lessons
GCSE FIne Art, Exam project 2017, Beginning and/or end, LessonsGCSE FIne Art, Exam project 2017, Beginning and/or end, Lessons
GCSE FIne Art, Exam project 2017, Beginning and/or end, Lessons
 
Hovercraft seminar report
Hovercraft seminar report Hovercraft seminar report
Hovercraft seminar report
 
Simulation of A Communications System Using Matlab
Simulation of A Communications System Using MatlabSimulation of A Communications System Using Matlab
Simulation of A Communications System Using Matlab
 
MATLAB and Simulink for Communications System Design (Design Conference 2013)
MATLAB and Simulink for Communications System Design (Design Conference 2013)MATLAB and Simulink for Communications System Design (Design Conference 2013)
MATLAB and Simulink for Communications System Design (Design Conference 2013)
 

Similar a Open the door of embedded systems to IoT! mruby on LEGO Mindstorms (R)

Cpqd's SDN activities in optical dwdm terabit networks
Cpqd's SDN activities in optical dwdm terabit networksCpqd's SDN activities in optical dwdm terabit networks
Cpqd's SDN activities in optical dwdm terabit networks
CPqD
 
7380969 Line Follower Using At89c51
7380969 Line Follower Using At89c517380969 Line Follower Using At89c51
7380969 Line Follower Using At89c51
biharimukund
 
Minor project report on
Minor project report on Minor project report on
Minor project report on
Arindam Paul
 

Similar a Open the door of embedded systems to IoT! mruby on LEGO Mindstorms (R) (20)

Autonomous robotics based on simple sensor inputs.
Autonomous robotics based on simplesensor inputs.Autonomous robotics based on simplesensor inputs.
Autonomous robotics based on simple sensor inputs.
 
Integrative detection of Human, Object movement and Fire Sensing Using LoRaWA...
Integrative detection of Human, Object movement and Fire Sensing Using LoRaWA...Integrative detection of Human, Object movement and Fire Sensing Using LoRaWA...
Integrative detection of Human, Object movement and Fire Sensing Using LoRaWA...
 
Elektor 0304-2020
Elektor 0304-2020Elektor 0304-2020
Elektor 0304-2020
 
Hard IP Core design | Convolution Encoder
Hard IP Core design | Convolution EncoderHard IP Core design | Convolution Encoder
Hard IP Core design | Convolution Encoder
 
Cpqd's SDN activities in optical dwdm terabit networks
Cpqd's SDN activities in optical dwdm terabit networksCpqd's SDN activities in optical dwdm terabit networks
Cpqd's SDN activities in optical dwdm terabit networks
 
An_Introduction_to_Microcontrollers.pptx
An_Introduction_to_Microcontrollers.pptxAn_Introduction_to_Microcontrollers.pptx
An_Introduction_to_Microcontrollers.pptx
 
7380969 Line Follower Using At89c51
7380969 Line Follower Using At89c517380969 Line Follower Using At89c51
7380969 Line Follower Using At89c51
 
TASSA-X
TASSA-XTASSA-X
TASSA-X
 
Line following robot
Line following robotLine following robot
Line following robot
 
Intro_to_Arduino_-_v30.pptx
Intro_to_Arduino_-_v30.pptxIntro_to_Arduino_-_v30.pptx
Intro_to_Arduino_-_v30.pptx
 
IRJET - Zigbee based Street Light Control System
IRJET - Zigbee based Street Light Control SystemIRJET - Zigbee based Street Light Control System
IRJET - Zigbee based Street Light Control System
 
Minor project report on
Minor project report on Minor project report on
Minor project report on
 
gesture
gesturegesture
gesture
 
DIGITAL IC TESTER USING UNIVERSAL GATES.pptx
DIGITAL IC TESTER USING UNIVERSAL GATES.pptxDIGITAL IC TESTER USING UNIVERSAL GATES.pptx
DIGITAL IC TESTER USING UNIVERSAL GATES.pptx
 
RF Controlled Robot Using Advanced Sensors
RF Controlled Robot Using Advanced SensorsRF Controlled Robot Using Advanced Sensors
RF Controlled Robot Using Advanced Sensors
 
IRJET- Autonomous Underwater Vehicle: Electronics and Software Implementation...
IRJET- Autonomous Underwater Vehicle: Electronics and Software Implementation...IRJET- Autonomous Underwater Vehicle: Electronics and Software Implementation...
IRJET- Autonomous Underwater Vehicle: Electronics and Software Implementation...
 
Embedded system
Embedded systemEmbedded system
Embedded system
 
Obstacle Detection Robot
Obstacle Detection RobotObstacle Detection Robot
Obstacle Detection Robot
 
micro-ROS goes easy: Developing professional applications using Eclipse based...
micro-ROS goes easy: Developing professional applications using Eclipse based...micro-ROS goes easy: Developing professional applications using Eclipse based...
micro-ROS goes easy: Developing professional applications using Eclipse based...
 
TheThingsConference 2019 Slides of Alex Raimondi
TheThingsConference 2019 Slides of Alex RaimondiTheThingsConference 2019 Slides of Alex Raimondi
TheThingsConference 2019 Slides of Alex Raimondi
 

Más de Takehiko YOSHIDA (6)

かるがもヘルメット/スキースクールIoTシステム
かるがもヘルメット/スキースクールIoTシステムかるがもヘルメット/スキースクールIoTシステム
かるがもヘルメット/スキースクールIoTシステム
 
RICOH THETAの全天球画像でペーパークラフト作成
RICOH THETAの全天球画像でペーパークラフト作成RICOH THETAの全天球画像でペーパークラフト作成
RICOH THETAの全天球画像でペーパークラフト作成
 
RICOH THETAの全天球画像でペーパークラフト
RICOH THETAの全天球画像でペーパークラフトRICOH THETAの全天球画像でペーパークラフト
RICOH THETAの全天球画像でペーパークラフト
 
Mindstorms EV3におけるソフトウェア開発環境 2014年 師走版
Mindstorms EV3におけるソフトウェア開発環境 2014年 師走版Mindstorms EV3におけるソフトウェア開発環境 2014年 師走版
Mindstorms EV3におけるソフトウェア開発環境 2014年 師走版
 
恋するクラウド ~ AWSへ個人ブログをお引っ越し ~
恋するクラウド ~ AWSへ個人ブログをお引っ越し ~恋するクラウド ~ AWSへ個人ブログをお引っ越し ~
恋するクラウド ~ AWSへ個人ブログをお引っ越し ~
 
ロボット組み立てのヒント ハイライト
ロボット組み立てのヒント ハイライトロボット組み立てのヒント ハイライト
ロボット組み立てのヒント ハイライト
 

Último

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

Open the door of embedded systems to IoT! mruby on LEGO Mindstorms (R)

  • 1. Open the door of embedded systems to IoT (the Internet of things)! mruby on LEGO Mindstorms EV3 ® Takehiko YOSHIDA @chihayafuru
  • 2. Agenda Self-introduction What's LEGO Mindstorms ◦Standard Programming Environment ◦Extended Programming Environment (ev3dev) Can we use mruby in embedded systems? ◦Example of a light sensor for Mindstorms RCX ◦APIs for EV3s color sensor implemented with mruby Concluding Remarks Demonstration of the "RUBY JINJA"
  • 3. Self-introduction I'm from Matsumoto city, Nagano. I work in a manufacturer of information- related equipment as a programmer. Takehiko YOSHIDA @chihayafuru
  • 4. A hierarchy of a Japanese manufacturing industry Samurai Farmer Artisan Trader Mechanical Engineer Electrical Engineer Software Engineer
  • 5. What's LEGO Mindstorms Educational Tool>Toy STEM education ◦Science ◦Technology ◦Engineering ◦Mathematics
  • 6. History of LEGO Mindstorms 1st gen. MindstormsRCX 2nd gen. MindstormsNXT 3rd gen. Mindstorms EV3 ReleaseDATE 1998 2006 2013 CPU H816MHz ARM7 48 MHz ARM9 300 MHz RAM 32 KB 64 KB 16 MB
  • 7. Standard Firmware Architecture OS (Linux) System Program Device driver (kernel module) VM (Virtual Machine) User Program Direct Command
  • 8. Extended Firmware ev3dev ◦full Debian 7 (wheezy) Linux Distribution. ◦customized for the LEGO MINDSTORM EV3 controller. ◦Bootable from microSD/SDHC card Available Programming Language C / C++ Python JavaScript (Node.js) Lua Go Ruby
  • 9. What's mruby ? mruby is the lightweight implementation of Ruby language complying to (part of) the ISO standard. Its syntax is Ruby 1.9 compatible. mruby can be linked and embedded into your application. https://github.com/mruby/mruby
  • 10. Can we use "mruby" in embedded systems ? Real-time constraint •Can mruby meet the deadline ? •A process of GC (Garbage Collection) deactivate other interrupts.
  • 11. An example of a light sensor for1st gen. Mindstorms RCX LED Light Photo Detector
  • 12. Circuit diagram of general light sensor Signal Power Common Out In LED Photodiode (Photo Detector)
  • 14. Circuit diagram of the RCX’s light sensor Signal Power Common Out In
  • 15. Waveforms of a signal voltage from the Light Sensor for RCX Oscilloscope reflected light is strong reflected light is weak
  • 17. Color Sensor API with mruby for Mindstorms EV3
  • 18. Initializer of Color sensor Ev3Color.new(port) port : "in1", "in2", "in3" , "in4"
  • 20. 3 modes of Color Sensor Ev3Color#mode=(mode) EV3Color.Mode.COL-REFLECT EV3Color.Mode.COL-AMBIENT EV3Color.Mode.RGB-RAW
  • 21. Evolution of Mindstorms Intelligent Brick Light Sensor 1st gen. Mindstorms RCX 2nd gen. Mindstorms NXT 3rd gen. Mindstorms EV3 ANALOG ANALOG DIGITAL
  • 22. Concluding Remarks What is mruby suitable for ? What is mruby NOT suitable for ?
  • 23. What is mruby NOT suitable for ? Reaching a hardware limit under software control. Be willing to work in the background of mechanics and electronics, and struggle with C/C++, assembly language.
  • 24. What is mrubysuitable for ? High-functional / Multi-functional electric devices Newly-developed Cloud servicesCreating new value with mashup technology
  • 25. References LEGO Mindstorms® http://www.lego.com/en-us/mindstorms/ ev3dev http://www.ev3dev.org/ mruby https://github.com/mruby/mruby mruby-ev3dev https://github.com/chihayafuru/mruby-ev3dev

Notas del editor

  1. "IoT" : Internet of Things (日常的ないろいろなモノをインターネットでつなげる技術)
  2. アジェンダ 自己紹介 LEGO Mindstormsとは 組み込みシステムにmrubyを使うことができるか? 初代 Mindstorms RCX の光センサーを例に組み込みシステムのプログラムに求められる能力を説明 今回、三代目 Mindstorms EV3 をターゲットにmruby-ev3devのAPI実装例 まとめ mrubyが向く分野、向かない分野 RUBY JINJA のデモ
  3. 長野県松本市からやってきました。 某プリンターメーカーにてプログラマーとして働いています。
  4. 『士農工商・メカ・エレキ・ソフト』 メーカーのソフトウェア開発者たちが自分たちのことを卑下した言葉です。 お客さんの手元に届くまでのリードタイムが一番長いのがメカ(機械)、次がエレキ(電気)、もっとも短いのがソフト。この言葉には色々な意味が込められていますが、製品開発の一番下流にソフトウェア開発が位置していることも理由の一つに挙げられるでしょう。 たとえば、ハードウェアのボタンの色を一旦図面が承認されたあとで変えるなんて言語道断でしょう。LEDの色を変更するのも部品発注後でははお手上げ。でしかしソフトウェアで実現するボタンの色であれば、お客さんの手元に届く前日でも仕様変更可です。 なので製品開発期間に終盤でみつかった不具合の尻拭いをソフトウェア開発者が担わされる、というような悲哀をしばしば耳にするとかしないとか。 このテーマが後半、ハードウェアとソフトウェアの関係を説明の伏線となっていますが、ひとまず日頃の愚痴はここまでにしておきます。
  5. レゴを皆さん知っていますか? みなさんの中には子供の頃にレゴブロック(LEGO Brick)で遊んだことのあるかたも大勢いると思います。 LEGO Mindstormsは、デンマークのレゴ社が発売している知育玩具製品です。 ブロック(Brick)やビーム(Beam)、シャフト(Shaft)と呼ばれる部品を組み合わせて思い思いの作品を作ることができます。 そして、その作品にモーターやセンサーを組み合わせて、さらにプログラムを組み込んでで様々な動きをするロボットを作ることができます。 右下の写真は私がMindstorms EV3で制作したLine Traceロボットです。 写真ではわかりにくいですが、左右の黒い部分がゴムでできたキャタピラーです。このキャタピラーで前後左右に動きます。 また、このロボットには黒い線を検知するセンサーがついていて、プログラムの働きによりリモコンではなく自律的に黒い線を辿って進むことができます。
  6. Mindstorms製品の歴史をたどります。 一番左の列がマインドストームの初代製品 Mindstorms RCX です。1998年に発売されました。 一番右の列が昨年発売された三代目となる最新製品 Mindstorms EV3 です。昨年2013年の秋に発売されました。 初代 iPhone は2007年の発売ですがずいぶん昔に現役を引退していますね。しかし2代目のNXTはまだまだ現役で多くの学校や企業で教育用に活躍していますし、初代のRCXだってまだまだ現役でつかっているところがあります。 ドッグイヤーと呼ばれるIT分野の製品としては長い商品サイクルをもった製品です。 それでも、初代の製品から15年でCPUのクロック(Clock)性能は20倍弱。RAMのサイズに至っては500倍強に性能アップしています。 ちなみに初代RCXに乗っていたCPUは当時の日立製作所(現在のルネサスエレクトロニクス社)の日本製マイコンでした。 そして15年後の現在は日本の半導体メーカーに過去の勢いが失われ海外製品が席巻していて時代を感じます。 3代目 EV3 に搭載されているマイコンはARMアーキテクチャ、Texas Insturuments社(TI社)製です。
  7. 標準ファームウェア、製品にあらかじめ組み込まれて出荷されているファームウェアのアーキテクチャです。 「ファームウェア」とはデジタルカメラなどの機器にあらかじめ搭載されているプログラムのことをいいます。 "firm"というのは堅い、堅牢なという意味ですから、堅いソフトウェアという、ちょっとアンビバレントな用語です。でもハードウェアと密接な関係を持つソフトウェアということで堅い"firm"という呼び名は言いえて妙かもしれません。 EV3本体に搭載されている標準ファームウェアにはLinuxが搭載されています。 Linux上でVM(Virtual Machine)が常駐し、ユーザーがPCで作成したプログラムを実行したり、スマホなどから送られていくるリモコン命令(Direct Command)を解釈して実行します。 Mindstorms EV3の製品に組み込まれているファームウェア(Firmware)はGithubにてGPL(Gnu General Public License)で公開されています。 システムプログラムの一部も、このVMが解釈できるバイトコード(Bytecode)で記述されています。 製品のファームウェアがGithubで公開されるようになった、という部分にも時代を感じます。 初代のRCXではファームウェアもハードウェアも非公開でしたが、ハッカーたちが解析して自由にソフトウェアを公開し製品の人気に一役買いました。 そのことを教訓にしたレゴ社は二代目のNXTではファームウェアのソースコードとハードウェアの回路図を公開しハッカーが自由な開発ができるように後押ししました。 そして三代目ではgithubでファームウェアのバージョンアップ過程も公開するようになりました。
  8. 標準ファームウェアは非常に高機能で優れています。パソコンなしでEV3本体だけでも簡単なプログラムを作成できます。 しかし標準ファームウェアは非常にリソース(Computer resource)食らいです。EV3本体に載っているメモリを使い尽くします。 システム改変して自由にソフトウェアを入れ替えるためには、この標準ファームウェアが邪魔になります。 そこで標準ファームウェアを開発した同じソフトウェア開発チームが最低限のOSとドライバーだけを提供した拡張ファームウェアをgithubで公開しています。 ev3devはEV3本体に挿入したmicro SD cardから起動するため標準ファームウェアを壊してしまうことはありません。 何枚でも起動ディスクを作成することができるので失敗を恐れずに様々なことを試すことができます。 ev3devの release 1.0 がリリースされたのが今年の7月。その前後から世界中のハッカーが様々なプログラミング言語でev3devのプログラムを作成しています。 私もその流れ(流行)に乗って、mrubyをev3devの上で動作させようと今回試みました。
  9. githubに掲載されている説明には次のようにあります。 "embedded"がキーワードになります。 "embedded" という言葉は意味が広く、例えば apache [固有名詞] や ngnx [固有名詞: 発音 engine x] に 組み込む(embed) という意味があります。 そういうアプリケーション・プログラム、サーバー・システムの一部としてmrubyを組み込む、ということに関心のある方は今日の16:00より、このホールAでMATSUMOTO Ryosukeさんが発表される講演をお聞きください。 私はもう一つの embedded の意味 家電製品や自動車やコピー機(いわゆるXerox)、そしてロボットなどマイコンを搭載した"組み込みシステム(embedded system)"にmrubyを組み込む用途について説明したいと思います。
  10. 当初サーバー分野で採用が進んだLinuxが、今では携帯電話(スマートフォン)やテレビに広く採用されています。 しかし、当初、こういった組み込み機器にLinuxを採用するときに様々な懸念や抵抗があったと聞きます。 「あれから20年(きみまろ風)」組み込みシステムにmrubyのような抽象度の高いプログラミング言語を採用しようとすれば、おなじような抵抗を受けることが容易に想像できます。 mrubyの採用に対する様々な懸念が投げかけられるでしょう。 『敵を知り己を知れば百戦危うからず』 mrubyの欠点としてしばしば取り上げられるリアルタイム性能とは何か?初代RCXの光センサーのソフトウェア制御を例に説明します。
  11. Mindstormsに採用されている光センサーはどういう仕組みか説明します。 写真では分かりにくいかもしれませんが、このセンサーには2つの電子部品が見えます。 一つはLEDライトです。光センサーがオンになると赤い光でセンサーの前にある物体を照らします。 そして、そのLEDライトの隣にあるのがフォトダイオードと呼ばれる光の強さを測定する電子部品です。 センサーから光を出して、反射してきた光の強さを測定する。航空機を探すレーダーに似た原理です。 このようなセンサーを能動センサー(Active sensor)と呼びます。 光センサーの正面に白い紙を置けば、反射光は強くなり、黒い紙を置けば反射光は弱くなる。 光センサーの正面に同じ白い紙を置いた時でも、近くであれば反射光が強くなり、遠ければ反射光が弱くなります。 単純な仕組みのセンサーですが様々な使いかたの応用が利きます。 まだ、mrubyの話はでてきません。もう少し我慢してハードウェアの話を聞いてください。敵を知り己を知れば百戦危うからず、です。
  12. RCXでつかう光センサーにはLEDが必須です。したがってLEDを光らせるための電力を供給するための配線が一組必要です。 また反射光(refrected light)の強さを測定する受光素子にも電力を供給するための配線が一組必要です。 これらの配線はRCX本体からセンサーへ電気を送り出す出力(アウトプット)の配線です。 一方で反射光を測定した結果の信号を受け取るための入力(インプット)の配線が必要になります。 電気回路ではグラウンド(ground/設置)と呼ばれる配線は出力と入力で共通化することができるので、合計3本の配線があれば出力と入力が可能な回路(electric circuit)が実現できます。
  13. これはMindstorm RCXと光センサーをつなぐコネクター部分の写真です。 レゴのポッチ(stug)を電気をつなぐコネクターとして上手に再デザインしています。 写真では分かりにくいかもしれませんが、コネクターから伸びているケーブルは二本(一組、一対, two-wired)しかありません。 いわゆるプラスとマイナスで一組です。モーターを回すのであれば、プラスとマイナスの一対の配線で構いません。 単純なセンサーであれば、プラスとマイナスの一対の配線で十分なものもあります。 ケーブルをコネクターのポッチ(stug)は4つありますが、ケーブルの線も4本にすると曲げたり狭い場所を通したりするのに不都合だとハードウェア設計者は考えたのではないでしょうか? ケーブルは3本の線(3線式)よりも2本の線(2線式)が良いと。まさに士農工商メカ・エレキ・ソフトの上位階層に君臨するメカ開発者が考えそうなことです。 そこでメカ担当者の我が儘をエレキ担当者とソフト担当者が叶えた工夫が実際のRCXの製品で実装している次の方法です。
  14. 前のスライドで説明した通り、RCX本体とセンサーをつなげる配線は2本(1対)だけです。 その代わりにセンサーにコンデンサー (英:Capacitor) と呼ばれる部品を追加してます。 あえて日本をつかうと蓄電器と呼びます。秋葉原の電子部品店では「コンデンサー」で十分通じますが… このコンデンサーは携帯電話など使われている充電池(rechargeable battery)とは電気をためる原理が異なり、長くてもほんの数秒間 LEDライトを光らせておくだけの電力しかため込むことができません。もちろん充電池をセンサーに組み込めば数分間でも数時間分でも必要な電気を蓄えておくことができますが、それではセンサーの大きさが電池で大きくなり部品代が高くなってしまいます。 そんなことをメカ屋さんやエレキ屋さんが許すはずがありません。 そこでソフト屋さんの登場です。短時間で出力(充電)と入力(放電)を繰り返せばいいんでしょ?
  15. RCX本体と光センサーと結ぶケーブルの電圧をオシロスコープと呼ばれる測定機器で測定した結果です。 図(グラフ)の読み方は、左から右に時間が流れて居ます。高さ(上下)は電圧です。 緑の線がRCX本体と光センサーを結ぶケーブルに流れる電気の強さ(電圧)を示しています。 緑の線の位置が上にあればケーブルに流れる電気の強さ(電圧)は高い、低ければ弱い、ということになります。 左右のメモリは一つの四角が40マイクロ秒です。1マイクロ秒は100万分の1秒ですから、非常に短い時間だというのがわかっていただけると思います。 緑の線が上に張り付いている平らな部分が、RCX本体から光センサーへ電気を送って充電している時間です。 非常に短い時間で充電が完了してMAXに達しているのが、このオシロスコープの図から見て取れます。 つぎに緑の線が下に落ちている部分、ここが光センサーが反射してきた光(反射光)の強さを測定している時間です。 反射光が強いとセンサーに流れる電気が多くなり(つまり放電する電気の量は多くなり)緑の線は、より下へ落ち込みます。 反射光が弱いとセンサーに流れる電気は小さくなり(つまり放電する電気の量は小さくなり)緑の線の下への落ち込みは小さくなります。 RCXに搭載されたプログラムは、この充電と放電(光の測定)を非常に短時間(160ミリ秒)で繰り返します。 とても人が切り替えていたのでは間に合いません。プログラムで動作するマイコンにしが実現できない機能です。 光センサーに対してどの程度の時間、充電すればよいのか? 光センサーが反射光をうけて値が安定するまでにどの程度の時間が必要になるのか? 実際にできあがった回路につないで試してみないと計算だけでは分からない部分があります。 そんな微妙な調整をオシロスコープをみながらプログラミングするのが古き良き時代の組み込みシステムプログラマーでした。
  16. ハードウェアをご存じない人は、一定時間で電気信号の出力と入力を切り替えるなんて簡単さ!と思うかもしれません。 このオシロスコープの波形を見てください。一定の時間(160マイクロ秒)で電気信号の出力と入力を切り替えているはずなのに、その周期が乱れている(遅れている)箇所があるのがわかると思います。 RCXのマイコンは光センサーの制御だけをやっているわけではありません。RCXには複数のセンサーがつながりますし、複数のモーターを回すのもRCXのマイコンの仕事なのです。 RCXのマイコンは忙しいんです。忙しいサラリーマンが手が離せない他の仕事に取り掛かっている間にメールに返信できないように、RCXのマイコンも時たま手が離せない仕事にはまって、光センサーの出力と入力の切り替えのお仕事が後回しになってしまうのです。 リアルタイム性能とは、この手の離せない仕事で後回しになる時間が最悪(最長)どの程度になるか正確に見積もることができる機能になります。 リアルタイム性能を持ったOS(Operationg System)をつかったから、リアルタイム性能をつかったxxを使ったから、この遅れ(後回しになる処理)がゼロになるわけではありません。 マイクロプロセッサが常に複数の仕事を担っている限り遅れは不可避ですが、その遅れがどの程度で収まるか見積もることができる、というのが重要な性能です。 手が離せなくなり遅れることが悪いのではありません。かならず決められた時間以内に返事を返す。まさに人に求められることがCPUには求められます。 このオシロスコープの例でも160マイクロ秒の周期は遅れていますが、放電が終わってしまい光センサーから受け取る入力信号が不正になることはないようになっています。 mrubyを採用してGC(Garbege Collection)が発生したらどうなるでしょうか? RCXのCPUはCGに掛かり切りになり、数百ミリ秒の間、光センサーの制御は後回しになります。 リアルタイム性能をもとめる組み込みシステムには採用できません。失格です。 160ミリ秒の一定周期でアップダウンすべき電圧の変化が、ときどき遅れていることがわかります。 Mindstorms RCXのCPUは複数のセンサーを監視する役割を担うため、処理が間に合わずに遅れることがあります。 このケースではコンデンサーから供給される電力が尽きる前に、処理が間に合っているため支障はありませんが、もし mrubyを採用するとCGのタイミングで、この数百倍から数千倍の遅れが発生して、コンデンサーの電力が途中で尽きてしまいます。
  17. 初代 Mindstorms RCX に mruby は採用できない。もし採用したらシステムが破たんすることがわかりました。 では 三代目 Mindstorms EV3 に mruby を採用しても大丈夫なのでしょうか? 今回、私が実装した mruby-ev3 を例に、Mindstorm EV3の光センサーの仕組みを説明します。
  18. 最初に Minstorms EV3 の光センサー(Color Sensor)のインスタンス(instance)を作成するInitializerの説明です。 引数としてはポート名を与えます。
  19. Initializerに与えたポート名は何かを説明するために写真をお見せします。 Mindstorms EV3では4つのセンサーを同時にIntelligent Brick本体に接続することができます。 4つのセンサーを区別するためにつないだコネクターの位置をAPIのinitializerで指定する必要があります。 写真をみていただくとわかるとおり 3代目 EV3 では本体とセンサーをつなぐケーブルは6線(6-wired)になっています。 ※「6線」と呼んだり「6芯」と呼んだり呼び方がいろいろありますができるだけ「6線」で用語は統一します。  英語も "line" と "wire" でニュアンスが変わると思いますが気にせず統一していただいて結構です。私も意識して「線」と「芯」を区別することはしません。 エレキ屋とソフト屋の巻き返しです! でも確かに初代 RCXと比べて EV3のケーブルは曲げたり丸めたりして取回すことが難しくなっています。 線(wire)の数が増えて、平たく太くなったので仕方がありません。
  20. EV3の光センサーは3つの動作モード、異なる機能を持っています。 RCXの光センサーは単色(赤色)の光の反射を測定することできませんでしたが、EV3ではカラー化を実現しています。 EV3では反射してくる光の色を測定するために、光の三原色、赤い光が反射する強さ、緑の光が反射する強さ、青の光が反射する強さを各々測定することができます。 したがってRCXの光センサーには赤く発光するLEDひとつしか搭載されていませんでしたが、EV3の光センサーには光の三原色、赤、緑、青で発行するLEDライトがひとつづつ、計3個のLEDが搭載されています。 Red, Green, Blueの三原色の各々の反射光の強さを測定する RGB-RAW (RAW:生の) モードがあります。 一方で RCXの光センサーと同じように単色(赤色)のLEDで照らして、赤色の反射光を測定する REFLECTモードがあります。 また反射光を測定するのではなく光センサーに入ってくる(環境の)光の強さを測定するAMBIENTモードがあります。 EV3のカラーセンサーには赤、緑、青の三色LEDライトが組み込まれています。一方で反射する光の強さを測定する部品は一つです。 赤、緑、青の各々の色の反射を測定するために、三色LEDを順番に点灯させて、その時々の反射光の強さを測っています。 RCXに比べてEV3の光センサー(=カラーセンサー)は高機能で複雑な制御が必要そうです。EV3のマイコンは性能がアップしていますがリアルタイム性能は大丈夫でしょうか?
  21. 初代RCXはメインプロセッサ(CPU)1つで複数のセンサーをコントロールしていました。したがってリアルタイム性能は欠かせませんでした。 2代目RCXはメインプロセッサとサブプロセッサのデュアルプロセッサ構成で処理を分担していました。メインプロセッサに求められるリアルタイム性能は低くなりました。 3代目EV3ではセンサーにプロセッサーが搭載されました。したがって、本体(Intelligent Block)のメインプロセッサは光センサー(カラーセンサー)から送られてくる情報を受け取るだけでよくなりました。リアルタイム性能も基本的に必要なくなりました。
  22. まとめ mrubyを使うことが向く分野 mrubyを使うことが向かない分野
  23. 士農工商メカ・エレキ・ソフトのヒエラルキーの最下層で、縁の下の力持ちとして頑張りましょう。
  24. マッシュアップ(Mashup)