Download Presentation
Total Page:16
File Type:pdf, Size:1020Kb
Robots for the Kid in All of Us Nikhil J. Nanivadekar Robots for the Kid in All of Us GS.com/Engineering Nikhil J. Nanivadekar Copyright © 2017 Goldman Sachs. All rights reserved. I Introduction NTRODUCTION 3 Agenda A Agenda GENDA • Robot video • Java vs EV3 Programmer App • Live Programming Demo • Dijkstra’s and A* Algorithm at a glance • Dijkstra’s Algorithm on EV3 • JRE vs Compact Profiles • Demos 5 Robot Video R Robot Video OBOT V IDEO https://youtu.be/EXdtbkYDRgI 7 A Agenda GENDA • Robot video • Java vs EV3 Programmer App • Live Programming Demo • Dijkstra’s and A* Algorithm at a glance • Dijkstra’s Algorithm on EV3 • JRE vs Compact Profiles • Demos 8 Java vs EV3 Programmer App EV3 P EV3 Programmer App • EV3 Programmer App distributed by ROGRAMMER Legos • Visual and graphical programming A interface PP • Available at Mindstorms website 10 L Lejos EJOS • Runs standard Java Virtual machine • Does not run Lego software • Write code similar to a standard Java project • Better motor control, faster processing, open source 11 T Third Party Libraries HIRD • Lejos is a Java Virtual Machine P ARTY • Easy integration with third party libraries L IBRARIES • Upload jars to EV3 and reference on classpath • Run similar to a standard Java project 12 A Agenda GENDA • Robot video • Java vs EV3 Programmer App • Live Programming Demo • Dijkstra’s and A* Algorithm at a glance • Dijkstra’s Algorithm on EV3 • JRE vs Compact Profiles • Demos 13 Live Programming Demo A Agenda GENDA • Robot video • Java vs EV3 Programmer App • Live Programming Demo • Dijkstra’s and A* Algorithm at a glance • Dijkstra’s Algorithm on EV3 • JRE vs Compact Profiles • Demos 15 Dijkstra’s and A* Algorithm at a glance D Dijkstra’s Algorithm IJKSTRA • Find the least cost path from source to all ’ S nodes A LGORITHM • Each node has cost for traversal • Least cost path can be a longer path • Conceived by Edsger W. Dijkstra 17 DIJKSTRA’S ALGORITHM 18 Wikipedia(Dijkstra’s Algorithm) Wikipedia(Dijkstra’s Source: Dijkstra’s Algorithm A* A A* Algorithm • Extension to Dijkstra’s Algorithm LGORITHM • Add a heuristic to guide the program towards the goal • Heuristic can be anything (distance, time, etc.) 19 A Algorithm Functions LGORITHM • Dijkstra – f(n) = c(n) F UNCTIONS • A* – f(n) = c(n) + h(n) c: cost function h: heuristic function 20 A Agenda GENDA • Robot video • Java vs EV3 Programmer App • Live Programming Demo • Dijkstra’s and A* Algorithm at a glance • Dijkstra’s Algorithm on EV3 • JRE vs Compact Profiles • Demos 21 Dijkstra’s Algorithm on EV3 P Problem Statement ROBLEM • Solve the maze S • Motion in x direction costs 1x the TATEMENT absolute distance • Motion in y direction costs 2x the absolute distance 23 PROBLEM STATEMENT 24 Problem Statement G Graph RAPH • Use RGB data of maze • Red: Traversable • Blue: Obstacle • Forms an adjacency matrix of x, y co-ordinates • Use adjacency matrix, color data to get nodes 25 G Graph RAPH • Store node, color data in a MutableObjectIntMap MutableObjectIntMap<Point> GRAPH = new ObjectIntHashMap<>(); // Red = 256, Blue = 1 GRAPH.put(new Point(0, 0), 1); 26 S Successors UCCESSORS if(GRAPH.get(point) > 1) { MutableSet<Point> successors = Sets.mutable.withInitialCapacity(4); if (GRAPH.get(negativeX) > 1) { successors.add(negativeX); } ... return successors; } 27 C Cost Function OST public static int getCost( F UNCTION Point point1, Point point2) { int xCost = Math.abs( point1.getX() – point2.getX()); int yCost = 2 * Math.abs( point1.getY() – point2.getY()); return xCost + yCost; } 28 P Prioritization RIORITIZATION public static Point getNodeToVisit( Point point, SetIterable<Point> verticesToSearch) { return verticesToSearch.minBy( each -> vertexCostMap.get(each)); } 29 P Prioritization RIORITIZATION vertexCostMap: – Map of node to cost to visit – Initialized with all node costs to be Integer.MAX_VALUE – Each time node is visited; update with least cost to visit 30 P Path ATH MutableStack<Point> path = Stacks.mutable.empty(); boolean isPathComplete = false; while (!isPathComplete) { if (start.equals(path.peek())) { isPathComplete = true; } else { path.push( nodeBackpointerMap.get(path.peek())); } } return path; 31 PATH: DIJKSTRA’S 32 Path: Dijkstra’s P Path: A* ATH : A* Heuristic = |xendpoint – xpoint2| + |yendpoint – ypoint2| 33 P Path: A* ATH : A* Heuristic = |xendpoint – xpoint2| + |yendpoint – xpoint2| 34 M Motion Uninterrupted OTION • Path comprised of 226 nodes U • Robot moves node to node, pausing 225 NINTERRUPTED times • How to make robot move smoothly? 35 M Motion Uninterrupted OTION • Flatten the path during motion by U peeking in the future NINTERRUPTED • Check if the next next node has the same heading – Same heading: Mark it to be flattened – Different heading: Compute the angle the robot needs to turn • Hence, achieving motion uninterrupted 36 A Agenda GENDA • Robot video • Java vs EV3 Programmer App • Live Programming Demo • Dijkstra’s and A* Algorithm at a glance • Dijkstra’s Algorithm on EV3 • JRE vs Compact Profiles • Demos 37 Performance of JRE vs Compact Profiles JRE JRE vs Compact Profiles • Stripped down version of JRE into VS C subsets OMPACT P ROFILES Source: Compact Profiles Overview 39 P Performance Comparison ERFORMANCE Compact2 Full JRE C Task OMPARISON (Time in s) (Time in s) EV3 start-up 80 80 Program execution start-up 13 15 Graph initialization 22 22 Dijkstra’s algorithm 110 115 A* algorithm 49 54 Source: Compact Profiles Overview 40 E Empirical Observations MPIRICAL • Does it stop mid-execution? • Is the performance consistent? O BSERVATIONS • What about the jar sizes? • What about the memory footprint? 41 A Agenda GENDA • Robot video • Java vs EV3 Programmer App • Live Programming Demo • Dijkstra’s and A* Algorithm at a glance • Dijkstra’s Algorithm on EV3 • JRE vs Compact Profiles • Demos 42 Demos Learn more at GS.com/Engineering © 2017 Goldman Sachs. This presentation should not be relied upon or considered investment advice. Goldman Sachs does not warrant or guarantee to anyone the accuracy, completeness or efficacy of this presentation, and recipients should not rely on it except at their own risk. This presentation may not be forwarded or disclosed except with this disclaimer intact. www.modsummit.com www.developersummit.com .