Copyright © 2012, Oracle and/or its affiliates. All rights reserved.1
InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese an...
Presented at QCon London
www.qconlondon.com
Purpose of QCon
- to empower software development by facilitating the spread o...
Is It A Car? Is It A Computer?
No, It’s The Raspberry Pi
Java Carputer
Simon Ritter
Head of Java Evangelism
Oracle Corpora...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.3
The following is intended to outline our general pro...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.4
Program Agenda
§  Cars and Computers
§  The Raspbe...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.5
Cars And Computers
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.6
My First Car: 1981
§  No electronics
–  Well, it ha...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.7
Car Wiring: 1970s
Image coutesy of Haynes manuals
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.8
My Current Car
§  Lots of electronics
–  Engine Con...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.9
Car Wiring: 2011
Bus architecture means substantiall...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.10
Protocols For Car Bus Communication
§  On Board Di...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.11
The Raspberry Pi
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.12
Raspberry Pi
§  Project started in 2006
–  Goal wa...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.13
Raspberry Pi
§  CPU: ARM 11 (v6) core running at 7...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.14
Raspberry Pi Carputer
§  Plenty of computing power...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.15
Embedded Java and JavaFX
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.16
Java Technology for Embedded Devices
Platform
Footp...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.17
Java ME Embedded 3.3
§  Connected Limited Device C...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.18
Java SE 8 Embedded (Early Access)
§  Tuned for Ras...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.19
JavaFX On Embedded Devices
§  JavaFX on embedded d...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.20
Building a Java Powered
“Carputer”
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.21
Carputer Design Objectives
§  Display realtime dat...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.22
ELM327
§  WiFi or Bluetooth connection to OBD-II
§...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.23
Touchscreen
§  2 DIN fitting size
–  Ideal for cen...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.24
JavaFX And Touchscreen
§  Raspian Linux recognises...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.25
Carputer Hardware Architecture
USB WiFi Dongle
Touc...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.26
Touchscreen
Hardware Fitting Challenges
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.27
Accelerometer
§  Sparkfun breakout board MPU 9150
...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.28
Accelerometer Code
Using Pi4J Library on Java SE Em...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.29
Compensating For Gravity In Acceleration
§  The ac...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.30
Calculating Power And Torque
§  Results will not h...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.31
Carputer Software Architecture
§  Screens based
– ...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.32
UI Design Ideas
Take Inspiration From Others
Renaul...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.33
UI Design Ideas
Take Inspiration From Others
Tesla
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.34
UI Design Ideas
Take Inspiration From Others
Lambor...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.35
Simple Data Display Control
§  Only uses 3 nodes
–...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.36
User Interaction
§  Complex UIs are bad for driver...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.37
UI Screens
Splash Screen
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.38
UI Screens
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.39
UI Screens
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.40
UI Screens
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.41
Graph Plots Of Throttle Position And Power
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.42
Using Car Control Buttons
§  Not simple
–  Car man...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.43
Future Ideas, Conclusions
and Resources
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.44
What Next
§  Integrate heart rate monitor to add b...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.45
Adafruit Ultimate GPS Breakout
P1-01
TX
RX
NOTE: RX...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.46
The Pi Can Interface
§  Can’t read CAN bus and OBD...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.47
Resources
§  www.audi.com
§  www.raspberrypi.org
...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.48
Demos
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.49
Watch the video with slide synchronization on
InfoQ.com!
http://www.infoq.com/presentations/raspberry-
pi-java-car
Upcoming SlideShare
Loading in …5
×

Is It A Car? Is It A Computer? No, It's a Raspberry Pi

2,452 views

Published on

Video and slides synchronized, mp3 and slide download available at URLhttp://bit.ly/1sRbEOD.

Simon Ritter looks at how Embedded Java and a Raspberry Pi were used to communicate with the diagnostic and management systems of an Audi S3 and process the data, and how JavaFX has been used to provide an in-car information system for less than $200. Filmed at qconlondon.com.

Simon Ritter is a Java Technology Evangelist at Oracle Corporation. Simon has been in the IT business since 1984. Originally working in the area of UNIX development for AT&T UNIX System Labs and then Novell, Simon moved to Sun in 1996. Having moved to Oracle as part of the Sun acquisition he now focuses on the core Java platform and Java for client applications.

Published in: Technology, Business
  • Be the first to comment

