introduction to rosjava - roscon 2020 to rosjava... · introduction to rosjava damon kohler. google...

30
Google Confidential and Proprietary Introduction to rosjava Damon Kohler

Upload: others

Post on 21-May-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Introduction to rosjavaDamon Kohler

Page 2: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

What to expect and what not to expect

Expect ● Developer oriented● High level concepts● Abbreviated code samples

Not ● Tutorial● ROS overview● Java overview● Android overview

Page 3: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

rosjava: One Year

Page 4: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Why use rosjava?

Page 5: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Asynchronous

What does that mean? ● Methods take listener objects (aka callbacks)● Netty (http://netty.io)

Why? ● Better performance● Better coupling/cohesion

Example Subscriber.addMessageListener(MessageListener)

Page 6: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Node vs. NodeMain

Node encapsulates ● NodeConfiguration● factories (e.g. newPublisher(), newSubscriber())● parameter client● master client● slave server

NodeMain ● encapsulates business logic● is a NodeListener

Page 7: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Lifecycle events

NodeMain started

onStart

onShutdown

Publisher started

onMasterRegistrationFailure

onMasterRegistrationSuccess

onNewSubscriber

onShutdown

Page 8: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

NodeMain

public class MyNode implements NodeMain { @Override public GraphName getDefaultNodeName() { return new GraphName("my_node"); } @Override public void onStart(Node node) { // TODO: Get down to business. ... } ...}

Page 9: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

More threads, fewer processes

NodeMainExecutor encapsulates ● NodeFactory● ExecutorService (thread pool)

public static void main(String[] argv) { NodeMain nodeMain; NodeConfiguration nodeConfiguration; NodeMainExecutor nodeMainExecutor; ... nodeMainExecutor.execute(nodeMain, nodeConfiguration); ...}

Page 10: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

No spin

node.executeCancellableLoop(new CancellableLoop() { @Override protected void loop() { System.out.println("Work, work, work."); }} Not while (node.isOk()) { System.out.println("Work, work, work."); node.spin();}

Page 11: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Publishers and Subscribers

Node node;std_msgs.String message;... Publisher<std_msgs.String> p = node.newPublisher("chatter", std_msgs.String._TYPE);p.publish(message); Subscriber<std_msgs.String> subscriber = node.newSubscriber("chat", std_msgs.String._TYPE);subscriber.addMessageListener( new MessageListener<std_msgs.String>() { @Override public void onNewMessage(std_msgs.String message) { ... }});

Page 12: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Service server

node.newServiceServer( "add_two_ints", test_ros.AddTwoInts._TYPE, new ServiceResponseBuilder< test_ros.AddTwoInts.Request, test_ros.AddTwoInts.Response>() { @Override public void build( test_ros.AddTwoInts.Request request, test_ros.AddTwoInts.Response response) { response.setSum(request.getA() + request.getB()); } });

Page 13: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Service client

ServiceClient< test_ros.AddTwoInts.Request, test_ros.AddTwoInts.Response> client = node.newServiceClient( "add_two_ints", test_ros.AddTwoInts._TYPE); test_ros.AddTwoInts.Request request = client.newMessage(); client.call( request, new ServiceResponseListener< test_ros.AddTwoInts.Response>() { @Override public void onSuccess( test_ros.AddTwoInts.Response response) { ... } });

Page 14: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Messages

● Empty interfaces backed by dynamic proxy● rosjava_messages contains the world● Definitions parsed at runtime Node node;...MessageFactory factory = node.getTopicMessageFactory();std_msgs.String m = factory.newFromType(std_msgs.String._TYPE); Publisher<std_msgs.String> publisher;...std_msgs.String m = publisher.newMessage();m.setData("Hello, world!");

Page 15: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Build system

● Java dependency management, not debs● Gradle, not rosmake

Gradle (http://www.gradle.org) ● Flexible● Build-by-convention ● Dependency management

Page 16: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Package directory layout

my_stackstack.xmlmy_package

manifest.xmlbuild.gradlesrc

mainjavaresources

testjavaresources

build

Page 17: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Basic build.gradle

apply plugin: 'java' sourceCompatibility = 1.6targetCompatibility = 1.6 version = '0.0.0-SNAPSHOT'group = 'ros.my_stack' dependencies { compile 'ros.rosjava_core:rosjava:0.0.0-SNAPSHOT'} repositories { mavenLocal() mavenCentral()}

Page 18: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Running nodes

build.gradle apply plugin: 'application' mainClassName = 'org.ros.RosRun'installApp.into project.file('dist')distZip.destinationDir project.file('dist') Build and execute ./gradlew installApprosrun my_package my_package com.example.MyNodeMain

Page 19: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

What about Android?

Page 20: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Play today

● Sensor driver● Robot monitor● Teleop● Map maker● Map navigation● PR2 props● PR2 pan/tilt

Page 21: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Adding more than what's on board

CDC ACM (android_acm_serial)

Page 22: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Android plus lasers

Page 23: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Android apps

public class MainActivity extends RosActivity { @Override protected void init(NodeMainExecutor nodeMainExecutor) { NodeMain nodeMain; ... NodeConfiguration cfg = NodeConfiguration.newPublic(); cfg.setMasterUri(getMasterUri()); nodeMainExecutor.execute(nodeMain, nodeConfiguration); } ...}

Page 24: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

RosActivity lifecycle

RosActivity started

MasterChooser started

init(NodeMainExecutor)

App exitsCancelNodeMainExecutorService

started

● Wake and WiFi locks● Persistent background service● Notification

Page 25: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Android patterns

● Views as NodeMains● Data driven UIs

public class RosTextView<T> extends TextView implements NodeMain { @Override public void onStart(Node node) { Subscriber<T> s = node.newSubscriber(...); } ...}

Page 26: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Android components

● RosTextView● RosImageView● RosCameraPreviewView● OrientationPublisher● VirtualJoystick● VisualizationView● DistanceView● ...

Page 27: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Best practices

Java packages ● Domain name should be followed by the ROS package name● Only core packages should begin with org.ros

Messages ● Use fully qualified class name (e.g. std_msgs.String)● Prefer newMessage() helpers to factories

Asynchronous ● Prefer callbacks to blocking

Page 28: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Current focus

● Feature parity with roscpp/rospy● Stable API● Comprehensive documentation● 1.0 release

Page 29: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

Future directions

● OSGi● Groovy deployment scripts● Java CLI tools (e.g. rostopic, rosservice)● Topic multiplexing● Topic-based services● Topic-based master, multi-master● ...

Page 30: Introduction to rosjava - ROSCon 2020 to rosjava... · Introduction to rosjava Damon Kohler. Google Confidential and Proprietary What to expect and what not to expect Expect Developer

Google Confidential and Proprietary

http://www.cloudrobotics.com/

[email protected]