+ All Categories
Home > Software > Cars and Computers: Building a Java Carputer

Cars and Computers: Building a Java Carputer

Date post: 15-Jul-2015
Category:
Upload: indicthreads
View: 508 times
Download: 0 times
Share this document with a friend
Popular Tags:
50
Cars and Computers: Building a Java Carputer Simon Ritter Head of Java Technology Evangelism Oracle Corp. Twitter: @speakjava
Transcript

Cars and Computers: Building a Java Carputer

Simon RitterHead of Java Technology EvangelismOracle Corp.

Twitter: @speakjava

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Safe Harbor Statement

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.

2

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Cars And Computers

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Car Wiring: 1970s

Image coutesy of Haynes manuals

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Bus architecture means substantially less wiring

Car Wiring: 2011

Convenience Bus Infotainment Bus Powertrain Bus

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

The Java Carputer(Mark 1)

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Carputer Design Objectives• Display realtime data• Engine performance (Power, Torque, Load)• Driver data (Throttle position, steering angle, braking force, etc)• G-Forces on car• Graphed data for time-based analysis

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Carputer Hardware Architecture

USB WiFi Dongle

Touch Screen

Accelerometer

HDMI USB

I2C

12V CarConverter

ELM327

CarService

Port

5V USB

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Hardware Fitting Challenges

Touchscreen

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Accelerometer CodeUsing 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); // Gyroscopedevice.write(0x1C, (byte)0b00000100); // Accelerometer

device.read(0x3B, accelData, 0, ACCEL_PACKET_SIZE);

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Take Inspiration From Others

UI Design Ideas

Renault Megane Sport

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Take Inspiration From Others

UI Design Ideas

Tesla

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Take Inspiration From Others

UI Design Ideas

Lamborghini Reveton

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Splash Screen

UI Screens

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

UI Screens

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

UI Screens

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

The Java Carputer(Mark 2)

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Carputer Hardware Architecture

25

USB via FTDICrossover ethernet

Infra red Thermal sensor

CAN High

CAN Low

OBD2 Service Port

Wi-Fi

Accelerometer/Gyro/Compass

I2C

USB

UART

Serial

GPSHeart Rate Monitor

USB

Video Camera

Raspberry Pi Model B+7” Touch secreen

USB

SDR/TPMS

CAN Bus

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Tracking Position With GPS• AdaFruit Ultimate GPS breakout– 10Hz read rate– Serial interface

• Very simple configuration– Disable /dev/ttyAMA0 on Pi as console– 9600 8N1– Read data using librxtx-java– Comma separated values $GPGGA and $GPVTG– Need to handle frequent data corruption

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Heart Rate Monitoring of the Driver• Sparkfun board– USB interface, serial connection

• Similar to GPS– Use librxtx-java– 9600, 8N1

• More complicated coding– Actually need to send a read request!

• Some issues with wireless connection– 80cm max, doesn’t work well through a Rapsberry Pi

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

In-car Video• Becoming very common to avoid insurance issues• Transcend DrivePro 200– Built-in Wi-Fi– iPhone app

• How to get video stream?– Approached Transcend tech support– Found VLC code–Wireshark– SYN/ACK, Yuck!

28

Camera Application

192.168.0.1 192.168.0.2

Port 9000 Port 43229

Port 9001 Port 42719

Port 9002 Port 58105

Port 8554 (RTSP) Port 60583

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

The Simplest Solution Is Often The Best

29

Push button using GPIO lines and Pi4J

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Thermal Sensors For Brakes and TyresThe Goal

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Infra-Red Thermometer

• MLX90614 breakout board– I2C interface seemed problematic on the Pi– Also has serial interface– Use FTDI breakout board– 4 wires becomes simple serial interface

31

The Reality

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Thermal Sensor Data• Provides continuous reading as lines of text (e.g. 73.2F)– Don’t like Fahrenheit, wanted Celcius– Lambdas and Streams!

32

private double currentTemperature;

public void run() { thermalReader.lines() .mapToDouble(s -> Double.parseDouble(s.substring(0, s.length() - 1))) .map(t -> ((t - 32) * 5 / 9)) .filter(t -> t != currentTemperature) .peek(t -> listener.ifPresent(l -> l.temperatureChange(t))) .forEach(t -> currentTemperature = t);}

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Thermal Sensor Data• Provides continuous reading as lines of text (e.g. 73.2F)– Don’t like Fahrenheit, wanted Celcius– Lambdas and Streams!

33

private double currentTemperature;

public void run() { thermalReader.lines() .mapToDouble(s -> Double.parseDouble(s.substring(0, s.length() - 1))) .map(t -> ((t - 32) * 5 / 9)) .filter(t -> t != this.currentTemperature) .peek(t -> listener.ifPresent(l -> l.temperatureChange(t))) .forEach(t -> this.currentTemperature = t);}

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 34

Tyre Sensor

Fitting The Thermal Sensors

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 35

Brake Disk Sensor

Fitting The Thermal Sensors

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 36

Separate Pi in Engine Bay

Fitting The Thermal Sensors

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Fitting The Thermal Sensors

• Simple server listens on port• Carputer requests data• Couple of issues– Server needed reset for new

connection (bug to be fixed)– How to tell which sensor is which

(ttyUSB0/ttyUSB1)

37

The Networked Car

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Fitting The Thermal Sensors

• Rasperry Pi at over 50C– After 10 minute drive

• New approach required– Longer USB cables– Put the Pi in the car

38

Internal Combustion Produces Heat

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Getting Data From The CAN Bus• Controller Area Network• Used to connect many sensors, actuators and devices–Without huge amounts of wiring

• Conveniently the CAN bus is connected to the OBD2 port– Yes, the wiring is there– No, the signals are not– Presumably security measure from car manufacturers– Boo!

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Where There’s A Will There’s A Way

Getting Data From The CAN Bus

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Where There’s A Will There’s A Way

Getting Data From The CAN Bus

Success! (And the car still works)

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Getting Data From The CAN Bus

• Lawicel CAN bus to USB • Serial device• Sends decoded data• Need to write a Java library– CAN id–Message data

• Then the hard part starts– Figuring it all out

42

Electrical Connectivity Is Only The Start

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 43

Finished Data Capture System

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Data Recording and Analysis

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Display Collected Data• JavaFX application• Video stream– Synchronised to data streams

• Data recorded as sequence of text records– Comma separated values–One line per sensor– Time stamp

• Read all data in at start of application– 15 minutes of data takes about 100ms

45

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

• Video (with controls)

• G-forces

• GPS co-ordinates/altitude

• Map of current position

• Speed (compare car and GPS)

• Bearing

• Engine load

• Fuel pressure

• Air intake temperature

• Coolant temperature

• Catalyst/exhaust temperature

• Tyre temperature

• Brake temperature

• Throttle position

• Engine RPM

• Heart rate

46

Data To Display

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Conclusions & Resources

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Conclusions• Cars produce lots of data• Use of sensors with Java is simple to collect (most) data• Playback of data useful for insurance, fleet management, training• Java and JavaFX make UI design simple

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Resources and Links• www.sparkfun.com• www.adafruit.com• www.raspberrypi.org• blogs.oracle.com/speakjava• Twitter: @speakjava

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Demos


Recommended