rubykaigi2015 making robots-with-mruby
TRANSCRIPT
![Page 1: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/1.jpg)
Making Robots with mruby
2015-12-12 RubyKaigi 2015 Yurie Yamane
Team Yamanekko
![Page 2: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/2.jpg)
Who am I?
やまね ゆりえ(Yurie Yamane) @yuri_at_earth(only in Japanese)
a member of TOPPERS project ET robocon staff たいやき部(taiyaki-bu)
![Page 4: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/4.jpg)
2012
![Page 5: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/5.jpg)
2013
![Page 6: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/6.jpg)
2014
nomitory
![Page 7: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/7.jpg)
2015
![Page 8: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/8.jpg)
Robots and Us
![Page 9: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/9.jpg)
http://global.yamaha-motor.com/jp/showroom/event/2015tokyomotorshow/sp/exhibitionmodels/mgp/
“There are probably some things in this world that only I can do.”https://www.youtube.com/watch?v=EzgJWwAx8Mo
![Page 10: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/10.jpg)
PART 1: Self-balancing Robot using LEGO EV3
![Page 11: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/11.jpg)
闇RubyKaigi(2011)
http://gihyo.jp/news/report/01/rubykaigi2011/0001?page=7
![Page 13: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/13.jpg)
ETロボコンAdvent Calendar 2015
http://www.adventar.org/calendars/734
![Page 14: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/14.jpg)
ET Robot Contest• aka ET ロボコン(ET ROBOCON)
• ET means “Embedded Technology”
• To develop the advanced skills of embedded technology such as modeling, designing, and developing embedded systems
• “one-make racing” style (all robots have same designs)
![Page 15: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/15.jpg)
EV3way: SoftwareSystem OS Language
TOPPERS/EV3RT TOPPERS RTOS C, C++
MonoBrick Linux C#
leJOS EV3 Linux Java
![Page 16: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/16.jpg)
EV3way: Software
• mruby on EV3RT + TECS
• mrby Forum ver.
• yamanekko ver.
System OS Language
TOPPERS/EV3RT TOPPERS RTOS C + mruby
![Page 17: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/17.jpg)
mruby-ev3rt
![Page 18: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/18.jpg)
mruby-ev3rt demoSep. 20th, 2015 at Fukuyama, Hiroshima Pref.
Movie by A. Hirai with ET Robocon Staff@chu-shikoku
![Page 19: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/19.jpg)
• TOPPERS(Toyohashi OPen Platform for Embedded Real-time Systems)
• TOPPERS’ Products
• Realtime Kernel
• Automotive Kernel
• Tools
• TOPPERS + TSUBAME(swallow) -> TOPAME
TOPPERS Project
とぱめ(TOPAME)https://www.toppers.jp/
![Page 20: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/20.jpg)
Who uses TOPPERS?
http://ev.nissan.co.jp/LEAF/?pfa=01http://www.ricoh.co.jp/printer/sg/3100ke/
http://www.korg.com/jp/products/dj/electribe/http://music.casio.com/ja/products/digital_pianos/ghs/products/
https://en.wikipedia.org/wiki/H-IIBfrom: http://toppers.jp/applications.html
![Page 21: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/21.jpg)
TOPPERS Kernel Roadmap
ATK1 ATK2 ATK3
FMP3
HRP3
ASP3
2000 2010 2020
1st generation 3rd generation2nd generation
ITRON
Automotive
FDMP
HRP
FI4
JSP
Dynamicgen.
ASP Safety
HRP2
FMP
ASPSSP
http://toppers.jp/docs/intro-invite.pdf
![Page 22: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/22.jpg)
TOPPERS EV3RTunprivileged mode (user mode)
privileged mode (kernel mode)
http://dev.toppers.jp/trac_user/ev3pf/wiki/WhatsEV3RT
![Page 23: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/23.jpg)
Self Balancing Robot
![Page 24: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/24.jpg)
Inverted Pendulum
![Page 25: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/25.jpg)
Inverted Pendulum
![Page 26: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/26.jpg)
Inverted Pendulum
![Page 27: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/27.jpg)
Inverted Pendulum
![Page 28: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/28.jpg)
Inverted Pendulum
![Page 29: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/29.jpg)
Inverted Pendulum
![Page 30: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/30.jpg)
Inverted Pendulum
![Page 31: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/31.jpg)
How Robot Works
Target BoardSensorsActuator
![Page 32: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/32.jpg)
Gyro Sensor
Ultrasonic Sensor
Motor
Light Sensor
![Page 33: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/33.jpg)
How Robot Works
Target BoardSensorsActuator
Read
![Page 34: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/34.jpg)
How Robot Works
Target BoardSensorsActuator
Move
![Page 35: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/35.jpg)
How Robot Works
sense
calculate
control motor
execute periodically
![Page 36: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/36.jpg)
What’s RTOS• OS for Real Time System
• Real time system: to make much of Deadlines
• NOTICE: “Real-Time” has several meanings
• “Real-Time” in RTOS is completely different from such as “Real-time Web”
![Page 37: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/37.jpg)
Time is Resource• In real time
system, Tasks should be done in a given time (deadline)
• RTOS manage “Time” as resources (like memories)
https://www.flickr.com/photos/arjanrichter/3886579525/
![Page 38: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/38.jpg)
Priority of tasks
• Every tasks have their own priority
• Lower-priority tasks never execute when higher-priority tasks alive
• While higher-priority task is running, lower-priority tasks are not running (into READY status)
![Page 39: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/39.jpg)
All tasks are mruby
main_task
balance_task
watch_task
HIGH priority
LOW priority
balancer.rb
watch.rb
app_ruby.rb
注)バランス制御に重点を置いた例。 これが正しい方法というわけではない
![Page 40: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/40.jpg)
balancer.rbloop do forward = 30 color = colorSensor.brightness if color >= (LIGHT_WHITE + LIGHT_BLACK)/2 turn = 20 ## turn left else turn = -20 ## turn right end
pwm_left, pwm_right, *args = balancer.calculate_auto(forward, turn, GYRO_OFFSET) leftMotor.pwm = pwm_left rightMotor.pwm = pwm_right EV3RT::Task.sleepend
![Page 41: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/41.jpg)
watch.rb
loop do break if back_button.pressed? EV3RT::Task.sleepend
![Page 42: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/42.jpg)
app_ruby.rb## initialize sensors, motors, clock and taskstouchSensor = EV3RT::TouchSensor.new(EV3RT::PORT_1)gyroSensor = EV3RT::GyroSensor.new(EV3RT::PORT_4)leftMotor = EV3RT::Motor.new(EV3RT::PORT_C, EV3RT::LARGE_MOTOR)rightMotor = EV3RT::Motor.new(EV3RT::PORT_B, EV3RT::LARGE_MOTOR)clock = EV3RT::Clock.new()EV3RT::Task.active(EV3RT::BALANCE_TASK_ID) ## initialize balancer
loop do ## waiting button pushed break if touchSensor.pressed? clock.sleep(10)end
EV3RT::Task.start_cyclic(EV3RT::BALANCE_CYC_ID) ## start balancerEV3RT::Task.sleep ## do other tasks
![Page 43: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/43.jpg)
Classes in mruby-ev3rtMotor
TailMotor
Sensor
GyroSensorColorSensor
TouchSensor
LED LCD Clock Serial Task
Balancer
Button
![Page 44: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/44.jpg)
PART 2:
DIY Self-balancing Robot
![Page 45: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/45.jpg)
DIY Self-balancing Robot
Can we make our own robots from scratch?
https://www.flickr.com/photos/84906483@N08/8747337118/
![Page 46: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/46.jpg)
DIY Self-balancing Robot
😿🙀😸http://www.instructables.com/id/Another-Easier-Inverted-Pendulum/
![Page 47: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/47.jpg)
![Page 48: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/48.jpg)
Collecting Parts
Target BoardSensors Actuator
![Page 49: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/49.jpg)
Raspberry Pi A+• Lower battery usage
than Pi B+ and Pi 2
• Works with small USB battery
• Cheeper (< $30) than Pi B+ and Pi 2
![Page 50: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/50.jpg)
Raspberry Pi A+
😿
![Page 51: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/51.jpg)
ARM Family
http://www.emcu.it/CortexFamily/CortexFamily.html
Pi1 Pi2
EV3STM32F4
![Page 52: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/52.jpg)
Inverted Pendulum
![Page 53: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/53.jpg)
How to measure an angle
![Page 54: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/54.jpg)
Gyro Sensor
http://akizukidenshi.com/catalog/g/gK-06779/
![Page 55: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/55.jpg)
Gyro Sensor
• ST Micro L3GD20
• 3-axis digital gyroscope
• use 8 pin DIP module by Akizuki Denshi
![Page 56: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/56.jpg)
Gyro Sensor
😿
![Page 57: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/57.jpg)
Gyro Sensor
🙀
![Page 58: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/58.jpg)
Measuring the Angle
!1 !2
![Page 59: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/59.jpg)
![Page 60: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/60.jpg)
How to rotate wheels
![Page 61: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/61.jpg)
DC Motor
• TAMIYA FA-130 Motor
• speed control by voltage
• IO cannot change voltage
• 3.3 V (fixed)
• → use PWM
![Page 62: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/62.jpg)
DC Motor
😿
![Page 63: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/63.jpg)
![Page 64: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/64.jpg)
(Motor + Gear) x 2
![Page 65: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/65.jpg)
![Page 66: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/66.jpg)
Wheel x 2
![Page 67: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/67.jpg)
Body
Tamiya 70157 Universal Plate Set
![Page 68: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/68.jpg)
![Page 69: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/69.jpg)
Batteries (for motors)
![Page 70: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/70.jpg)
Batteries (for motors)
🙀
![Page 71: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/71.jpg)
Battery (for Pi A+)
![Page 72: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/72.jpg)
![Page 73: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/73.jpg)
connect a sensor
?
![Page 74: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/74.jpg)
SPI vs I2C• SPI and I2C are popular protocols
• Gyro sensor L3GD20 supports both
• SPI is more complex, but faster than I2C
• Raspberry Pi supports SPI (see “BCM2835 ARM Peripherals”) • https://www.raspberrypi.org/wp-content/uploads/
2012/02/BCM2835-ARM-Peripherals.pdf
![Page 75: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/75.jpg)
Serial Peripheral Interface (SPI)
• Master and Slave model • In our case, Raspberry Pi is master • 4 pins (Input, Output, Clock, Select)
![Page 76: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/76.jpg)
Demo
![Page 77: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/77.jpg)
Gyro Testserial = Serial.new timer = SystemTimer.new gyro = Gyro.new() serial.puts("time,gyro")
MESURE_COUNTS = 45 start_time = timer.now
cnt = 0 loop do mesure_sum = 0 MESURE_COUNTS.times{ mesure_sum += gyro.read(Gyro::Y) }
omega_i = mesure_sum * 0.00875 / MESURE_COUNTS; cnt +=1 now = ((timer.now - start_time) / 1000).floor if cnt == 10 cnt = 0 serial.puts("#{now},#{omega_i}") end end
![Page 78: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/78.jpg)
connect motors
?
![Page 79: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/79.jpg)
PWM• Pulse-Width Modulation
• pseudo-analog signal output
http://www.electronics-tutorials.ws/blog/pulse-width-modulation.html
![Page 80: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/80.jpg)
PWM• Raspberry Pi A+/B+/2 supports 2 PWMs
• Old Raspberry Pi B support only 1 PWM
• So we can control 2 motors (Right/Left)
![Page 81: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/81.jpg)
Motor Driver
ST Micro L298N
![Page 82: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/82.jpg)
Motor Driver
PWMIN1 IN2
OUT1 OUT2
MOTOR
Motor Driver
Raspberry Pi
IN1 IN2 OUT0 0 STOP
0 1 Forward
1 0 Reverse
1 1 Brake
![Page 83: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/83.jpg)
Demo
![Page 84: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/84.jpg)
Motor Test# in1, in2, enable, pwm0or1 motor_left = Motor.new(5,6,12,0) motor_right = Motor.new(16,20,19,1)
motor_right.drive(50) motor_left.drive(50) RSRobot.delay(3000000) motor_left.drive(200) motor_right.drive(200) RSRobot.delay(3000000) motor_right.drive(50) motor_left.drive(50) RSRobot.delay(3000000) motor_right.drive(-100) motor_left.drive(-100) RSRobot.delay(3000000) motoy_right.stop motor_left.sop
![Page 85: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/85.jpg)
JTAG• For Debugger
• Doesn’t have to use it
• but with JTAG, we can use GDB, so it’s very helpful to debug
![Page 86: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/86.jpg)
Pinout
![Page 87: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/87.jpg)
Making Balancer class
![Page 88: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/88.jpg)
Balancing Equation
power = k_1 * (Angular Velocity) + k_2 * (Angle) + k_3 * (Velocity) + k_4 * (Position)
P = K
!
! +K
✓
✓ +K
v
v +K
x
x
![Page 89: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/89.jpg)
Angle
✓ ✓
![Page 90: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/90.jpg)
Angular Velocity! !(fast) (slow)
![Page 91: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/91.jpg)
Velocity(fast) (slow)vv
![Page 92: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/92.jpg)
Position(far) (near)y asixsy asixs
![Page 93: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/93.jpg)
Balancing Equation
power = k_1 * omega_i + k_2 * theta_i + k_3 * v_i + k_4 * x_i
P = K
!
! +K
✓
✓ +K
v
v +K
x
x
![Page 94: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/94.jpg)
Balancing Equation
power = k_1 * omega_i + k_2 * theta_i + k_3 * v_i + k_4 * x_i
a ≒ Power v ≒ ∫ Power x ≒ ∬ Power
P = K
!
! +K
✓
✓ +K
v
v +K
x
x
![Page 95: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/95.jpg)
Balancing EquationP = K
!
! +K
✓
✓ +K
v
v +K
x
x
= K
!
! +K
✓
X! +K
v
XP +K
x
XXP
power = k_1 * omega_i + k_2 * theta_i + k_3 * v_i + k_4 * x_i
a ≒ Power v ≒ ∫ Power x ≒ ∬ Power
![Page 96: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/96.jpg)
Balancing Equation
theta_i += omega_i v_i += power x_i += v_i power = k_1 * theta_i + k_2 * omega_i + k_3 * v_i + k_4 * x_i
P = K
!
! +K
✓
✓ +K
v
v +K
x
x
= K
!
! +K
✓
X! +K
v
XP +K
x
XXP
![Page 97: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/97.jpg)
Balancer classclass Balancer
def calculate(omega_i) @theta_i += omega_i # … t = @k_angle * @theta_i o = @k_omega * omega_i # … power = t + o + … # … return power, power end
end
![Page 98: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/98.jpg)
main looploop do gyro_value = gyro.measure(Gyro::Y, MESURE_COUNTS)
pwm_left, pwm_right = balancer.calculate(gyro_value)
motor_left.pwm = pwm_left motor_right.pwm = pwm_right end
![Page 99: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/99.jpg)
demo
![Page 100: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/100.jpg)
![Page 101: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/101.jpg)
まずは何か作ってみよう!
![Page 102: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/102.jpg)
Source code
• https://github.com/yamanekko/mruby-ev3rt
• https://github.com/yamanekko/mruby-rs-robot
• https://github.com/yamanekko/raspi_robot
![Page 103: RubyKaigi2015 making robots-with-mruby](https://reader035.vdocuments.mx/reader035/viewer/2022062522/5873229c1a28ab673e8b7c81/html5/thumbnails/103.jpg)
Thank you & Domo Arigato!
ZZZ...
You can contact us on Twitter: @yuri_at_earth Special Thanks to: @tenderlove A. Hirai with ET Robocon Staff@chu-shikoku