25
LET’S SHIFT THE THE WORLD Miroslav Kopecky 23 rd October 2014

The Robot under dictate of the LegoMindStorm Java Concurrency API

Embed Size (px)

DESCRIPTION

Way How To connect LegoEV3 (Robot with sensors) to highly concurrent JavaEE system based on spring by solving well know Consumer Producer paradigm.

Citation preview

Page 1: The Robot under dictate of the LegoMindStorm Java Concurrency API

LET’S SHIFT THETHE WORLD

Miroslav Kopecky

23rd October 2014

Page 2: The Robot under dictate of the LegoMindStorm Java Concurrency API

MOTIVATION: I HAVE A DREAM

Karel Capek ROBOT

Miroslav Kopecky Prague, 23rd October 2014

© Martin Luther King

CZECH WORD

Page 3: The Robot under dictate of the LegoMindStorm Java Concurrency API

BEGINNING: HOW IT LOOKED LIKE?

Miroslav Kopecky Prague, 23rd October 2014

Page 4: The Robot under dictate of the LegoMindStorm Java Concurrency API

DREAM EVOLUTION

Miroslav Kopecky Prague, 23rd October 2014

DREAM REDEFINITION

Page 5: The Robot under dictate of the LegoMindStorm Java Concurrency API

LET’S CREATE/FIND PROBLEMSand try to provide some set of solutions

Miroslav Kopecky Prague, 23rd October 2014

The Robot under dictate of the LegoMindStorm Java Concurrency API

Page 6: The Robot under dictate of the LegoMindStorm Java Concurrency API

DO YOU KNOW THE MEANING?

Miroslav Kopecky Prague, 23rd October 2014

Page 7: The Robot under dictate of the LegoMindStorm Java Concurrency API

AGENDA:• ROBOT INITIATION SEQUENCE INJAVA SPACE

• PRODUCER / CONSUMER PROBLEM • SYNCHRONIZED (demo) • CONCURRENCY API FEATURE (demo) • CONNECT ALL UNITS TOGETHER (demo)

• ROBOT GOES ONLINE (demo)

Miroslav Kopecky Prague, 23rd October 2014

Page 8: The Robot under dictate of the LegoMindStorm Java Concurrency API

ROBOT INITIATION SEQUENCE

Miroslav Kopecky Prague, 23rd October 2014

LegoMindStorm Java Concurrency APINetwork Communication

Install LeJOS 8.1maven B tool

Compile Libraries (ev3classes)Connect The Brick

(WiFi, Bluetooth,UBS)

Page 9: The Robot under dictate of the LegoMindStorm Java Concurrency API

EVEN SMALL DREAM IS COMPLEX

Miroslav Kopecky Prague, 23rd October 2014

Page 10: The Robot under dictate of the LegoMindStorm Java Concurrency API

EVEN SMALL DREAM IS COMPLEX

Miroslav Kopecky Prague, 23rd October 2014

RMI

brick = new RemoteEV3(EV3BRICK_IP); brick.setDefault();

…STILL ONE LegoBRICK…

ProdCons

Page 11: The Robot under dictate of the LegoMindStorm Java Concurrency API

THE ARE some RULEZ again

Miroslav Kopecky Prague, 23rd October 2014

1. brick.createRegulatedMotor(“A", "M".charAt(0));

2. Port portTouchSensor = brick.getPort("S1"); return new EV3TouchSensor(portTouchSensor);

possible monitor lock

return raw data

3. Mixture of 1 and 2 => IR Sensor (HEAD)

Page 12: The Robot under dictate of the LegoMindStorm Java Concurrency API

PRODUCER CONSUMER STORY:

Miroslav Kopecky Prague, 23rd October 2014

BUS - Shared DataStructure

ORDERS PRODUCERS

CONSUMERS ~ BRIDGES

Page 13: The Robot under dictate of the LegoMindStorm Java Concurrency API

SYNCRONIZED (demo 1, 2, 3) - early age

Miroslav Kopecky Prague, 23rd October 2014

public EventStorage(){ maxSize = 4; storage = new LinkedList<>(); motorRight = LegoBrickMoveEnginesProvider.

getInstance().getMotorRight(); motorLeft = LegoBrickMoveEnginesProvider.

getInstance().getMotorLeft(); }

feature:: couldn’t extend the lock beyond boundaries

Page 14: The Robot under dictate of the LegoMindStorm Java Concurrency API

SYNCHRONIZED 1: THREAD CREATION

Miroslav Kopecky Prague, 23rd October 2014

DEMO

…more threads flying around…

Page 15: The Robot under dictate of the LegoMindStorm Java Concurrency API

SYNCHRONIZED 2: EXECUTORs

Miroslav Kopecky Prague, 23rd October 2014

DEMO

… creation and execution…

Page 16: The Robot under dictate of the LegoMindStorm Java Concurrency API

SYNCHRONIZED 3: LegoExecutor

Miroslav Kopecky Prague, 23rd October 2014

DEMO

… statistics…

Page 17: The Robot under dictate of the LegoMindStorm Java Concurrency API

JAVA CONCURENCY API (demo)

Miroslav Kopecky Prague, 23rd October 2014

couple of synchronisation Utilities: Semaphore, CountDownLatch, CyclicBarrier

Exchanger<List<Integer>> exchanger = new Exchanger<>();

executor.submit( new BrickConsumer( consumerBuffer, exchanger)); executor.shutdown();

Page 18: The Robot under dictate of the LegoMindStorm Java Concurrency API

EXCHANGER : exchanger.exchange(buffer)

Miroslav Kopecky Prague, 23rd October 2014

DEMO

Page 19: The Robot under dictate of the LegoMindStorm Java Concurrency API

CONNECT ALL UNITS TOGETHER (demo)

Miroslav Kopecky Prague, 23rd October 2014

concurrency and parallelism in the action

1. sensors + engine (front hand) executor.submit(new MoveSimulationSeparate());

2. movement engine (robot platform) executor.submit(new MovementUnit());

Page 20: The Robot under dictate of the LegoMindStorm Java Concurrency API

CONNECT ALL UNITS TOGETHER

Miroslav Kopecky Prague, 23rd October 2014

FRONT HAND SYSTEM

PLATFORM

Page 21: The Robot under dictate of the LegoMindStorm Java Concurrency API

CONNECT ALL UNITS TOGETHER

Miroslav Kopecky Prague, 23rd October 2014

DEMO

… more treads with statistics…

Page 22: The Robot under dictate of the LegoMindStorm Java Concurrency API

ROBOT GOES ONLINE (demo)

Miroslav Kopecky Prague, 23rd October 2014

not to Hollywood (yet) ~ like Frankie => RELAX

1. Spring 4.1 1. JSP + TILES with AngularJS

2. NETTY -> RaspberryPi 3. LegoROBOT

LegoCommandPriorityQueue<E>

Page 23: The Robot under dictate of the LegoMindStorm Java Concurrency API

ROBOTS GOES ONLINE

Miroslav Kopecky Prague, 23rd October 2014

DEMO… promising Feature<?>…

Page 24: The Robot under dictate of the LegoMindStorm Java Concurrency API

QUESTIONS & ANSWERS

I CAN ONLY PLAY THE SOUND!

Miroslav Kopecky Prague, 23rd October 2014

Audio brickAudio = brick.getAudio(); brickAudio.systemSound(?);

Page 25: The Robot under dictate of the LegoMindStorm Java Concurrency API

THANKs!

Miroslav Kopecky Prague, 23rd October 2014