Is It A Car? Is It A Computer? No, It's a Raspberry Pi

  1. 1. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.1
  2. 2. InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations /raspberry-pi-java-car
  3. 3. Presented at QCon London www.qconlondon.com Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide
  4. 4. Is It A Car? Is It A Computer? No, It’s The Raspberry Pi Java Carputer Simon Ritter Head of Java Evangelism Oracle Corporation @speakjava
  5. 5. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.3 The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle s products remains at the sole discretion of Oracle.
  6. 6. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.4 Program Agenda §  Cars and Computers §  The Raspberry Pi §  Embedded Java and JavaFX §  Building a Java Powered “Carputer” §  Demos
  7. 7. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.5 Cars And Computers
  8. 8. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.6 My First Car: 1981 §  No electronics –  Well, it had a radio §  Purely electromechanical –  Points/Distributor –  Carburettor/Manual choke –  Drum brakes –  Dynamo –  Lights, horn, wipers, fan, ignition switch 1971 Mini Clubman 1000
  9. 9. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.7 Car Wiring: 1970s Image coutesy of Haynes manuals
  10. 10. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.8 My Current Car §  Lots of electronics –  Engine Control Unit (ECU) –  Fuel Injection/Electronic timing –  “Fly-by-wire” throttle –  Anti-lock Braking System (ABS) –  Electronic Stability Program (ESP) –  Magnetorheological Suspension –  Satellite navigation –  Auto-sensing wipers and lights 2011 Audi S3
  11. 11. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.9 Car Wiring: 2011 Bus architecture means substantially less wiring Convenience Bus Infotainment Bus Powertrain Bus
  12. 12. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.10 Protocols For Car Bus Communication §  On Board Diagnostics (OBD-II) –  Connector, SAE J1939 / ISO 15031-3 §  OBD-II Protocols –  SAE J1850 PWM or VPM –  ISO 9141-2 –  ISO 14230 –  ISO 15765-4: Controller Area Network (CAN) Bus §  11 or 29 bit ID, 250 or 500 kbaud
  13. 13. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.11 The Raspberry Pi
  14. 14. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.12 Raspberry Pi §  Project started in 2006 –  Goal was to devise a computer to inspire children –  Inspiration from the BBC Micro project from 1981 –  Officially launched 29th Feb, 2012 –  Over 1 million boards shipped so far History and Goals
  15. 15. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.13 Raspberry Pi §  CPU: ARM 11 (v6) core running at 700MHz –  Broadcom SoC package –  Can now be overclocked to 1GHz (without breaking the warranty!) §  Memory: 512Mb §  I/O: –  HDMI and composite video –  Audio out (3.5mm plug) –  2 x USB ports –  Ethernet –  Header pins for GPIO, UART, SPI and I2C Specification
  16. 16. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.14 Raspberry Pi Carputer §  Plenty of computing power –  With low electrical power consumption (< 1 Amp at 5V) §  Persistent storage provided by SD card –  Disk drives not ideal in hot places with lots of vibration §  Supported device for embedded Java –  Hardware floating point acceleration configured –  Java SE Embedded and Java ME Embedded –  JavaFX Prism graphics engine ported Advantages
  17. 17. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.15 Embedded Java and JavaFX
  18. 18. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.16 Java Technology for Embedded Devices Platform Footprint Device CPU/ GPU/I-OARM 7 Cortex M ARM9/11 MIPS32 ARM Cortex A PPC Intel Atom 50KB-1MB 1MB-10MB 10MB-100MB Java ME Java SE Java Card
  19. 19. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.17 Java ME Embedded 3.3 §  Connected Limited Device Configuration 1.1 –  Reduced footprint JVM and core libraries §  Device Access API (new) –  Standard library for access to §  GPIO §  UART §  I2C/SPI §  Additional profiles used as required Key Features
  20. 20. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.18 Java SE 8 Embedded (Early Access) §  Tuned for Raspberry Pi –  ARM6 architecture does not require hardware FP –  Raspberry Pi has one, so JVM needs specific compiler options §  Inlcudes JavaFX §  Includes compact profiles for reduced footprint §  Recently added to standard build platforms –  EA updated as each new build comes out Key Features
  21. 21. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.19 JavaFX On Embedded Devices §  JavaFX on embedded does not support the full feature set –  No WebView component (not a problem for the carputer) –  No direct media playback support §  For video there is a work around (but, does the carputer need it?) §  Sound would be nice, but not essential §  Remember resource constraints –  Big scene graphs need memory and CPU cycles –  Keep number of nodes small (ideally <50) Things To Consider
  22. 22. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.20 Building a Java Powered “Carputer”
  23. 23. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.21 Carputer Design Objectives §  Display realtime data –  Engine performance (Power, Torque, Load) –  Driver data (Throttle position, steering angle, braking force, etc) –  G-Forces on car §  Record data for later analysis –  Produce graphs to display changes over time –  Play at Formula 1 –  Improve driving style (!)
  24. 24. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.22 ELM327 §  WiFi or Bluetooth connection to OBD-II §  Fixed IP address, Ad-hoc networking §  Need to configure Raspberry Pi –  /etc/network/interfaces §  AT style commands for control §  Non-AT commands are assumed to be OBD-II –  Simple request-response interaction –  Easy to write Java code to handle this Cheap way to hack your car
  25. 25. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.23 Touchscreen §  2 DIN fitting size –  Ideal for centre console §  HDMI input –  Specifically marketed for Raspberry Pi §  USB connection for touch screen Lots of things available on eBay
  26. 26. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.24 JavaFX And Touchscreen §  Raspian Linux recognises device: eGalax Inc §  Creates two devices in /dev/input/event0, event1 §  JavaFX sees devices and uses event0 –  No events generated –  Need to use event1 (No idea why) §  Special build of JavaFX? §  Neccesity is the mother of invention –  Delete event0 and mknod event0 c 13 65 (same as event1) –  Need script to repeat at boot time Not completely straightforward
  27. 27. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.25 Carputer Hardware Architecture USB WiFi Dongle Touch Screen Accelerometer HDMI USB I2C 12V Car Converter ELM327 Car Service Port 5V USB
  28. 28. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.26 Touchscreen Hardware Fitting Challenges
  29. 29. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.27 Accelerometer §  Sparkfun breakout board MPU 9150 –  9 DoF sensor (accelerometer, gyroscope, compass) §  Communications via I2C –  Configure Raspberry Pi /etc/modules §  i2c-bcm2708, i2c-dev §  i2c-detect -y 1 to get address –  Compass communication is a bit more complicated §  Second I2C bus
  30. 30. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.28 Accelerometer Code Using Pi4J Library on Java SE Embedded I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1); I2CDevice device = bus.getDevice(0x68); /* Start sensing */ device.write(0x6B, (byte)0b00000000); device.write(0x6C, (byte)0b00000000); /* Set configuration */ device.write(0x1B, (byte)0b00011000); // Gyroscope device.write(0x1C, (byte)0b00000100); // Accelerometer device.read(0x3B, accelData, 0, ACCEL_PACKET_SIZE);
  31. 31. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.29 Compensating For Gravity In Acceleration §  The accelerometer measures acceleration (obviously) §  Gravity is a constant acceleration –  Consider it static acceleration §  What we want is dynamic acceleration §  Zero out gravitational effect –  Assume no rotation of the sensor –  Nearly correct, car will roll in corners and pitch under braking/acceleration –  Good enough for the demo –  Could integrate gyro and Kalman filter for higher accuracy The Earth Sucks
  32. 32. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.30 Calculating Power And Torque §  Results will not have high accuracy –  Values in red are not precise §  Dynamometer is the only way to get accurate figures §  Interesting to see values v. manufacturers figures Torque (Nm) = Mass x Wheel Radius x Acceleration (in G) Torque (lb/ft) = Torque in Nm x 0.73756 Power (BHP) = Torque (lb/ft) x engine RPM / 5252
  33. 33. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.31 Carputer Software Architecture §  Screens based –  Splash screen –  Basic and advanced car data –  G forces on car –  Graphed results of different parameters §  Simple UI –  Can’t read numbers when driving §  Touchscreen to switch screens –  Repurpose existing car controls to change screen? Realtime Data
  34. 34. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.32 UI Design Ideas Take Inspiration From Others Renault Megane Sport
  35. 35. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.33 UI Design Ideas Take Inspiration From Others Tesla
  36. 36. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.34 UI Design Ideas Take Inspiration From Others Lamborghini Reveton
  37. 37. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.35 Simple Data Display Control §  Only uses 3 nodes –  Polygon –  Rectangle –  Line –  Labels are optional §  Displays –  Current value –  Maximum value since start (resetable) §  Simple to understand from a glance
  38. 38. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.36 User Interaction §  Complex UIs are bad for driver distraction –  Programming the SatNav while driving §  Make Carputer interaction as simple as possible §  Sequence of screens –  Main menu? Too complex, too much reading –  Cycle through screens (Keep number small) –  Just touch screen to change to next display §  Use setMouseTransparent(true); –  Use steering wheel button
  39. 39. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.37 UI Screens Splash Screen
  40. 40. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.38 UI Screens
  41. 41. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.39 UI Screens
  42. 42. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.40 UI Screens
  43. 43. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.41 Graph Plots Of Throttle Position And Power
  44. 44. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.42 Using Car Control Buttons §  Not simple –  Car manufacturers don’t share the CAN bus IDs and message formats –  Even things like Audi forums can’t supply this –  Need to reverse engineer §  ELM327 has AT MA command –  Monitor all CAN Bus traffic –  Need to pick the relevant message from a LOT of data –  Once the ID is know use AT MT xx to monitor transmit messages Monitoring CAN Bus Data
  45. 45. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.43 Future Ideas, Conclusions and Resources
  46. 46. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.44 What Next §  Integrate heart rate monitor to add biometric data §  Heads Up Display (HUD) –  Microprojector and half-silvered perspex §  Further investigation of CAN Bus signals –  Brake pressure, steering position –  Use other switches –  Send commands (this is rather scary)
  47. 47. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.45 Adafruit Ultimate GPS Breakout P1-01 TX RX NOTE: RX TX TX RX
  48. 48. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.46 The Pi Can Interface §  Can’t read CAN bus and OBDII at the same time via ELM327 §  Use connector for entertainment system §  Need to check that I2C for accelerometer will still work §  Reasonable cost, $50
  49. 49. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.47 Resources §  www.audi.com §  www.raspberrypi.org §  javafx.oracle.com §  blogs.oracle.com/speakjava
  50. 50. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.48 Demos
  51. 51. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.49
  52. 52. Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations/raspberry- pi-java-car

×