├── .gitignore
├── CHANGELOG.rst
├── CMakeLists.txt
├── README.md
├── android_acm_serial
├── AndroidManifest.xml
├── build.gradle
└── src
│ └── org
│ └── ros
│ └── android
│ └── android_acm_serial
│ ├── AcmAsyncInputStream.java
│ ├── AcmDevice.java
│ ├── AcmDeviceActivity.java
│ ├── AcmDevicePermissionCallback.java
│ ├── AcmInputStream.java
│ ├── AcmOutputStream.java
│ ├── BitRate.java
│ ├── DataBits.java
│ ├── Parity.java
│ ├── StopBits.java
│ ├── UsbDeviceDetachedReceiver.java
│ ├── UsbDevicePermissionCallback.java
│ ├── UsbDevicePermissionReceiver.java
│ ├── UsbRequestCallback.java
│ ├── UsbRequestPool.java
│ └── UsbRequestQueue.java
├── android_benchmarks
├── AndroidManifest.xml
├── build.gradle
├── res
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── org
│ └── ros
│ └── android
│ └── android_benchmarks
│ └── MainActivity.java
├── android_core_components
├── AndroidManifest.xml
├── build.gradle
├── res
│ ├── drawable
│ │ ├── background.png
│ │ ├── black_background.png
│ │ ├── center_widget.png
│ │ ├── directional_arrow.png
│ │ ├── error.png
│ │ ├── grey_ring_notched.png
│ │ ├── horizon_original.png
│ │ ├── intensity.png
│ │ ├── large_d_widget_3.png
│ │ ├── large_pan_marker_3.png
│ │ ├── large_tilt_marker_3.png
│ │ ├── mid_angle_slice.png
│ │ ├── ok.png
│ │ ├── pan_tilt_controller.png
│ │ ├── pan_tilt_follower.png
│ │ ├── previous_velocity.png
│ │ ├── pt_bg.png
│ │ ├── pt_home_marker.png
│ │ ├── rotate_left_icon.png
│ │ ├── rotate_right_icon.png
│ │ ├── small_d_widget_3.png
│ │ ├── small_pan_marker_3.png
│ │ ├── small_tilt_marker_3.png
│ │ ├── stale.png
│ │ ├── top_angle_slice.png
│ │ ├── warn.png
│ │ ├── zoom_bar_lit.png
│ │ ├── zoom_bar_notlit.png
│ │ ├── zoom_bg.png
│ │ ├── zoom_in_normal.png
│ │ ├── zoom_in_pressed.png
│ │ ├── zoom_out_normal.png
│ │ └── zoom_out_pressed.png
│ ├── layout
│ │ ├── master_chooser.xml
│ │ ├── pan_tilt.xml
│ │ └── virtual_joystick.xml
│ ├── mipmap-hdpi
│ │ └── icon.png
│ ├── mipmap-ldpi
│ │ └── icon.png
│ ├── mipmap-mdpi
│ │ └── icon.png
│ └── values
│ │ ├── common_strings.xml
│ │ └── styles.xml
└── src
│ ├── org
│ └── ros
│ │ └── android
│ │ ├── AppCompatRosActivity.java
│ │ ├── BitmapFromCompressedImage.java
│ │ ├── BitmapFromImage.java
│ │ ├── MasterChooser.java
│ │ ├── MessageCallable.java
│ │ ├── NodeMainExecutorListener.java
│ │ ├── NodeMainExecutorService.java
│ │ ├── NodeMainExecutorServiceListener.java
│ │ ├── OrientationPublisher.java
│ │ ├── RosActivity.java
│ │ └── view
│ │ ├── DiagnosticsArrayView.java
│ │ ├── DistancePoints.java
│ │ ├── DistanceRenderer.java
│ │ ├── DistanceView.java
│ │ ├── PanTiltView.java
│ │ ├── RosImageView.java
│ │ ├── RosTextView.java
│ │ ├── VirtualJoystickView.java
│ │ ├── ZoomMode.java
│ │ ├── camera
│ │ ├── CameraPreviewView.java
│ │ ├── CompressedImagePublisher.java
│ │ ├── RawImageListener.java
│ │ └── RosCameraPreviewView.java
│ │ └── visualization
│ │ ├── Color.java
│ │ ├── OpenGlDrawable.java
│ │ ├── OpenGlTransform.java
│ │ ├── RotateGestureDetector.java
│ │ ├── TextureBitmap.java
│ │ ├── Vertices.java
│ │ ├── Viewport.java
│ │ ├── VisualizationView.java
│ │ ├── XYOrthographicCamera.java
│ │ ├── XYOrthographicRenderer.java
│ │ ├── layer
│ │ ├── CameraControlLayer.java
│ │ ├── CameraControlListener.java
│ │ ├── CompressedOccupancyGridLayer.java
│ │ ├── DefaultLayer.java
│ │ ├── GridCellsLayer.java
│ │ ├── LaserScanLayer.java
│ │ ├── Layer.java
│ │ ├── OccupancyGridLayer.java
│ │ ├── PathLayer.java
│ │ ├── PointCloud2DLayer.java
│ │ ├── PosePublisherLayer.java
│ │ ├── PoseSubscriberLayer.java
│ │ ├── RobotLayer.java
│ │ ├── SubscriberLayer.java
│ │ └── TfLayer.java
│ │ └── shape
│ │ ├── BaseShape.java
│ │ ├── GoalShape.java
│ │ ├── MetricSpacePoiShape.java
│ │ ├── MetricSpacePolygon.java
│ │ ├── MetricSpacePoseShape.java
│ │ ├── PixelSpacePoiShape.java
│ │ ├── PixelSpacePoseShape.java
│ │ ├── Shape.java
│ │ ├── TextShape.java
│ │ ├── TextShapeFactory.java
│ │ ├── TriangleFanShape.java
│ │ └── Triangulate.java
│ └── uk
│ └── co
│ └── blogspot
│ └── fractiousg
│ └── texample
│ ├── GLText.java
│ ├── SpriteBatch.java
│ ├── TextureRegion.java
│ └── Vertices.java
├── android_tutorial_camera
├── AndroidManifest.xml
├── build.gradle
├── res
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── org
│ └── ros
│ └── android
│ └── android_tutorial_camera
│ └── MainActivity.java
├── android_tutorial_image_transport
├── AndroidManifest.xml
├── README
├── build.gradle
├── res
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
├── src
│ └── org
│ │ └── ros
│ │ └── android
│ │ └── android_tutorial_image_transport
│ │ └── MainActivity.java
└── usb_cam.launch
├── android_tutorial_map_viewer
├── AndroidManifest.xml
├── build.gradle
├── res
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── org
│ └── ros
│ └── android
│ └── android_tutorial_map_viewer
│ ├── MainActivity.java
│ └── SystemCommands.java
├── android_tutorial_pubsub
├── AndroidManifest.xml
├── build.gradle
├── res
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── org
│ └── ros
│ └── android
│ └── android_tutorial_pubsub
│ └── MainActivity.java
├── android_tutorial_teleop
├── AndroidManifest.xml
├── build.gradle
├── res
│ ├── layout
│ │ └── main.xml
│ ├── menu
│ │ └── settings_menu.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── org
│ └── ros
│ └── android
│ └── android_tutorial_teleop
│ └── MainActivity.java
├── build.gradle
├── buildscript.gradle
├── compressed_map_transport
├── build.gradle
└── src
│ └── main
│ └── java
│ └── org
│ └── ros
│ └── android
│ └── compressed_map_transport
│ └── CompressedMapTransport.java
├── docs
├── Makefile
├── build.gradle
└── src
│ └── main
│ └── sphinx
│ ├── building.rst
│ ├── conf.py.in
│ ├── getting_started.rst
│ ├── index.rst
│ ├── installing.rst
│ ├── javadoc.py
│ ├── overview.rst
│ └── ros.py
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── package.xml
├── polling_input_stream
├── build.gradle
└── src
│ ├── main
│ └── java
│ │ └── org
│ │ └── ros
│ │ └── android
│ │ └── acm_serial
│ │ └── PollingInputStream.java
│ └── test
│ └── java
│ └── org
│ └── ros
│ └── android
│ └── acm_serial
│ └── PollingInputStreamTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .gradle
3 | .project
4 | .settings
5 | bin
6 | build
7 | build.xml
8 | gen
9 | libs
10 | lint.xml
11 | local.properties
12 | proguard-project.txt
13 | project.properties
14 |
15 | # These are Android Studio files, might be worth including these later.
16 | *.iml
17 | .idea
18 | build.log
19 | build-log.xml
20 | /opencv/
21 | /android_all_sensors_driver/
22 | /android_camera_driver/
23 | /android_sensors_driver/
24 | *~
25 | *.log
26 |
--------------------------------------------------------------------------------
/CHANGELOG.rst:
--------------------------------------------------------------------------------
1 | Changelog
2 | =========
3 |
4 | 0.4.0 (2018-10-04)
5 | * Deprecating android_10 and android_15; adding support for Android P.
6 | * Minor fixes for visualization layers.
7 | * Made LocalBinder class public.
8 | * Gradle 4.10.2 update.
9 | * Contributors: Rob (rking788), Juan Ignacio Ubeira, Julian Cerruti.
10 |
11 | 0.3.3 (2017-04-17)
12 | ------------------
13 | * Several MasterChooser fixes and improvements.
14 | * Added all constructors from RosActivity to AppCompat activity.
15 | * RosActivity can now call a custom activity as a MasterChooser.
16 | * Cherry-pick from indigo. Fixing memory leaks with ServiceConnection.
17 | * Contributors: Dan Ambrosio, Juan Ignacio Ubeira, Julian Cerruti
18 |
19 | 0.3.2 (2017-03-07)
20 | ------------------
21 | * Cherry-picked from indigo. Fixing memory leaks with ServiceConnection
22 | * Contributors: Dan Ambrosio
23 |
24 | 0.3.1 (2017-02-22)
25 | ------------------
26 | * Update vertex buffer limit - fixes #251.
27 | * Add autofocus parameters to android_tutorial_camera
28 | * Use compileSdk compatible with support library version
29 | * Update gradle sdk version
30 | * Update gradle dependencies
31 | * Add AppCompatRosActivity class
32 | * Android Gradle Plug-in 1.0.+ -> 2.2.3
33 | * Gradle 2.2.1 -> 2.14.1
34 | * update essential function which is addLayer and delete null check in onCreate
35 | * revert addlayer to use in android apps
36 | * Contributors: Daniel Stonier, Ernesto Corbellini, Julian Cerruti, Perrine Aguiar, Sem van den Broek, dwlee
37 |
38 | 0.3.0 (2016-12-13)
39 | ------------------
40 | * Updates for Kinetic release.
41 |
42 | 0.2.0 (2015-02-21)
43 | ------------------
44 | * Option for choosing to start with/without the master chooser.
45 | * Revamped camera classes.
46 | * Revamped onStart with fewer arguments.
47 | * First build on indigo.
48 |
49 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.8.3)
2 | project(android_core)
3 |
4 | find_package(catkin REQUIRED rosjava_build_tools)
5 |
6 | catkin_android_setup(assembleRelease uploadArchives)
7 |
8 | catkin_package()
9 |
10 | ##############################################################################
11 | # Installation
12 | ##############################################################################
13 |
14 | install(DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_MAVEN_DESTINATION}/org/ros/android_core/
15 | DESTINATION ${CATKIN_GLOBAL_MAVEN_DESTINATION}/org/ros/android_core)
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | See [rosjava_core](https://github.com/rosjava/rosjava_core) readme.
2 |
--------------------------------------------------------------------------------
/android_acm_serial/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/android_acm_serial/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | dependencies {
18 | compile project(':android_core_components')
19 | }
20 |
21 | apply plugin: 'com.android.library'
22 |
23 | android {
24 | compileSdkVersion 28
25 |
26 | defaultConfig {
27 | minSdkVersion 16
28 | targetSdkVersion 28
29 | versionCode 1
30 | versionName "1.0"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/AcmAsyncInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | import com.google.common.base.Preconditions;
20 |
21 | import android.hardware.usb.UsbConstants;
22 | import android.hardware.usb.UsbEndpoint;
23 | import android.hardware.usb.UsbRequest;
24 | import android.util.Log;
25 |
26 | import java.io.IOException;
27 | import java.io.InputStream;
28 | import java.nio.ByteBuffer;
29 |
30 | public class AcmAsyncInputStream extends InputStream {
31 |
32 | private static final boolean DEBUG = false;
33 | private static final String TAG = "AcmAsyncInputStream";
34 |
35 | private final UsbRequestPool usbRequestPool;
36 | private final UsbEndpoint endpoint;
37 |
38 | public AcmAsyncInputStream(UsbRequestPool usbRequestPool, UsbEndpoint endpoint) {
39 | Preconditions.checkArgument(endpoint.getDirection() == UsbConstants.USB_DIR_IN);
40 | this.endpoint = endpoint;
41 | this.usbRequestPool = usbRequestPool;
42 | }
43 |
44 | @Override
45 | public void close() throws IOException {
46 | usbRequestPool.shutdown();
47 | }
48 |
49 | @Override
50 | public int read(byte[] buffer, int offset, int count) throws IOException {
51 | Preconditions.checkNotNull(buffer);
52 | if (offset < 0 || count < 0 || offset + count > buffer.length) {
53 | throw new IndexOutOfBoundsException();
54 | }
55 | // NOTE(damonkohler): According to the InputStream.read() javadoc, we should
56 | // be able to return 0 when we didn't read anything. However, it also says
57 | // we should block until input is available. Blocking seems to be the
58 | // preferred behavior.
59 | if (DEBUG) {
60 | Log.i(TAG, "Reading " + count + " bytes.");
61 | }
62 | int byteCount = 0;
63 | while (byteCount == 0) {
64 | UsbRequest request = usbRequestPool.poll(endpoint);
65 | if (!request.queue(ByteBuffer.wrap(buffer, offset, count), count)) {
66 | Log.e(TAG, "IO error while queuing " + count + " bytes to be read.");
67 | }
68 | }
69 | if (byteCount < 0) {
70 | throw new IOException("USB read failed.");
71 | }
72 | // System.arraycopy(slice, 0, buffer, offset, byteCount);
73 | if (DEBUG) {
74 | Log.i(TAG, "Actually read " + byteCount + " bytes.");
75 | // Log.i(TAG, "Slice: " + byteArrayToHexString(slice));
76 | }
77 | return byteCount;
78 | }
79 |
80 | @Override
81 | public int read() throws IOException {
82 | throw new UnsupportedOperationException();
83 | }
84 |
85 | // TODO(damonkohler): Possibly move this to some common place?
86 | private static String byteArrayToHexString(byte[] data) {
87 | if (data == null) {
88 | return "null";
89 | }
90 | if (data.length == 0) {
91 | return "empty";
92 | }
93 | StringBuilder out = new StringBuilder(data.length * 5);
94 | for (byte b : data) {
95 | out.append(String.format("%02x", b));
96 | }
97 | return out.toString();
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/AcmDevicePermissionCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | /**
20 | * @author damonkohler@google.com (Damon Kohler)
21 | */
22 | public interface AcmDevicePermissionCallback {
23 |
24 | void onPermissionGranted(AcmDevice acmDevice);
25 |
26 | void onPermissionDenied();
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/AcmInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | import com.google.common.base.Preconditions;
20 |
21 | import android.hardware.usb.UsbConstants;
22 | import android.hardware.usb.UsbDeviceConnection;
23 | import android.hardware.usb.UsbEndpoint;
24 | import android.util.Log;
25 |
26 | import java.io.IOException;
27 | import java.io.InputStream;
28 |
29 | public class AcmInputStream extends InputStream {
30 |
31 | private static final boolean DEBUG = false;
32 | private static final String TAG = "AcmInputStream";
33 |
34 | // Disable USB read timeouts. Reads are expected to block until data becomes
35 | // available.
36 | private static final int TIMEOUT = 0;
37 |
38 | private final UsbDeviceConnection connection;
39 | private final UsbEndpoint endpoint;
40 |
41 | public AcmInputStream(UsbDeviceConnection connection, UsbEndpoint endpoint) {
42 | Preconditions.checkArgument(endpoint.getDirection() == UsbConstants.USB_DIR_IN);
43 | this.connection = connection;
44 | this.endpoint = endpoint;
45 | }
46 |
47 | @Override
48 | public void close() throws IOException {
49 | }
50 |
51 | @Override
52 | public int read(byte[] buffer, int offset, int count) throws IOException {
53 | Preconditions.checkNotNull(buffer);
54 | if (offset < 0 || count < 0 || offset + count > buffer.length) {
55 | throw new IndexOutOfBoundsException();
56 | }
57 | // NOTE(damonkohler): According to the InputStream.read() javadoc, we should
58 | // be able to return 0 when we didn't read anything. However, it also says
59 | // we should block until input is available. Blocking seems to be the
60 | // preferred behavior.
61 | byte[] slice = new byte[count];
62 | if (DEBUG) {
63 | Log.i(TAG, "Reading " + count + " bytes.");
64 | }
65 | int byteCount = 0;
66 | while (byteCount == 0) {
67 | byteCount = connection.bulkTransfer(endpoint, slice, slice.length, TIMEOUT);
68 | if (DEBUG) {
69 | if (byteCount == 0) {
70 | Log.i(TAG, "bulkTransfer() returned 0, retrying.");
71 | }
72 | }
73 | }
74 | if (byteCount < 0) {
75 | throw new IOException("USB read failed.");
76 | }
77 | System.arraycopy(slice, 0, buffer, offset, byteCount);
78 | if (DEBUG) {
79 | Log.i(TAG, "Actually read " + byteCount + " bytes.");
80 | Log.i(TAG, "Slice: " + byteArrayToHexString(slice));
81 | }
82 | return byteCount;
83 | }
84 |
85 | @Override
86 | public int read() throws IOException {
87 | throw new UnsupportedOperationException();
88 | }
89 |
90 | // TODO(damonkohler): Possibly move this to some common place?
91 | private static String byteArrayToHexString(byte[] data) {
92 | if (data == null) {
93 | return "null";
94 | }
95 | if (data.length == 0) {
96 | return "empty";
97 | }
98 | StringBuilder out = new StringBuilder(data.length * 5);
99 | for (byte b : data) {
100 | out.append(String.format("%02x", b));
101 | }
102 | return out.toString();
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/AcmOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | import com.google.common.base.Preconditions;
20 |
21 | import android.hardware.usb.UsbConstants;
22 | import android.hardware.usb.UsbEndpoint;
23 | import android.hardware.usb.UsbRequest;
24 | import android.util.Log;
25 |
26 | import java.io.IOException;
27 | import java.io.OutputStream;
28 | import java.nio.ByteBuffer;
29 |
30 | public class AcmOutputStream extends OutputStream {
31 |
32 | private static final boolean DEBUG = false;
33 | private static final String TAG = "AcmOutputStream";
34 |
35 | private final UsbRequestPool usbRequestPool;
36 | private final UsbEndpoint endpoint;
37 |
38 | public AcmOutputStream(UsbRequestPool usbRequestPool, UsbEndpoint endpoint) {
39 | Preconditions.checkArgument(endpoint.getDirection() == UsbConstants.USB_DIR_OUT);
40 | this.endpoint = endpoint;
41 | this.usbRequestPool = usbRequestPool;
42 | }
43 |
44 | @Override
45 | public void close() throws IOException {
46 | usbRequestPool.shutdown();
47 | }
48 |
49 | @Override
50 | public void flush() throws IOException {
51 | }
52 |
53 | @Override
54 | public void write(byte[] buffer, int offset, int count) {
55 | Preconditions.checkNotNull(buffer);
56 | if (offset < 0 || count < 0 || offset + count > buffer.length) {
57 | throw new IndexOutOfBoundsException();
58 | }
59 | if (DEBUG) {
60 | Log.i(TAG, "Writing " + count + " bytes from offset " + offset + ".");
61 | }
62 | UsbRequest request = usbRequestPool.poll(endpoint);
63 | if (!request.queue(ByteBuffer.wrap(buffer, offset, count), count)) {
64 | Log.e(TAG, "IO error while queuing " + count + " bytes to be written.");
65 | }
66 | }
67 |
68 | @Override
69 | public void write(int oneByte) throws IOException {
70 | write(new byte[] { (byte) oneByte }, 0, 1);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/BitRate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | public enum BitRate {
20 | BPS_300(300), BPS_1200(1200), BPS_2400(2400), BPS_4800(4800), BPS_9600(9600), BPS_14400(14400), BPS_19200(19200), BPS_28800(28800), BPS_38400(38400), BPS_57600(57600), BPS_115200(115200);
21 |
22 | private int bitRate;
23 |
24 | private BitRate(int bitRate) {
25 | this.bitRate = bitRate;
26 | }
27 |
28 | int getBitRate() {
29 | return bitRate;
30 | }
31 | }
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/DataBits.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | public enum DataBits {
20 | DATA_BITS_5(5), DATA_BITS_6(6), DATA_BITS_7(7), DATA_BITS_8(8), DATA_BITS_16(16);
21 |
22 | private byte dataBits;
23 |
24 | private DataBits(int dataBits) {
25 | this.dataBits = (byte) dataBits;
26 | }
27 |
28 | byte getDataBits() {
29 | return dataBits;
30 | }
31 | }
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/Parity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | public enum Parity {
20 | NONE(0), ODD(1), EVEN(2), MARK(3), SPACE(4);
21 |
22 | private byte parity;
23 |
24 | private Parity(int parity) {
25 | this.parity = (byte) parity;
26 | }
27 |
28 | byte getParity() {
29 | return parity;
30 | }
31 | }
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/StopBits.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | public enum StopBits {
20 | STOP_BITS_1(0), STOP_BITS_1_5(1), STOP_BITS_2(2);
21 |
22 | private byte stopBits;
23 |
24 | private StopBits(int stopBits) {
25 | this.stopBits = (byte) stopBits;
26 | }
27 |
28 | byte getStopBits() {
29 | return stopBits;
30 | }
31 | }
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/UsbDeviceDetachedReceiver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | import android.content.BroadcastReceiver;
20 | import android.content.Context;
21 | import android.content.Intent;
22 | import android.hardware.usb.UsbDevice;
23 | import android.hardware.usb.UsbManager;
24 | import org.apache.commons.logging.Log;
25 | import org.apache.commons.logging.LogFactory;
26 | import org.ros.exception.RosRuntimeException;
27 |
28 | import java.util.Map;
29 |
30 | /**
31 | * @author damonkohler@google.com (Damon Kohler)
32 | */
33 | final class UsbDeviceDetachedReceiver extends BroadcastReceiver {
34 |
35 | private static final boolean DEBUG = true;
36 | private static final Log log = LogFactory.getLog(UsbDeviceDetachedReceiver.class);
37 |
38 | private final Map acmDevices;
39 |
40 | public UsbDeviceDetachedReceiver(Map acmDevices) {
41 | this.acmDevices = acmDevices;
42 | }
43 |
44 | @Override
45 | public void onReceive(Context context, Intent intent) {
46 | UsbDevice usbDevice = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
47 | String deviceName = usbDevice.getDeviceName();
48 | AcmDevice acmDevice = acmDevices.remove(deviceName);
49 | if (acmDevice != null) {
50 | try {
51 | acmDevice.close();
52 | } catch (RosRuntimeException e) {
53 | // Ignore spurious errors on disconnect.
54 | }
55 | }
56 | if (DEBUG) {
57 | log.info("USB device removed: " + deviceName);
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/UsbDevicePermissionCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | import android.hardware.usb.UsbDevice;
20 |
21 | /**
22 | * @author damonkohler@google.com (Damon Kohler)
23 | */
24 | public interface UsbDevicePermissionCallback {
25 |
26 | void onPermissionGranted(UsbDevice device);
27 |
28 | void onPermissionDenied();
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/UsbDevicePermissionReceiver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | import android.content.BroadcastReceiver;
20 | import android.content.Context;
21 | import android.content.Intent;
22 | import android.hardware.usb.UsbDevice;
23 | import android.hardware.usb.UsbManager;
24 |
25 | /**
26 | * @author damonkohler@google.com (Damon Kohler)
27 | */
28 | class UsbDevicePermissionReceiver extends BroadcastReceiver {
29 |
30 | private final UsbDevicePermissionCallback callback;
31 |
32 | public UsbDevicePermissionReceiver(UsbDevicePermissionCallback callback) {
33 | this.callback = callback;
34 | }
35 |
36 | @Override
37 | public void onReceive(Context context, Intent intent) {
38 | String action = intent.getAction();
39 | if (AcmDeviceActivity.ACTION_USB_PERMISSION.equals(action)) {
40 | synchronized (this) {
41 | if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
42 | UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
43 | callback.onPermissionGranted(device);
44 | } else {
45 | callback.onPermissionDenied();
46 | }
47 | }
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/UsbRequestCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | import android.hardware.usb.UsbRequest;
20 |
21 | /**
22 | * @author damonkohler@google.com (Damon Kohler)
23 | */
24 | public interface UsbRequestCallback {
25 |
26 | void onRequestComplete(UsbRequest request);
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/UsbRequestPool.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | import com.google.common.base.Preconditions;
20 | import com.google.common.collect.Maps;
21 |
22 | import android.hardware.usb.UsbDeviceConnection;
23 | import android.hardware.usb.UsbEndpoint;
24 | import android.hardware.usb.UsbRequest;
25 | import android.util.Log;
26 |
27 | import java.util.Map;
28 |
29 | class UsbRequestPool {
30 |
31 | private static final boolean DEBUG = false;
32 | private static final String TAG = "UsbRequestPool";
33 |
34 | private final UsbDeviceConnection connection;
35 | private final Map usbRequestQueues;
36 | private final RequestWaitThread requestWaitThread;
37 |
38 | private final class RequestWaitThread extends Thread {
39 | @Override
40 | public void run() {
41 | while (!Thread.currentThread().isInterrupted()) {
42 | UsbRequest request;
43 | try {
44 | request = connection.requestWait();
45 | } catch (NullPointerException e) {
46 | // NOTE(damonkohler): There appears to be a bug around
47 | // UsbRequest.java:155 that can cause a spurious NPE. This seems safe
48 | // to ignore.
49 | if (DEBUG) {
50 | Log.e(TAG, "NPE while waiting for UsbRequest.", e);
51 | }
52 | continue;
53 | }
54 | if (request != null) {
55 | UsbEndpoint endpoint = request.getEndpoint();
56 | if (endpoint != null) {
57 | Preconditions.checkState(usbRequestQueues.containsKey(endpoint));
58 | usbRequestQueues.get(endpoint).add(request);
59 | } else {
60 | Log.e(TAG, "Completed UsbRequest is no longer open.");
61 | }
62 | } else {
63 | Log.e(TAG, "USB request error.");
64 | }
65 | if (DEBUG) {
66 | Log.d(TAG, "USB request completed.");
67 | }
68 | }
69 | }
70 | }
71 |
72 | public UsbRequestPool(UsbDeviceConnection connection) {
73 | this.connection = connection;
74 | usbRequestQueues = Maps.newConcurrentMap();
75 | requestWaitThread = new RequestWaitThread();
76 | }
77 |
78 | public void addEndpoint(UsbEndpoint endpoint, UsbRequestCallback callback) {
79 | usbRequestQueues.put(endpoint, new UsbRequestQueue(connection, endpoint, callback));
80 | }
81 |
82 | public UsbRequest poll(UsbEndpoint endpoint) {
83 | Preconditions.checkArgument(usbRequestQueues.containsKey(endpoint),
84 | "Call addEndpoint() before the first call to poll().");
85 | UsbRequestQueue queue = usbRequestQueues.get(endpoint);
86 | UsbRequest request = queue.poll();
87 | return request;
88 | }
89 |
90 | public void start() {
91 | requestWaitThread.start();
92 | }
93 |
94 | public void shutdown() {
95 | requestWaitThread.interrupt();
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/android_acm_serial/src/org/ros/android/android_acm_serial/UsbRequestQueue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_acm_serial;
18 |
19 | import android.hardware.usb.UsbDeviceConnection;
20 | import android.hardware.usb.UsbEndpoint;
21 | import android.hardware.usb.UsbRequest;
22 | import android.util.Log;
23 | import org.ros.exception.RosRuntimeException;
24 |
25 | import java.util.Queue;
26 | import java.util.concurrent.ConcurrentLinkedQueue;
27 |
28 | /**
29 | * @author damonkohler@google.com (Damon Kohler)
30 | */
31 | class UsbRequestQueue {
32 |
33 | private static final boolean DEBUG = false;
34 | private static final String TAG = "UsbRequestQueue";
35 |
36 | private final UsbDeviceConnection connection;
37 | private final UsbEndpoint endpoint;
38 | private final UsbRequestCallback callback;
39 | private final Queue queue;
40 |
41 | public UsbRequestQueue(UsbDeviceConnection connection, UsbEndpoint endpoint,
42 | UsbRequestCallback callback) {
43 | this.connection = connection;
44 | this.endpoint = endpoint;
45 | this.callback = callback;
46 | queue = new ConcurrentLinkedQueue();
47 | }
48 |
49 | public void add(UsbRequest request) {
50 | if (callback != null) {
51 | callback.onRequestComplete(request);
52 | }
53 | queue.add(request);
54 | if (DEBUG) {
55 | Log.d(TAG, "USB request added.");
56 | }
57 | }
58 |
59 | public UsbRequest poll() {
60 | UsbRequest request = queue.poll();
61 | if (request == null) {
62 | request = new UsbRequest();
63 | if (!request.initialize(connection, endpoint)) {
64 | throw new RosRuntimeException("Failed to open UsbRequest.");
65 | }
66 | }
67 | return request;
68 | }
69 | }
--------------------------------------------------------------------------------
/android_benchmarks/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/android_benchmarks/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | dependencies {
18 | compile 'org.ros.rosjava_core:rosjava_benchmarks:[0.3,0.4)'
19 | compile project(':android_core_components')
20 | }
21 |
22 | apply plugin: 'com.android.application'
23 |
24 | android {
25 | compileSdkVersion 28
26 |
27 | defaultConfig {
28 | minSdkVersion 16
29 | applicationId "org.ros.android.android_benchmarks"
30 | targetSdkVersion 28
31 | versionCode 1
32 | versionName "1.0"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/android_benchmarks/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/android_benchmarks/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Benchmarks
5 |
6 |
--------------------------------------------------------------------------------
/android_benchmarks/src/org/ros/android/android_benchmarks/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_benchmarks;
18 |
19 | import android.os.Bundle;
20 | import org.ros.android.MessageCallable;
21 | import org.ros.android.RosActivity;
22 | import org.ros.android.view.RosTextView;
23 | import org.ros.node.NodeConfiguration;
24 | import org.ros.node.NodeMainExecutor;
25 | import org.ros.rosjava_benchmarks.MessagesBenchmark;
26 |
27 | /**
28 | * @author damonkohler@google.com (Damon Kohler)
29 | */
30 | public class MainActivity extends RosActivity {
31 |
32 | private RosTextView rosTextView;
33 |
34 | public MainActivity() {
35 | super("Benchmarks", "Benchmarks");
36 | }
37 |
38 | @SuppressWarnings("unchecked")
39 | @Override
40 | public void onCreate(Bundle savedInstanceState) {
41 | super.onCreate(savedInstanceState);
42 | setContentView(R.layout.main);
43 | rosTextView = (RosTextView) findViewById(R.id.text);
44 | rosTextView.setTopicName("status");
45 | rosTextView.setMessageType(std_msgs.String._TYPE);
46 | rosTextView.setMessageToStringCallable(new MessageCallable() {
47 | @Override
48 | public String call(std_msgs.String message) {
49 | return message.getData();
50 | }
51 | });
52 | }
53 |
54 | @Override
55 | protected void init(NodeMainExecutor nodeMainExecutor) {
56 | NodeConfiguration nodeConfiguration = NodeConfiguration.newPrivate();
57 | nodeConfiguration.setMasterUri(getMasterUri());
58 | nodeMainExecutor.execute(rosTextView, nodeConfiguration);
59 | // TODO(damonkohler): Support launching different benchmarks via the UI.
60 | // nodeMainExecutor.execute(new PubsubBenchmark(), nodeConfiguration);
61 | // nodeMainExecutor.execute(new TransformBenchmark(), nodeConfiguration);
62 | nodeMainExecutor.execute(new MessagesBenchmark(), nodeConfiguration);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/android_core_components/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
18 |
23 |
24 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/android_core_components/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | dependencies {
18 | compile "org.ros.rosjava_core:rosjava:[0.3.2,0.4)"
19 | compile "org.ros.rosjava_messages:diagnostic_msgs:[1.12,1.13)"
20 | compile "org.ros.rosjava_messages:sensor_msgs:[1.12,1.13)"
21 | compile 'org.ros.rosjava_core:rosjava_geometry:[0.3,0.4)'
22 | compile 'org.ros.rosjava_messages:visualization_msgs:[1.12,1.13)'
23 | compile "com.android.support:appcompat-v7:28.0.0"
24 | compile 'com.android.support:support-v4:28.0.0'
25 | }
26 |
27 | apply plugin: "com.android.library"
28 |
29 | android {
30 | compileSdkVersion 28
31 |
32 | defaultConfig {
33 | minSdkVersion 16
34 | targetSdkVersion 28
35 | versionCode 1
36 | versionName "1.0"
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/android_core_components/res/drawable/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/background.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/black_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/black_background.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/center_widget.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/center_widget.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/directional_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/directional_arrow.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/error.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/grey_ring_notched.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/grey_ring_notched.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/horizon_original.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/horizon_original.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/intensity.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/intensity.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/large_d_widget_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/large_d_widget_3.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/large_pan_marker_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/large_pan_marker_3.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/large_tilt_marker_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/large_tilt_marker_3.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/mid_angle_slice.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/mid_angle_slice.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/ok.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/ok.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/pan_tilt_controller.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/pan_tilt_controller.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/pan_tilt_follower.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/pan_tilt_follower.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/previous_velocity.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/previous_velocity.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/pt_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/pt_bg.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/pt_home_marker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/pt_home_marker.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/rotate_left_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/rotate_left_icon.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/rotate_right_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/rotate_right_icon.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/small_d_widget_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/small_d_widget_3.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/small_pan_marker_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/small_pan_marker_3.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/small_tilt_marker_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/small_tilt_marker_3.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/stale.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/stale.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/top_angle_slice.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/top_angle_slice.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/warn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/warn.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/zoom_bar_lit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/zoom_bar_lit.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/zoom_bar_notlit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/zoom_bar_notlit.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/zoom_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/zoom_bg.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/zoom_in_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/zoom_in_normal.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/zoom_in_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/zoom_in_pressed.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/zoom_out_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/zoom_out_normal.png
--------------------------------------------------------------------------------
/android_core_components/res/drawable/zoom_out_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/drawable/zoom_out_pressed.png
--------------------------------------------------------------------------------
/android_core_components/res/mipmap-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/mipmap-hdpi/icon.png
--------------------------------------------------------------------------------
/android_core_components/res/mipmap-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/mipmap-ldpi/icon.png
--------------------------------------------------------------------------------
/android_core_components/res/mipmap-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/android_core_components/res/mipmap-mdpi/icon.png
--------------------------------------------------------------------------------
/android_core_components/res/values/common_strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ROS for Android
5 | Connect
6 | Cancel
7 | Read QRCode
8 | http://localhost:11311/
9 | New Public Master
10 | New Private Master
11 | Show advanced options
12 | Select network interface
13 | Master URI:
14 | Trying to reach master…
15 |
16 |
17 |
--------------------------------------------------------------------------------
/android_core_components/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/AppCompatRosActivity.java:
--------------------------------------------------------------------------------
1 | package org.ros.android;
2 |
3 | import android.content.res.Configuration;
4 | import android.os.Bundle;
5 | import android.support.annotation.LayoutRes;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.app.ActionBar;
8 | import android.support.v7.app.AppCompatDelegate;
9 | import android.support.v7.widget.Toolbar;
10 | import android.view.MenuInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 |
14 | import java.net.URI;
15 |
16 | /**
17 | * A RosActivity which implements and proxies the necessary calls
18 | * to be used with AppCompat.
19 | */
20 | public abstract class AppCompatRosActivity extends RosActivity {
21 | private AppCompatDelegate mDelegate;
22 |
23 | public AppCompatRosActivity() {
24 | super("", "");
25 | }
26 |
27 | protected AppCompatRosActivity(String notificationTicker, String notificationTitle) {
28 | super(notificationTicker, notificationTitle);
29 | }
30 |
31 | protected AppCompatRosActivity(String notificationTicker, String notificationTitle, URI customMasterUri) {
32 | super(notificationTicker, notificationTitle, customMasterUri);
33 | }
34 |
35 | protected AppCompatRosActivity(String notificationTicker, String notificationTitle, Class> activity, int requestCode) {
36 | super(notificationTicker, notificationTitle, activity, requestCode);
37 | }
38 |
39 | @Override
40 | protected void onCreate(Bundle savedInstanceState) {
41 | getDelegate().installViewFactory();
42 | getDelegate().onCreate(savedInstanceState);
43 | super.onCreate(savedInstanceState);
44 | }
45 | @Override
46 | protected void onPostCreate(Bundle savedInstanceState) {
47 | super.onPostCreate(savedInstanceState);
48 | getDelegate().onPostCreate(savedInstanceState);
49 | }
50 | public ActionBar getSupportActionBar() {
51 | return getDelegate().getSupportActionBar();
52 | }
53 | public void setSupportActionBar(@Nullable Toolbar toolbar) {
54 | getDelegate().setSupportActionBar(toolbar);
55 | }
56 | @Override
57 | public MenuInflater getMenuInflater() {
58 | return getDelegate().getMenuInflater();
59 | }
60 | @Override
61 | public void setContentView(@LayoutRes int layoutResID) {
62 | getDelegate().setContentView(layoutResID);
63 | }
64 | @Override
65 | public void setContentView(View view) {
66 | getDelegate().setContentView(view);
67 | }
68 | @Override
69 | public void setContentView(View view, ViewGroup.LayoutParams params) {
70 | getDelegate().setContentView(view, params);
71 | }
72 | @Override
73 | public void addContentView(View view, ViewGroup.LayoutParams params) {
74 | getDelegate().addContentView(view, params);
75 | }
76 | @Override
77 | protected void onPostResume() {
78 | super.onPostResume();
79 | getDelegate().onPostResume();
80 | }
81 | @Override
82 | protected void onTitleChanged(CharSequence title, int color) {
83 | super.onTitleChanged(title, color);
84 | getDelegate().setTitle(title);
85 | }
86 | @Override
87 | public void onConfigurationChanged(Configuration newConfig) {
88 | super.onConfigurationChanged(newConfig);
89 | getDelegate().onConfigurationChanged(newConfig);
90 | }
91 | @Override
92 | protected void onStop() {
93 | super.onStop();
94 | getDelegate().onStop();
95 | }
96 | @Override
97 | protected void onDestroy() {
98 | super.onDestroy();
99 | getDelegate().onDestroy();
100 | }
101 | public void invalidateOptionsMenu() {
102 | getDelegate().invalidateOptionsMenu();
103 | }
104 | private AppCompatDelegate getDelegate() {
105 | if (mDelegate == null) {
106 | mDelegate = AppCompatDelegate.create(this, null);
107 | }
108 | return mDelegate;
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/BitmapFromCompressedImage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android;
18 |
19 | import android.graphics.Bitmap;
20 | import android.graphics.BitmapFactory;
21 | import org.jboss.netty.buffer.ChannelBuffer;
22 |
23 | /**
24 | * @author damonkohler@google.com (Damon Kohler)
25 | */
26 | public class BitmapFromCompressedImage implements
27 | MessageCallable {
28 |
29 | @Override
30 | public Bitmap call(sensor_msgs.CompressedImage message) {
31 | ChannelBuffer buffer = message.getData();
32 | byte[] data = buffer.array();
33 | return BitmapFactory.decodeByteArray(data, buffer.arrayOffset(), buffer.readableBytes());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/BitmapFromImage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android;
18 |
19 | import com.google.common.base.Preconditions;
20 |
21 | import android.graphics.Bitmap;
22 | import android.graphics.Color;
23 | import org.jboss.netty.buffer.ChannelBuffer;
24 |
25 | /**
26 | * @author damonkohler@google.com (Damon Kohler)
27 | */
28 | public class BitmapFromImage implements MessageCallable {
29 |
30 | @Override
31 | public Bitmap call(sensor_msgs.Image message) {
32 | Preconditions.checkArgument(message.getEncoding().equals("rgb8"));
33 | Bitmap bitmap =
34 | Bitmap.createBitmap((int) message.getWidth(), (int) message.getHeight(),
35 | Bitmap.Config.ARGB_8888);
36 | for (int x = 0; x < message.getWidth(); x++) {
37 | for (int y = 0; y < message.getHeight(); y++) {
38 | ChannelBuffer data = message.getData();
39 | byte red = data.getByte((int) (y * message.getStep() + 3 * x));
40 | byte green = data.getByte((int) (y * message.getStep() + 3 * x + 1));
41 | byte blue = data.getByte((int) (y * message.getStep() + 3 * x + 2));
42 | bitmap.setPixel(x, y, Color.argb(255, red & 0xFF, green & 0xFF, blue & 0xFF));
43 | }
44 | }
45 | return bitmap;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/MessageCallable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android;
18 |
19 | /**
20 | * @author damonkohler@google.com (Damon Kohler)
21 | *
22 | * @param
23 | * the return type
24 | * @param
25 | * the message type
26 | */
27 | public interface MessageCallable {
28 |
29 | T call(S message);
30 | }
31 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/NodeMainExecutorListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android;
18 |
19 | import org.ros.node.NodeMainExecutor;
20 |
21 | /**
22 | * @author damonkohler@google.com (Damon Kohler)
23 | */
24 | public interface NodeMainExecutorListener {
25 |
26 | /**
27 | * @param nodeMainExecutor
28 | * the newly created {@link NodeMainExecutor}
29 | */
30 | void onNewNodeMainExecutor(NodeMainExecutor nodeMainExecutor);
31 | }
32 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/NodeMainExecutorServiceListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android;
18 |
19 | /**
20 | * @author damonkohler@google.com (Damon Kohler)
21 | */
22 | public interface NodeMainExecutorServiceListener {
23 |
24 | /**
25 | * @param nodeMainExecutorService the {@link NodeMainExecutorService} that was shut down
26 | */
27 | void onShutdown(NodeMainExecutorService nodeMainExecutorService);
28 | }
29 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/OrientationPublisher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android;
18 |
19 | import android.hardware.Sensor;
20 | import android.hardware.SensorEvent;
21 | import android.hardware.SensorEventListener;
22 | import android.hardware.SensorManager;
23 | import geometry_msgs.PoseStamped;
24 | import org.ros.message.Time;
25 | import org.ros.namespace.GraphName;
26 | import org.ros.node.AbstractNodeMain;
27 | import org.ros.node.ConnectedNode;
28 | import org.ros.node.topic.Publisher;
29 |
30 | /**
31 | * @author damonkohler@google.com (Damon Kohler)
32 | */
33 | public class OrientationPublisher extends AbstractNodeMain {
34 |
35 | private final SensorManager sensorManager;
36 |
37 | private OrientationListener orientationListener;
38 |
39 | private final class OrientationListener implements SensorEventListener {
40 |
41 | private final Publisher publisher;
42 |
43 | private OrientationListener(Publisher publisher) {
44 | this.publisher = publisher;
45 | }
46 |
47 | @Override
48 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
49 | }
50 |
51 | @Override
52 | public void onSensorChanged(SensorEvent event) {
53 | if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
54 | float[] quaternion = new float[4];
55 | SensorManager.getQuaternionFromVector(quaternion, event.values);
56 | PoseStamped pose = publisher.newMessage();
57 | pose.getHeader().setFrameId("/map");
58 | // TODO(damonkohler): Should get time from the Node.
59 | pose.getHeader().setStamp(Time.fromMillis(System.currentTimeMillis()));
60 | pose.getPose().getOrientation().setW(quaternion[0]);
61 | pose.getPose().getOrientation().setX(quaternion[1]);
62 | pose.getPose().getOrientation().setY(quaternion[2]);
63 | pose.getPose().getOrientation().setZ(quaternion[3]);
64 | publisher.publish(pose);
65 | }
66 | }
67 | }
68 |
69 | public OrientationPublisher(SensorManager sensorManager) {
70 | this.sensorManager = sensorManager;
71 | }
72 |
73 | @Override
74 | public GraphName getDefaultNodeName() {
75 | return GraphName.of("android/orientiation_sensor");
76 | }
77 |
78 | @Override
79 | public void onStart(ConnectedNode connectedNode) {
80 | try {
81 | Publisher publisher =
82 | connectedNode.newPublisher("android/orientation", "geometry_msgs/PoseStamped");
83 | orientationListener = new OrientationListener(publisher);
84 | Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
85 | // 10 Hz
86 | sensorManager.registerListener(orientationListener, sensor, 500000);
87 | } catch (Exception e) {
88 | connectedNode.getLog().fatal(e);
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/RosImageView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view;
18 |
19 | import android.content.Context;
20 | import android.graphics.Bitmap;
21 | import android.util.AttributeSet;
22 | import android.widget.ImageView;
23 | import org.ros.android.MessageCallable;
24 | import org.ros.message.MessageListener;
25 | import org.ros.namespace.GraphName;
26 | import org.ros.node.ConnectedNode;
27 | import org.ros.node.Node;
28 | import org.ros.node.NodeMain;
29 | import org.ros.node.topic.Subscriber;
30 |
31 | /**
32 | * Displays incoming sensor_msgs/CompressedImage messages.
33 | *
34 | * @author ethan.rublee@gmail.com (Ethan Rublee)
35 | * @author damonkohler@google.com (Damon Kohler)
36 | */
37 | public class RosImageView extends ImageView implements NodeMain {
38 |
39 | private String topicName;
40 | private String messageType;
41 | private MessageCallable callable;
42 |
43 | public RosImageView(Context context) {
44 | super(context);
45 | }
46 |
47 | public RosImageView(Context context, AttributeSet attrs) {
48 | super(context, attrs);
49 | }
50 |
51 | public RosImageView(Context context, AttributeSet attrs, int defStyle) {
52 | super(context, attrs, defStyle);
53 | }
54 |
55 | public void setTopicName(String topicName) {
56 | this.topicName = topicName;
57 | }
58 |
59 | public void setMessageType(String messageType) {
60 | this.messageType = messageType;
61 | }
62 |
63 | public void setMessageToBitmapCallable(MessageCallable callable) {
64 | this.callable = callable;
65 | }
66 |
67 | @Override
68 | public GraphName getDefaultNodeName() {
69 | return GraphName.of("ros_image_view");
70 | }
71 |
72 | @Override
73 | public void onStart(ConnectedNode connectedNode) {
74 | Subscriber subscriber = connectedNode.newSubscriber(topicName, messageType);
75 | subscriber.addMessageListener(new MessageListener() {
76 | @Override
77 | public void onNewMessage(final T message) {
78 | post(new Runnable() {
79 | @Override
80 | public void run() {
81 | setImageBitmap(callable.call(message));
82 | }
83 | });
84 | postInvalidate();
85 | }
86 | });
87 | }
88 |
89 | @Override
90 | public void onShutdown(Node node) {
91 | }
92 |
93 | @Override
94 | public void onShutdownComplete(Node node) {
95 | }
96 |
97 | @Override
98 | public void onError(Node node, Throwable throwable) {
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/RosTextView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view;
18 |
19 | import android.content.Context;
20 | import android.util.AttributeSet;
21 | import android.widget.TextView;
22 | import org.ros.android.MessageCallable;
23 | import org.ros.message.MessageListener;
24 | import org.ros.namespace.GraphName;
25 | import org.ros.node.ConnectedNode;
26 | import org.ros.node.Node;
27 | import org.ros.node.NodeMain;
28 | import org.ros.node.topic.Subscriber;
29 |
30 | /**
31 | * @author damonkohler@google.com (Damon Kohler)
32 | */
33 | public class RosTextView extends TextView implements NodeMain {
34 |
35 | private String topicName;
36 | private String messageType;
37 | private MessageCallable callable;
38 |
39 | public RosTextView(Context context) {
40 | super(context);
41 | }
42 |
43 | public RosTextView(Context context, AttributeSet attrs) {
44 | super(context, attrs);
45 | }
46 |
47 | public RosTextView(Context context, AttributeSet attrs, int defStyle) {
48 | super(context, attrs, defStyle);
49 | }
50 |
51 | public void setTopicName(String topicName) {
52 | this.topicName = topicName;
53 | }
54 |
55 | public void setMessageType(String messageType) {
56 | this.messageType = messageType;
57 | }
58 |
59 | public void setMessageToStringCallable(MessageCallable callable) {
60 | this.callable = callable;
61 | }
62 |
63 | @Override
64 | public GraphName getDefaultNodeName() {
65 | return GraphName.of("android_gingerbread/ros_text_view");
66 | }
67 |
68 | @Override
69 | public void onStart(ConnectedNode connectedNode) {
70 | Subscriber subscriber = connectedNode.newSubscriber(topicName, messageType);
71 | subscriber.addMessageListener(new MessageListener() {
72 | @Override
73 | public void onNewMessage(final T message) {
74 | if (callable != null) {
75 | post(new Runnable() {
76 | @Override
77 | public void run() {
78 | setText(callable.call(message));
79 | }
80 | });
81 | } else {
82 | post(new Runnable() {
83 | @Override
84 | public void run() {
85 | setText(message.toString());
86 | }
87 | });
88 | }
89 | postInvalidate();
90 | }
91 | });
92 | }
93 |
94 | @Override
95 | public void onShutdown(Node node) {
96 | }
97 |
98 | @Override
99 | public void onShutdownComplete(Node node) {
100 | }
101 |
102 | @Override
103 | public void onError(Node node, Throwable throwable) {
104 | }
105 | }
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/ZoomMode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view;
18 |
19 | /**
20 | * @author munjaldesai@google.com (Munjal Desai)
21 | */
22 | public enum ZoomMode {
23 | /**
24 | * In the CLUTTER_ZOOM_MODE the {@link DistanceView} will auto adjust the
25 | * level of zoom based on proximity to objects near by. The view will zoom in
26 | * further when there are objects closer to the robot and vice versa.
27 | */
28 | CLUTTER_ZOOM_MODE,
29 | /**
30 | * In the VELOCITY_ZOOM_MODE the {@link DistanceView} will auto adjust the
31 | * level of zoom based on the current linear velocity of the robot. The faster
32 | * the robot moves the move zoomed out the view will be.
33 | */
34 | VELOCITY_ZOOM_MODE,
35 | /**
36 | * In CUSTOM_ZOOM_MODE the {@link DistanceView} allows the user to change the
37 | * zoom level via pinch and reverse-pinch gestures.
38 | */
39 | CUSTOM_ZOOM_MODE
40 | }
41 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/camera/CompressedImagePublisher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.camera;
18 |
19 | import com.google.common.base.Preconditions;
20 |
21 | import android.graphics.ImageFormat;
22 | import android.graphics.Rect;
23 | import android.graphics.YuvImage;
24 | import android.hardware.Camera.Size;
25 | import org.jboss.netty.buffer.ChannelBufferOutputStream;
26 | import org.ros.internal.message.MessageBuffers;
27 | import org.ros.message.Time;
28 | import org.ros.namespace.NameResolver;
29 | import org.ros.node.ConnectedNode;
30 | import org.ros.node.topic.Publisher;
31 |
32 | /**
33 | * Publishes preview frames.
34 | *
35 | * @author damonkohler@google.com (Damon Kohler)
36 | */
37 | class CompressedImagePublisher implements RawImageListener {
38 |
39 | private final ConnectedNode connectedNode;
40 | private final Publisher imagePublisher;
41 | private final Publisher cameraInfoPublisher;
42 |
43 | private byte[] rawImageBuffer;
44 | private Size rawImageSize;
45 | private YuvImage yuvImage;
46 | private Rect rect;
47 | private ChannelBufferOutputStream stream;
48 |
49 | public CompressedImagePublisher(ConnectedNode connectedNode) {
50 | this.connectedNode = connectedNode;
51 | NameResolver resolver = connectedNode.getResolver().newChild("camera");
52 | imagePublisher =
53 | connectedNode.newPublisher(resolver.resolve("image/compressed"),
54 | sensor_msgs.CompressedImage._TYPE);
55 | cameraInfoPublisher =
56 | connectedNode.newPublisher(resolver.resolve("camera_info"), sensor_msgs.CameraInfo._TYPE);
57 | stream = new ChannelBufferOutputStream(MessageBuffers.dynamicBuffer());
58 | }
59 |
60 | @Override
61 | public void onNewRawImage(byte[] data, Size size) {
62 | Preconditions.checkNotNull(data);
63 | Preconditions.checkNotNull(size);
64 | if (data != rawImageBuffer || !size.equals(rawImageSize)) {
65 | rawImageBuffer = data;
66 | rawImageSize = size;
67 | yuvImage = new YuvImage(rawImageBuffer, ImageFormat.NV21, size.width, size.height, null);
68 | rect = new Rect(0, 0, size.width, size.height);
69 | }
70 |
71 | Time currentTime = connectedNode.getCurrentTime();
72 | String frameId = "camera";
73 |
74 | sensor_msgs.CompressedImage image = imagePublisher.newMessage();
75 | image.setFormat("jpeg");
76 | image.getHeader().setStamp(currentTime);
77 | image.getHeader().setFrameId(frameId);
78 |
79 | Preconditions.checkState(yuvImage.compressToJpeg(rect, 20, stream));
80 | image.setData(stream.buffer().copy());
81 | stream.buffer().clear();
82 |
83 | imagePublisher.publish(image);
84 |
85 | sensor_msgs.CameraInfo cameraInfo = cameraInfoPublisher.newMessage();
86 | cameraInfo.getHeader().setStamp(currentTime);
87 | cameraInfo.getHeader().setFrameId(frameId);
88 |
89 | cameraInfo.setWidth(size.width);
90 | cameraInfo.setHeight(size.height);
91 | cameraInfoPublisher.publish(cameraInfo);
92 | }
93 | }
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/camera/RawImageListener.java:
--------------------------------------------------------------------------------
1 | package org.ros.android.view.camera;
2 |
3 | import android.hardware.Camera.Size;
4 |
5 | interface RawImageListener {
6 |
7 | void onNewRawImage(byte[] data, Size size);
8 |
9 | }
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/camera/RosCameraPreviewView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.camera;
18 |
19 | import android.content.Context;
20 | import android.util.AttributeSet;
21 | import org.ros.namespace.GraphName;
22 | import org.ros.node.ConnectedNode;
23 | import org.ros.node.Node;
24 | import org.ros.node.NodeMain;
25 |
26 | /**
27 | * Displays and publishes preview frames from the camera.
28 | *
29 | * @author damonkohler@google.com (Damon Kohler)
30 | */
31 | public class RosCameraPreviewView extends CameraPreviewView implements NodeMain {
32 |
33 | public RosCameraPreviewView(Context context) {
34 | super(context);
35 | }
36 |
37 | public RosCameraPreviewView(Context context, AttributeSet attrs) {
38 | super(context, attrs);
39 | }
40 |
41 | public RosCameraPreviewView(Context context, AttributeSet attrs, int defStyle) {
42 | super(context, attrs, defStyle);
43 | }
44 |
45 | @Override
46 | public GraphName getDefaultNodeName() {
47 | return GraphName.of("ros_camera_preview_view");
48 | }
49 |
50 | @Override
51 | public void onStart(ConnectedNode connectedNode) {
52 | setRawImageListener(new CompressedImagePublisher(connectedNode));
53 | }
54 |
55 | @Override
56 | public void onShutdown(Node node) {
57 | }
58 |
59 | @Override
60 | public void onShutdownComplete(Node node) {
61 | }
62 |
63 | @Override
64 | public void onError(Node node, Throwable throwable) {
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/Color.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization;
18 |
19 | import com.google.common.base.Preconditions;
20 |
21 | import javax.microedition.khronos.opengles.GL10;
22 |
23 | /**
24 | * Defines a color based on RGBA values in the range [0, 1].
25 | *
26 | * @author damonkohler@google.com (Damon Kohler)
27 | */
28 | public class Color {
29 |
30 | private float red;
31 | private float green;
32 | private float blue;
33 | private float alpha;
34 |
35 | public static Color copyOf(Color color) {
36 | return new Color(color.red, color.green, color.blue, color.alpha);
37 | }
38 |
39 | public static Color fromHexAndAlpha(String hex, float alpha) {
40 | Preconditions.checkArgument(hex.length() == 6);
41 | float red = Integer.parseInt(hex.substring(0, 2), 16) / 255.0f;
42 | float green = Integer.parseInt(hex.substring(2, 4), 16) / 255.0f;
43 | float blue = Integer.parseInt(hex.substring(4), 16) / 255.0f;
44 | return new Color(red, green, blue, alpha);
45 | }
46 |
47 | public Color(float red, float green, float blue, float alpha) {
48 | Preconditions.checkArgument(0.0f <= red && red <= 1.0f);
49 | Preconditions.checkArgument(0.0f <= green && green <= 1.0f);
50 | Preconditions.checkArgument(0.0f <= blue && blue <= 1.0f);
51 | Preconditions.checkArgument(0.0f <= alpha && alpha <= 1.0f);
52 | this.red = red;
53 | this.green = green;
54 | this.blue = blue;
55 | this.alpha = alpha;
56 | }
57 |
58 | public void apply(GL10 gl) {
59 | gl.glColor4f(red, green, blue, alpha);
60 | }
61 |
62 | public float getRed() {
63 | return red;
64 | }
65 |
66 | public void setRed(float red) {
67 | this.red = red;
68 | }
69 |
70 | public float getGreen() {
71 | return green;
72 | }
73 |
74 | public void setGreen(float green) {
75 | this.green = green;
76 | }
77 |
78 | public float getBlue() {
79 | return blue;
80 | }
81 |
82 | public void setBlue(float blue) {
83 | this.blue = blue;
84 | }
85 |
86 | public float getAlpha() {
87 | return alpha;
88 | }
89 |
90 | public void setAlpha(float alpha) {
91 | this.alpha = alpha;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/OpenGlDrawable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization;
18 |
19 | import javax.microedition.khronos.opengles.GL10;
20 |
21 | /**
22 | * @author damonkohler@google.com (Damon Kohler)
23 | */
24 | public interface OpenGlDrawable {
25 | void draw(VisualizationView view, GL10 gl);
26 | }
27 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/OpenGlTransform.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization;
18 |
19 | import org.ros.rosjava_geometry.Transform;
20 |
21 | import java.nio.FloatBuffer;
22 |
23 | import javax.microedition.khronos.opengles.GL10;
24 |
25 | /**
26 | * An adapter for applying {@link Transform}s in an OpenGL context.
27 | *
28 | * @author damonkohler@google.com (Damon Kohler)
29 | * @author moesenle@google.com (Lorenz Moesenlechner)
30 | */
31 | public class OpenGlTransform {
32 |
33 | private static final ThreadLocal buffer = new ThreadLocal() {
34 | @Override
35 | protected FloatBuffer initialValue() {
36 | return FloatBuffer.allocate(16);
37 | };
38 |
39 | @Override
40 | public FloatBuffer get() {
41 | FloatBuffer buffer = super.get();
42 | buffer.clear();
43 | return buffer;
44 | };
45 | };
46 |
47 | private OpenGlTransform() {
48 | // Utility class.
49 | }
50 |
51 | /**
52 | * Applies a {@link Transform} to an OpenGL context.
53 | *
54 | * @param gl
55 | * the context
56 | * @param transform
57 | * the {@link Transform} to apply
58 | */
59 | public static void apply(GL10 gl, Transform transform) {
60 | FloatBuffer matrix = buffer.get();
61 | for (double value : transform.toMatrix()) {
62 | matrix.put((float) value);
63 | }
64 | matrix.position(0);
65 | gl.glMultMatrixf(matrix);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/RotateGestureDetector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization;
18 |
19 | import android.view.MotionEvent;
20 | import org.ros.math.RosMath;
21 |
22 | /**
23 | * @author damonkohler@google.com (Damon Kohler)
24 | */
25 | public class RotateGestureDetector {
26 |
27 | public interface OnRotateGestureListener {
28 | boolean onRotate(MotionEvent event1, MotionEvent event2, double deltaAngle);
29 | }
30 |
31 | private static final double MAX_DELTA_ANGLE = 1e-1;
32 |
33 | private final OnRotateGestureListener listener;
34 |
35 | private MotionEvent previousMotionEvent;
36 |
37 | public RotateGestureDetector(OnRotateGestureListener listener) {
38 | this.listener = listener;
39 | }
40 |
41 | private double angle(MotionEvent event) {
42 | double deltaX = (event.getX(0) - event.getX(1));
43 | double deltaY = (event.getY(0) - event.getY(1));
44 | return Math.atan2(deltaY, deltaX);
45 | }
46 |
47 | public boolean onTouchEvent(MotionEvent event) {
48 | if (event.getPointerCount() != 2) {
49 | return false;
50 | }
51 | if (previousMotionEvent == null) {
52 | previousMotionEvent = MotionEvent.obtain(event);
53 | return false;
54 | }
55 | double deltaAngle =
56 | RosMath.clamp(angle(previousMotionEvent) - angle(event), -MAX_DELTA_ANGLE, MAX_DELTA_ANGLE);
57 | boolean result = listener.onRotate(previousMotionEvent, event, deltaAngle);
58 | previousMotionEvent.recycle();
59 | previousMotionEvent = MotionEvent.obtain(event);
60 | return result;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/Vertices.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization;
18 |
19 | import com.google.common.base.Preconditions;
20 |
21 | import java.nio.ByteBuffer;
22 | import java.nio.ByteOrder;
23 | import java.nio.FloatBuffer;
24 |
25 | import javax.microedition.khronos.opengles.GL10;
26 |
27 | /**
28 | * @author damonkohler@google.com (Damon Kohler)
29 | */
30 | public class Vertices {
31 |
32 | private static final int FLOAT_BYTE_SIZE = Float.SIZE / 8;
33 |
34 | private Vertices() {
35 | // Utility class.
36 | }
37 |
38 | public static FloatBuffer allocateBuffer(int size) {
39 | ByteBuffer byteBuffer = ByteBuffer.allocateDirect(size * FLOAT_BYTE_SIZE);
40 | byteBuffer.order(ByteOrder.nativeOrder());
41 | return byteBuffer.asFloatBuffer();
42 | }
43 |
44 | public static FloatBuffer toFloatBuffer(float[] floats) {
45 | FloatBuffer floatBuffer = allocateBuffer(floats.length);
46 | floatBuffer.put(floats);
47 | floatBuffer.position(0);
48 | return floatBuffer;
49 | }
50 |
51 | public static void drawPoints(GL10 gl, FloatBuffer vertices, Color color, float size) {
52 | vertices.mark();
53 | color.apply(gl);
54 | gl.glPointSize(size);
55 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
56 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);
57 | gl.glDrawArrays(GL10.GL_POINTS, 0, countVertices(vertices, 3));
58 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
59 | vertices.reset();
60 | }
61 |
62 | public static void drawTriangleFan(GL10 gl, FloatBuffer vertices, Color color) {
63 | vertices.mark();
64 | color.apply(gl);
65 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
66 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);
67 | gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, countVertices(vertices, 3));
68 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
69 | vertices.reset();
70 | }
71 |
72 | public static void drawLineLoop(GL10 gl, FloatBuffer vertices, Color color, float width) {
73 | vertices.mark();
74 | color.apply(gl);
75 | gl.glLineWidth(width);
76 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
77 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);
78 | gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, countVertices(vertices, 3));
79 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
80 | vertices.reset();
81 | }
82 |
83 | public static void drawLines(GL10 gl, FloatBuffer vertices, Color color, float width) {
84 | vertices.mark();
85 | color.apply(gl);
86 | gl.glLineWidth(width);
87 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
88 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);
89 | gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, countVertices(vertices, 3));
90 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
91 | vertices.reset();
92 | }
93 |
94 | private static int countVertices(FloatBuffer vertices, int size) {
95 | // FloatBuffer accounts for the size of each float when calling remaining().
96 | Preconditions.checkArgument(vertices.remaining() % size == 0,
97 | "Number of vertices: " + vertices.remaining());
98 | return vertices.remaining() / size;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/Viewport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization;
18 |
19 | import javax.microedition.khronos.opengles.GL10;
20 |
21 | /**
22 | * @author damonkohler@google.com (Damon Kohler)
23 | */
24 | public class Viewport {
25 |
26 | private final int width;
27 | private final int height;
28 |
29 | public Viewport(int width, int height) {
30 | this.width = width;
31 | this.height = height;
32 | }
33 |
34 | public void apply(GL10 gl) {
35 | gl.glViewport(0, 0, width, height);
36 | // Set the perspective projection to be orthographic.
37 | gl.glMatrixMode(GL10.GL_PROJECTION);
38 | gl.glLoadIdentity();
39 | // This corrects for the aspect ratio of the viewport. The viewport can now
40 | // be reasoned about in pixels. The zNear and zFar only need to be
41 | // sufficiently large to avoid clipping. The z-buffer is not otherwise used.
42 | gl.glOrthof(-width / 2.0f, width / 2.0f, -height / 2.0f, height / 2.0f, -1e4f, 1e4f);
43 | }
44 |
45 | public int getWidth() {
46 | return width;
47 | }
48 |
49 | public int getHeight() {
50 | return height;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/XYOrthographicRenderer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization;
18 |
19 | import android.opengl.GLSurfaceView;
20 | import org.ros.android.view.visualization.layer.Layer;
21 | import org.ros.android.view.visualization.layer.TfLayer;
22 | import org.ros.namespace.GraphName;
23 |
24 | import javax.microedition.khronos.egl.EGLConfig;
25 | import javax.microedition.khronos.opengles.GL10;
26 |
27 | /**
28 | * Renders all layers of a navigation view.
29 | *
30 | * @author damonkohler@google.com (Damon Kohler)
31 | * @author moesenle@google.com (Lorenz Moesenlechner)
32 | */
33 | public class XYOrthographicRenderer implements GLSurfaceView.Renderer {
34 |
35 | private static final Color BACKGROUND_COLOR = new Color(0.87f, 0.87f, 0.87f, 1.f);
36 |
37 | private final VisualizationView view;
38 |
39 | public XYOrthographicRenderer(VisualizationView view) {
40 | this.view = view;
41 | }
42 |
43 | @Override
44 | public void onSurfaceChanged(GL10 gl, int width, int height) {
45 | Viewport viewport = new Viewport(width, height);
46 | viewport.apply(gl);
47 | view.getCamera().setViewport(viewport);
48 | gl.glMatrixMode(GL10.GL_MODELVIEW);
49 | gl.glEnable(GL10.GL_BLEND);
50 | gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
51 | gl.glDisable(GL10.GL_DEPTH_TEST);
52 | gl.glClearColor(BACKGROUND_COLOR.getRed(), BACKGROUND_COLOR.getGreen(),
53 | BACKGROUND_COLOR.getBlue(), BACKGROUND_COLOR.getAlpha());
54 | for (Layer layer : view.getLayers()) {
55 | layer.onSurfaceChanged(view, gl, width, height);
56 | }
57 | }
58 |
59 | @Override
60 | public void onDrawFrame(GL10 gl) {
61 | gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
62 | gl.glLoadIdentity();
63 | view.getCamera().apply(gl);
64 | drawLayers(gl);
65 | }
66 |
67 | private void drawLayers(GL10 gl) {
68 | for (Layer layer : view.getLayers()) {
69 | gl.glPushMatrix();
70 | if (layer instanceof TfLayer) {
71 | GraphName layerFrame = ((TfLayer) layer).getFrame();
72 | if (layerFrame != null && view.getCamera().applyFrameTransform(gl, layerFrame)) {
73 | layer.draw(view, gl);
74 | }
75 | } else {
76 | layer.draw(view, gl);
77 | }
78 | gl.glPopMatrix();
79 | }
80 | }
81 |
82 | @Override
83 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
84 | for (Layer layer : view.getLayers()) {
85 | layer.onSurfaceCreated(view, gl, config);
86 | }
87 | }
88 | }
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/layer/CameraControlListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.layer;
18 |
19 | /**
20 | * @author damonkohler@google.com (Damon Kohler)
21 | */
22 | public interface CameraControlListener {
23 | void onTranslate(float distanceX, float distanceY);
24 |
25 | void onRotate(float focusX, float focusY, double deltaAngle);
26 |
27 | void onZoom(float focusX, float focusY, float factor);
28 |
29 | void onDoubleTap(float x, float y);
30 | }
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/layer/CompressedOccupancyGridLayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.layer;
18 |
19 | import com.google.common.base.Preconditions;
20 |
21 | import org.ros.android.view.visualization.VisualizationView;
22 | import android.graphics.Bitmap;
23 | import android.graphics.BitmapFactory;
24 | import org.jboss.netty.buffer.ChannelBuffer;
25 | import org.ros.android.view.visualization.TextureBitmap;
26 | import org.ros.message.MessageListener;
27 | import org.ros.namespace.GraphName;
28 | import org.ros.node.ConnectedNode;
29 | import org.ros.rosjava_geometry.Transform;
30 |
31 | import javax.microedition.khronos.opengles.GL10;
32 |
33 | /**
34 | * @author damonkohler@google.com (Damon Kohler)
35 | * @author moesenle@google.com (Lorenz Moesenlechner)
36 | */
37 | public class CompressedOccupancyGridLayer extends SubscriberLayer implements
38 | TfLayer {
39 |
40 | /**
41 | * Color of occupied cells in the map.
42 | */
43 | private static final int COLOR_OCCUPIED = 0xdfffffff;
44 |
45 | /**
46 | * Color of free cells in the map.
47 | */
48 | private static final int COLOR_FREE = 0xff8d8d8d;
49 |
50 | /**
51 | * Color of unknown cells in the map.
52 | */
53 | private static final int COLOR_UNKNOWN = 0xff000000;
54 |
55 | private final TextureBitmap textureBitmap;
56 |
57 | private boolean ready;
58 | private GraphName frame;
59 |
60 | public CompressedOccupancyGridLayer(String topic) {
61 | this(GraphName.of(topic));
62 | }
63 |
64 | public CompressedOccupancyGridLayer(GraphName topic) {
65 | super(topic, nav_msgs.OccupancyGrid._TYPE);
66 | textureBitmap = new TextureBitmap();
67 | ready = false;
68 | }
69 |
70 | @Override
71 | public void draw(VisualizationView view, GL10 gl) {
72 | if (ready) {
73 | textureBitmap.draw(view, gl);
74 | }
75 | }
76 |
77 | @Override
78 | public GraphName getFrame() {
79 | return frame;
80 | }
81 |
82 | @Override
83 | public void onStart(VisualizationView view, ConnectedNode connectedNode) {
84 | super.onStart(view, connectedNode);
85 | getSubscriber().addMessageListener(new MessageListener() {
86 | @Override
87 | public void onNewMessage(nav_msgs.OccupancyGrid message) {
88 | update(message);
89 | }
90 | });
91 | }
92 |
93 | void update(nav_msgs.OccupancyGrid message) {
94 | ChannelBuffer buffer = message.getData();
95 | Bitmap bitmap =
96 | BitmapFactory.decodeByteArray(buffer.array(), buffer.arrayOffset(), buffer.readableBytes());
97 | int stride = bitmap.getWidth();
98 | int height = bitmap.getHeight();
99 | Preconditions.checkArgument(stride <= 1024);
100 | Preconditions.checkArgument(height <= 1024);
101 | int[] pixels = new int[stride * height];
102 | bitmap.getPixels(pixels, 0, stride, 0, 0, stride, height);
103 | for (int i = 0; i < pixels.length; i++) {
104 | // Pixels are ARGB packed ints.
105 | if (pixels[i] == 0xffffffff) {
106 | pixels[i] = COLOR_UNKNOWN;
107 | } else if (pixels[i] == 0xff000000) {
108 | pixels[i] = COLOR_FREE;
109 | } else {
110 | pixels[i] = COLOR_OCCUPIED;
111 | }
112 | }
113 | float resolution = message.getInfo().getResolution();
114 | Transform origin = Transform.fromPoseMessage(message.getInfo().getOrigin());
115 | textureBitmap.updateFromPixelArray(pixels, stride, resolution, origin, COLOR_UNKNOWN);
116 | frame = GraphName.of(message.getHeader().getFrameId());
117 | ready = true;
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/layer/DefaultLayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.layer;
18 |
19 | import android.view.MotionEvent;
20 | import org.ros.android.view.visualization.VisualizationView;
21 | import org.ros.node.ConnectedNode;
22 | import org.ros.node.Node;
23 | import org.ros.node.NodeMainExecutor;
24 |
25 | import javax.microedition.khronos.egl.EGLConfig;
26 | import javax.microedition.khronos.opengles.GL10;
27 |
28 | /**
29 | * Base class for visualization layers.
30 | *
31 | * @author moesenle@google.com (Lorenz Moesenlechner)
32 | */
33 | public abstract class DefaultLayer implements Layer {
34 |
35 | @Override
36 | public void init(NodeMainExecutor nodeMainExecutor) {
37 | }
38 |
39 | @Override
40 | public void draw(VisualizationView view, GL10 gl) {
41 | }
42 |
43 | @Override
44 | public boolean onTouchEvent(VisualizationView view, MotionEvent event) {
45 | return false;
46 | }
47 |
48 | @Override
49 | public void onStart(VisualizationView view, ConnectedNode connectedNode) {
50 | }
51 |
52 | @Override
53 | public void onShutdown(VisualizationView view, Node node) {
54 | }
55 |
56 | @Override
57 | public void onSurfaceChanged(VisualizationView view, GL10 gl, int width, int height) {
58 | }
59 |
60 | @Override
61 | public void onSurfaceCreated(VisualizationView view, GL10 gl, EGLConfig config) {
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/layer/GridCellsLayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.layer;
18 |
19 | import org.ros.android.view.visualization.Color;
20 | import org.ros.android.view.visualization.Vertices;
21 | import org.ros.android.view.visualization.VisualizationView;
22 | import org.ros.android.view.visualization.XYOrthographicCamera;
23 | import org.ros.message.MessageListener;
24 | import org.ros.namespace.GraphName;
25 | import org.ros.node.ConnectedNode;
26 |
27 | import java.util.concurrent.locks.Lock;
28 | import java.util.concurrent.locks.ReentrantLock;
29 |
30 | import javax.microedition.khronos.opengles.GL10;
31 |
32 | /**
33 | * @author damonkohler@google.com (Damon Kohler)
34 | */
35 | public class GridCellsLayer extends SubscriberLayer implements TfLayer {
36 |
37 | private final Color color;
38 | private final Lock lock;
39 |
40 | private GraphName frame;
41 | private XYOrthographicCamera camera;
42 | private boolean ready;
43 | private nav_msgs.GridCells message;
44 |
45 | public GridCellsLayer(String topicName, Color color) {
46 | this(GraphName.of(topicName), color);
47 | }
48 |
49 | public GridCellsLayer(GraphName topicName, Color color) {
50 | super(topicName, "nav_msgs/GridCells");
51 | this.color = color;
52 | frame = null;
53 | lock = new ReentrantLock();
54 | ready = false;
55 | }
56 |
57 | @Override
58 | public void draw(VisualizationView view, GL10 gl) {
59 | if (!ready) {
60 | return;
61 | }
62 | super.draw(view, gl);
63 | lock.lock();
64 | float pointSize =
65 | (float) (Math.max(message.getCellWidth(), message.getCellHeight()) * camera.getZoom());
66 | float[] vertices = new float[3 * message.getCells().size()];
67 | int i = 0;
68 | for (geometry_msgs.Point cell : message.getCells()) {
69 | vertices[i] = (float) cell.getX();
70 | vertices[i + 1] = (float) cell.getY();
71 | vertices[i + 2] = 0.0f;
72 | i += 3;
73 | }
74 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
75 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, Vertices.toFloatBuffer(vertices));
76 | color.apply(gl);
77 | gl.glPointSize(pointSize);
78 | gl.glDrawArrays(GL10.GL_POINTS, 0, message.getCells().size());
79 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
80 | lock.unlock();
81 | }
82 |
83 | @Override
84 | public void onStart(final VisualizationView view, ConnectedNode connectedNode) {
85 | super.onStart(view, connectedNode);
86 | getSubscriber().addMessageListener(new MessageListener() {
87 | @Override
88 | public void onNewMessage(nav_msgs.GridCells data) {
89 | frame = GraphName.of(data.getHeader().getFrameId());
90 | if (view.getFrameTransformTree().lookUp(frame) != null) {
91 | if (lock.tryLock()) {
92 | message = data;
93 | ready = true;
94 | lock.unlock();
95 | }
96 | }
97 | }
98 | });
99 | }
100 |
101 | @Override
102 | public GraphName getFrame() {
103 | return frame;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/layer/Layer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.layer;
18 |
19 | import android.opengl.GLSurfaceView;
20 | import android.view.MotionEvent;
21 | import org.ros.android.RosActivity;
22 | import org.ros.android.view.visualization.OpenGlDrawable;
23 | import org.ros.android.view.visualization.VisualizationView;
24 | import org.ros.node.ConnectedNode;
25 | import org.ros.node.Node;
26 | import org.ros.node.NodeMainExecutor;
27 |
28 | import javax.microedition.khronos.egl.EGLConfig;
29 | import javax.microedition.khronos.opengles.GL10;
30 |
31 | /**
32 | * Interface for a drawable layer on a VisualizationView.
33 | *
34 | * @author moesenle@google.com (Lorenz Moesenlechner)
35 | */
36 | public interface Layer extends OpenGlDrawable {
37 |
38 | /**
39 | * @see RosActivity#init(NodeMainExecutor)
40 | */
41 | void init(NodeMainExecutor nodeMainExecutor);
42 |
43 | /**
44 | * Event handler for touch events.
45 | *
46 | * @param view
47 | * the view generating the event
48 | * @param event
49 | * the touch event
50 | * @return true if the event has been handled
51 | */
52 | boolean onTouchEvent(VisualizationView view, MotionEvent event);
53 |
54 | /**
55 | * Called when the layer is added to the {@link VisualizationView}.
56 | */
57 | void onStart(VisualizationView view, ConnectedNode connectedNode);
58 |
59 | /**
60 | * Called when the view is removed from the {@link VisualizationView}.
61 | */
62 | void onShutdown(VisualizationView view, Node node);
63 |
64 | /**
65 | * @param view
66 | * the {@link VisualizationView} associated with the
67 | * {@link GLSurfaceView.Renderer}
68 | * @see GLSurfaceView.Renderer#onSurfaceCreated(GL10, EGLConfig)
69 | */
70 | void onSurfaceCreated(VisualizationView view, GL10 gl, EGLConfig config);
71 |
72 | /**
73 | * @param view
74 | * the {@link VisualizationView} associated with the
75 | * {@link GLSurfaceView.Renderer}
76 | * @see GLSurfaceView.Renderer#onSurfaceChanged(GL10, int, int)
77 | */
78 | void onSurfaceChanged(VisualizationView view, GL10 gl, int width, int height);
79 | }
80 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/layer/PathLayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.layer;
18 |
19 | import org.ros.android.view.visualization.VisualizationView;
20 | import org.ros.android.view.visualization.Color;
21 | import geometry_msgs.PoseStamped;
22 | import org.ros.message.MessageListener;
23 | import org.ros.namespace.GraphName;
24 | import org.ros.node.ConnectedNode;
25 |
26 | import java.nio.ByteBuffer;
27 | import java.nio.ByteOrder;
28 | import java.nio.FloatBuffer;
29 |
30 | import javax.microedition.khronos.opengles.GL10;
31 |
32 | /**
33 | * Renders a nav_msgs/Path as a solid line.
34 | *
35 | * @author moesenle@google.com (Lorenz Moesenlechner)
36 | * @author damonkohler@google.com (Damon Kohler)
37 | */
38 | public class PathLayer extends SubscriberLayer implements TfLayer {
39 |
40 | private static final Color COLOR = Color.fromHexAndAlpha("03dfc9", 0.3f);
41 | private static final float LINE_WIDTH = 4.0f;
42 |
43 | private FloatBuffer vertexBuffer;
44 | private int numPoints;
45 | private boolean ready;
46 | private GraphName frame;
47 |
48 | public PathLayer(String topic) {
49 | this(GraphName.of(topic));
50 | }
51 |
52 | public PathLayer(GraphName topic) {
53 | super(topic, "nav_msgs/Path");
54 | ready = false;
55 | numPoints = 0;
56 | }
57 |
58 | @Override
59 | public void draw(VisualizationView view, GL10 gl) {
60 | if (ready) {
61 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
62 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
63 | COLOR.apply(gl);
64 | gl.glLineWidth(LINE_WIDTH);
65 | gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, numPoints);
66 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
67 | }
68 | }
69 |
70 | @Override
71 | public void onStart(VisualizationView view, ConnectedNode connectedNode) {
72 | super.onStart(view, connectedNode);
73 | getSubscriber().addMessageListener(new MessageListener() {
74 | @Override
75 | public void onNewMessage(nav_msgs.Path path) {
76 | updateVertexBuffer(path);
77 | ready = true;
78 | }
79 | });
80 | }
81 |
82 | private void updateVertexBuffer(nav_msgs.Path path) {
83 | ByteBuffer goalVertexByteBuffer =
84 | ByteBuffer.allocateDirect(path.getPoses().size() * 3 * Float.SIZE);
85 | goalVertexByteBuffer.order(ByteOrder.nativeOrder());
86 | vertexBuffer = goalVertexByteBuffer.asFloatBuffer();
87 | int i = 0;
88 | if (path.getPoses().size() > 0) {
89 | frame = GraphName.of(path.getPoses().get(0).getHeader().getFrameId());
90 | for (PoseStamped pose : path.getPoses()) {
91 | vertexBuffer.put((float) pose.getPose().getPosition().getX());
92 | vertexBuffer.put((float) pose.getPose().getPosition().getY());
93 | vertexBuffer.put((float) pose.getPose().getPosition().getZ());
94 | i++;
95 | }
96 | }
97 | vertexBuffer.position(0);
98 | numPoints = i;
99 | }
100 |
101 | @Override
102 | public GraphName getFrame() {
103 | return frame;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/layer/PosePublisherLayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.layer;
18 |
19 | import com.google.common.base.Preconditions;
20 |
21 | import android.view.GestureDetector;
22 | import android.view.MotionEvent;
23 | import org.ros.android.view.visualization.VisualizationView;
24 | import org.ros.android.view.visualization.shape.PixelSpacePoseShape;
25 | import org.ros.android.view.visualization.shape.Shape;
26 | import org.ros.namespace.GraphName;
27 | import org.ros.node.ConnectedNode;
28 | import org.ros.node.Node;
29 | import org.ros.node.topic.Publisher;
30 | import org.ros.rosjava_geometry.Transform;
31 | import org.ros.rosjava_geometry.Vector3;
32 |
33 | import javax.microedition.khronos.opengles.GL10;
34 |
35 | /**
36 | * @author moesenle@google.com (Lorenz Moesenlechner)
37 | */
38 | public class PosePublisherLayer extends DefaultLayer {
39 |
40 | private Shape shape;
41 | private Publisher posePublisher;
42 | private boolean visible;
43 | private GraphName topic;
44 | private GestureDetector gestureDetector;
45 | private Transform pose;
46 | private ConnectedNode connectedNode;
47 |
48 | public PosePublisherLayer(String topic) {
49 | this(GraphName.of(topic));
50 | }
51 |
52 | public PosePublisherLayer(GraphName topic) {
53 | this.topic = topic;
54 | visible = false;
55 | }
56 |
57 | @Override
58 | public void draw(VisualizationView view, GL10 gl) {
59 | if (visible) {
60 | Preconditions.checkNotNull(pose);
61 | shape.draw(view, gl);
62 | }
63 | }
64 |
65 | private double angle(double x1, double y1, double x2, double y2) {
66 | double deltaX = x1 - x2;
67 | double deltaY = y1 - y2;
68 | return Math.atan2(deltaY, deltaX);
69 | }
70 |
71 | @Override
72 | public boolean onTouchEvent(VisualizationView view, MotionEvent event) {
73 | if (visible) {
74 | Preconditions.checkNotNull(pose);
75 | if (event.getAction() == MotionEvent.ACTION_MOVE) {
76 | Vector3 poseVector = pose.apply(Vector3.zero());
77 | Vector3 pointerVector =
78 | view.getCamera().toCameraFrame((int) event.getX(), (int) event.getY());
79 | double angle =
80 | angle(pointerVector.getX(), pointerVector.getY(), poseVector.getX(), poseVector.getY());
81 | pose = Transform.translation(poseVector).multiply(Transform.zRotation(angle));
82 | shape.setTransform(pose);
83 | return true;
84 | }
85 | if (event.getAction() == MotionEvent.ACTION_UP) {
86 | posePublisher.publish(pose.toPoseStampedMessage(view.getCamera().getFrame(),
87 | connectedNode.getCurrentTime(), posePublisher.newMessage()));
88 | visible = false;
89 | return true;
90 | }
91 | }
92 | gestureDetector.onTouchEvent(event);
93 | return false;
94 | }
95 |
96 | @Override
97 | public void onStart(final VisualizationView view, ConnectedNode connectedNode) {
98 | this.connectedNode = connectedNode;
99 | shape = new PixelSpacePoseShape();
100 | posePublisher = connectedNode.newPublisher(topic, geometry_msgs.PoseStamped._TYPE);
101 | view.post(new Runnable() {
102 | @Override
103 | public void run() {
104 | gestureDetector =
105 | new GestureDetector(view.getContext(), new GestureDetector.SimpleOnGestureListener() {
106 | @Override
107 | public void onLongPress(MotionEvent e) {
108 | pose =
109 | Transform.translation(view.getCamera().toCameraFrame((int) e.getX(),
110 | (int) e.getY()));
111 | shape.setTransform(pose);
112 | visible = true;
113 | }
114 | });
115 | }
116 | });
117 | }
118 |
119 | @Override
120 | public void onShutdown(VisualizationView view, Node node) {
121 | posePublisher.shutdown();
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/layer/PoseSubscriberLayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.layer;
18 |
19 | import org.ros.android.view.visualization.VisualizationView;
20 | import org.ros.android.view.visualization.shape.GoalShape;
21 | import org.ros.android.view.visualization.shape.Shape;
22 | import org.ros.message.MessageListener;
23 | import org.ros.namespace.GraphName;
24 | import org.ros.node.ConnectedNode;
25 | import org.ros.rosjava_geometry.FrameTransform;
26 | import org.ros.rosjava_geometry.Transform;
27 |
28 | import javax.microedition.khronos.opengles.GL10;
29 |
30 | /**
31 | * @author moesenle@google.com (Lorenz Moesenlechner)
32 | */
33 | public class PoseSubscriberLayer extends SubscriberLayer implements
34 | TfLayer {
35 |
36 | private final GraphName targetFrame;
37 |
38 | private Shape shape;
39 | private boolean ready;
40 |
41 | public PoseSubscriberLayer(String topic) {
42 | this(GraphName.of(topic));
43 | }
44 |
45 | public PoseSubscriberLayer(GraphName topic) {
46 | super(topic, geometry_msgs.PoseStamped._TYPE);
47 | targetFrame = GraphName.of("map");
48 | ready = false;
49 | }
50 |
51 | @Override
52 | public void draw(VisualizationView view, GL10 gl) {
53 | if (ready) {
54 | shape.draw(view, gl);
55 | }
56 | }
57 |
58 | @Override
59 | public void onStart(final VisualizationView view, ConnectedNode connectedNode) {
60 | super.onStart(view, connectedNode);
61 | shape = new GoalShape();
62 | getSubscriber().addMessageListener(new MessageListener() {
63 | @Override
64 | public void onNewMessage(geometry_msgs.PoseStamped pose) {
65 | GraphName source = GraphName.of(pose.getHeader().getFrameId());
66 | FrameTransform frameTransform = view.getFrameTransformTree().transform(source, targetFrame);
67 | if (frameTransform != null) {
68 | Transform poseTransform = Transform.fromPoseMessage(pose.getPose());
69 | shape.setTransform(frameTransform.getTransform().multiply(poseTransform));
70 | ready = true;
71 | }
72 | }
73 | });
74 | }
75 |
76 | @Override
77 | public GraphName getFrame() {
78 | return targetFrame;
79 | }
80 | }
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/layer/RobotLayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.layer;
18 |
19 | import org.ros.android.view.visualization.VisualizationView;
20 | import org.ros.android.view.visualization.shape.PixelSpacePoseShape;
21 | import org.ros.android.view.visualization.shape.Shape;
22 | import org.ros.namespace.GraphName;
23 | import org.ros.node.ConnectedNode;
24 |
25 | import javax.microedition.khronos.opengles.GL10;
26 |
27 | /**
28 | * @author moesenle@google.com (Lorenz Moesenlechner)
29 | */
30 | public class RobotLayer extends DefaultLayer implements TfLayer {
31 |
32 | private final GraphName frame;
33 |
34 | private Shape shape;
35 |
36 | public RobotLayer(GraphName frame) {
37 | this.frame = frame;
38 | }
39 |
40 | public RobotLayer(String frame) {
41 | this(GraphName.of(frame));
42 | }
43 |
44 | @Override
45 | public void draw(VisualizationView view, GL10 gl) {
46 | if (shape != null) {
47 | shape.draw(view, gl);
48 | }
49 | }
50 |
51 | @Override
52 | public void onStart(VisualizationView view, ConnectedNode connectedNode) {
53 | shape = new PixelSpacePoseShape();
54 | }
55 |
56 | @Override
57 | public GraphName getFrame() {
58 | return frame;
59 | }
60 | }
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/layer/SubscriberLayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.layer;
18 |
19 | import com.google.common.base.Preconditions;
20 |
21 | import org.ros.android.view.visualization.VisualizationView;
22 | import org.ros.namespace.GraphName;
23 | import org.ros.node.ConnectedNode;
24 | import org.ros.node.Node;
25 | import org.ros.node.topic.Subscriber;
26 |
27 | /**
28 | * @author damonkohler@google.com (Damon Kohler)
29 | */
30 | public class SubscriberLayer extends DefaultLayer {
31 |
32 | private final GraphName topicName;
33 | private final String messageType;
34 |
35 | private Subscriber subscriber;
36 |
37 | public SubscriberLayer(GraphName topicName, String messageType) {
38 | this.topicName = topicName;
39 | this.messageType = messageType;
40 | }
41 |
42 | @Override
43 | public void onStart(VisualizationView view, ConnectedNode connectedNode) {
44 | super.onStart(view, connectedNode);
45 | subscriber = connectedNode.newSubscriber(topicName, messageType);
46 | }
47 |
48 | @Override
49 | public void onShutdown(VisualizationView view, Node node) {
50 | subscriber.shutdown();
51 | super.onShutdown(view, node);
52 | }
53 |
54 | public Subscriber getSubscriber() {
55 | Preconditions.checkNotNull(subscriber);
56 | return subscriber;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/layer/TfLayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.layer;
18 |
19 | import org.ros.namespace.GraphName;
20 |
21 | /**
22 | * Interface for layers that are positioned by using Tf.
23 | *
24 | * @author moesenle@google.com (Lorenz Moesenlechner)
25 | */
26 | public interface TfLayer {
27 |
28 | /**
29 | * @return the {@link Layer}'s reference frame
30 | */
31 | GraphName getFrame();
32 | }
33 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/shape/BaseShape.java:
--------------------------------------------------------------------------------
1 | package org.ros.android.view.visualization.shape;
2 |
3 | import com.google.common.base.Preconditions;
4 |
5 | import org.ros.android.view.visualization.Color;
6 | import org.ros.android.view.visualization.OpenGlTransform;
7 | import org.ros.android.view.visualization.VisualizationView;
8 | import org.ros.rosjava_geometry.Transform;
9 |
10 | import javax.microedition.khronos.opengles.GL10;
11 |
12 | /**
13 | * Defines the getters and setters that are required for all {@link Shape}
14 | * implementors.
15 | *
16 | * @author damonkohler@google.com (Damon Kohler)
17 | */
18 | abstract class BaseShape implements Shape {
19 |
20 | private Color color;
21 | private Transform transform;
22 |
23 | public BaseShape() {
24 | setTransform(Transform.identity());
25 | }
26 |
27 | @Override
28 | public void draw(VisualizationView view, GL10 gl) {
29 | gl.glPushMatrix();
30 | OpenGlTransform.apply(gl, getTransform());
31 | scale(view, gl);
32 | drawShape(view, gl);
33 | gl.glPopMatrix();
34 | }
35 |
36 | /**
37 | * To be implemented by children. Draws the shape after the shape's
38 | * transform and scaling have been applied.
39 | */
40 | abstract protected void drawShape(VisualizationView view, GL10 gl);
41 |
42 | /**
43 | * Scales the coordinate system.
44 | *
45 | * This is called after transforming the surface according to
46 | * {@link #transform}.
47 | */
48 | protected void scale(VisualizationView view, GL10 gl) {
49 | // The default scale is in metric space.
50 | }
51 |
52 | @Override
53 | public Color getColor() {
54 | Preconditions.checkNotNull(color);
55 | return color;
56 | }
57 |
58 | @Override
59 | public void setColor(Color color) {
60 | this.color = color;
61 | }
62 |
63 | @Override
64 | public Transform getTransform() {
65 | Preconditions.checkNotNull(transform);
66 | return transform;
67 | }
68 |
69 | @Override
70 | public void setTransform(Transform pose) {
71 | this.transform = pose;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/shape/GoalShape.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.shape;
18 |
19 | import org.ros.android.view.visualization.Color;
20 |
21 | /**
22 | * Represents the robot's current goal pose.
23 | *
24 | * @author damonkohler@google.com (Damon Kohler)
25 | */
26 | public class GoalShape extends MetricSpacePoseShape {
27 |
28 | private static final Color COLOR = Color.fromHexAndAlpha("03d5c9", 0.3f);
29 |
30 | public GoalShape() {
31 | super();
32 | setColor(COLOR);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/shape/MetricSpacePoiShape.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.shape;
18 |
19 | import org.ros.android.view.visualization.Color;
20 |
21 | /**
22 | * Represents a pose.
23 | *
24 | * @author damonkohler@google.com (Damon Kohler)
25 | */
26 | public class MetricSpacePoiShape extends TriangleFanShape {
27 |
28 | private static final Color COLOR = Color.fromHexAndAlpha("377dfa", 1.0f);
29 | private static final float VERTICES[] = {
30 | -0.2f, 0.2f, 0.f,
31 | 0.2f, 0.2f, 0.f,
32 | 0.5f, 0.f, 0.f,
33 | 0.2f, -0.2f, 0.f,
34 | -0.2f, -0.2f, 0.f,
35 | -0.2f, 0.2f, 0.f
36 | };
37 |
38 | public MetricSpacePoiShape() {
39 | super(VERTICES, COLOR);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/shape/MetricSpacePolygon.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.shape;
18 |
19 | import com.google.common.base.Preconditions;
20 | import com.google.common.collect.Lists;
21 |
22 | import org.ros.android.view.visualization.Color;
23 | import org.ros.android.view.visualization.Vertices;
24 | import org.ros.android.view.visualization.VisualizationView;
25 |
26 | import java.nio.FloatBuffer;
27 | import java.util.List;
28 |
29 | import javax.microedition.khronos.opengles.GL10;
30 |
31 | /**
32 | * A polygon with metric space vertices.
33 | *
34 | * @author damonkohler@google.com (Damon Kohler)
35 | */
36 | public class MetricSpacePolygon extends BaseShape {
37 |
38 | final FloatBuffer vertexBuffer;
39 | final List triangles;
40 |
41 | public MetricSpacePolygon(final float[] vertices, final Color color) {
42 | super();
43 | vertexBuffer = Vertices.toFloatBuffer(vertices);
44 | setColor(color);
45 |
46 | final List points = Lists.newArrayList();
47 | final Triangulate.Point[] contour = new Triangulate.Point[vertices.length / 3];
48 | for (int i = 0; i < contour.length; ++i) {
49 | contour[i] = new Triangulate.Point(vertices[i * 3], vertices[i * 3 + 1]);
50 | }
51 | Preconditions.checkState(Triangulate.process(contour, points));
52 |
53 | triangles = Lists.newArrayList();
54 | for (int i = 0; i < points.size() / 3; ++i) {
55 | final FloatBuffer triangle = Vertices.allocateBuffer(3 * 3);
56 | for (int j = i * 3; j < i * 3 + 3; ++j) {
57 | triangle.put(points.get(j).x());
58 | triangle.put(points.get(j).y());
59 | triangle.put(0.f);
60 | }
61 | triangle.flip();
62 | triangles.add(triangle);
63 | }
64 | }
65 |
66 | @Override
67 | public void drawShape(VisualizationView view, GL10 gl) {
68 | final Color translucent = getColor();
69 | translucent.setAlpha(0.3f);
70 | for (final FloatBuffer triangle : triangles) {
71 | Vertices.drawTriangleFan(gl, triangle, translucent);
72 | }
73 | final Color opaque = getColor();
74 | opaque.setAlpha(1.f);
75 | Vertices.drawLineLoop(gl, vertexBuffer, opaque, 3.f);
76 | Vertices.drawPoints(gl, vertexBuffer, opaque, 10.f);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/shape/MetricSpacePoseShape.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.shape;
18 |
19 | import org.ros.android.view.visualization.Color;
20 |
21 | /**
22 | * Represents a pose.
23 | *
24 | * @author damonkohler@google.com (Damon Kohler)
25 | */
26 | public class MetricSpacePoseShape extends TriangleFanShape {
27 |
28 | private static final Color COLOR = Color.fromHexAndAlpha("377dfa", 1.0f);
29 | private static final float VERTICES[] = {
30 | 0.2f, 0.f, 0.f,
31 | -0.2f, -0.15f, 0.f,
32 | -0.05f, 0.f, 0.f,
33 | -0.2f, 0.15f, 0.f,
34 | 0.2f, 0.f, 0.f
35 | };
36 |
37 | public MetricSpacePoseShape() {
38 | super(VERTICES, COLOR);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/shape/PixelSpacePoiShape.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.shape;
18 |
19 | import org.ros.android.view.visualization.VisualizationView;
20 |
21 | import javax.microedition.khronos.opengles.GL10;
22 |
23 | /**
24 | * Represents a pose.
25 | *
26 | * This shape is defined in pixel space and will not be affected by the zoom
27 | * level of the camera.
28 | *
29 | * @author damonkohler@google.com (Damon Kohler)
30 | */
31 | public class PixelSpacePoiShape extends MetricSpacePoiShape {
32 |
33 | private static final float PIXELS_PER_METER = 100.f;
34 |
35 | @Override
36 | protected void scale(VisualizationView view, GL10 gl) {
37 | // Adjust for metric scale definition of MetricSpacePoseShape vertices.
38 | gl.glScalef(PIXELS_PER_METER, PIXELS_PER_METER, 1.f);
39 | // Counter adjust for the camera zoom.
40 | gl.glScalef(1 / (float) view.getCamera().getZoom(), 1 / (float) view.getCamera().getZoom(),
41 | 1.0f);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/shape/PixelSpacePoseShape.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.shape;
18 |
19 | import org.ros.android.view.visualization.VisualizationView;
20 |
21 | import javax.microedition.khronos.opengles.GL10;
22 |
23 | /**
24 | * Represents a pose.
25 | *
26 | * This shape is defined in pixel space and will not be affected by the zoom
27 | * level of the camera.
28 | *
29 | * @author damonkohler@google.com (Damon Kohler)
30 | */
31 | public class PixelSpacePoseShape extends MetricSpacePoseShape {
32 |
33 | private static final float PIXELS_PER_METER = 250.f;
34 |
35 | @Override
36 | protected void scale(VisualizationView view, GL10 gl) {
37 | // Adjust for metric scale definition of MetricSpacePoseShape vertices.
38 | gl.glScalef(PIXELS_PER_METER, 250.f, 1.f);
39 | // Counter adjust for the camera zoom.
40 | gl.glScalef(1 / (float) view.getCamera().getZoom(), 1 / (float) view.getCamera().getZoom(),
41 | 1.0f);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/shape/Shape.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.shape;
18 |
19 | import org.ros.android.view.visualization.Color;
20 |
21 | import org.ros.android.view.visualization.OpenGlDrawable;
22 | import org.ros.rosjava_geometry.Transform;
23 |
24 | /**
25 | * A {@link Shape} is a {@link OpenGlDrawable} that has a {@link Color} and a
26 | * {@link Transform} that is applied to the OpenGL matrix stack before drawing.
27 | *
28 | * @author damonkohler@google.com (Damon Kohler)
29 | */
30 | public interface Shape extends OpenGlDrawable {
31 |
32 | /**
33 | * @param color
34 | * the {@link Color} of this {@link Shape}
35 | */
36 | void setColor(Color color);
37 |
38 | /**
39 | * @return the {@link Color} of this {@link Shape}
40 | */
41 | Color getColor();
42 |
43 | /**
44 | * @param transform
45 | * the {@link Transform} that will be applied to this {@link Shape}
46 | * before it is drawn
47 | */
48 | void setTransform(Transform transform);
49 |
50 | /**
51 | * @return the {@link Transform} that will be applied to this {@link Shape}
52 | * before it is drawn
53 | */
54 | Transform getTransform();
55 | }
56 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/shape/TextShape.java:
--------------------------------------------------------------------------------
1 | package org.ros.android.view.visualization.shape;
2 |
3 | import org.ros.android.view.visualization.Vertices;
4 | import org.ros.android.view.visualization.VisualizationView;
5 |
6 | import java.nio.FloatBuffer;
7 |
8 | import javax.microedition.khronos.opengles.GL10;
9 |
10 | import uk.co.blogspot.fractiousg.texample.GLText;
11 |
12 | public class TextShape extends BaseShape {
13 |
14 | private final GLText glText;
15 | private final String text;
16 |
17 | private float x;
18 | private float y;
19 | private FloatBuffer lines;
20 |
21 | public TextShape(GLText glText, String text) {
22 | this.glText = glText;
23 | this.text = text;
24 | lines = Vertices.allocateBuffer(4 * 3);
25 | }
26 |
27 | public void setOffset(float x, float y) {
28 | this.x = x;
29 | this.y = y;
30 | lines.put(0.f);
31 | lines.put(0.f);
32 | lines.put(0.f);
33 |
34 | lines.put(x);
35 | lines.put(y);
36 | lines.put(0.f);
37 |
38 | lines.put(x);
39 | lines.put(y);
40 | lines.put(0.f);
41 |
42 | lines.put(x + glText.getLength(text));
43 | lines.put(y);
44 | lines.put(0.f);
45 |
46 | lines.flip();
47 | }
48 |
49 | @Override
50 | protected void scale(VisualizationView view, GL10 gl) {
51 | // Counter adjust for the camera zoom.
52 | gl.glScalef(1 / (float) view.getCamera().getZoom(), 1 / (float) view.getCamera().getZoom(),
53 | 1.0f);
54 | }
55 |
56 | @Override
57 | protected void drawShape(VisualizationView view, GL10 gl) {
58 | Vertices.drawLines(gl, lines, getColor(), 3.f);
59 | gl.glEnable(GL10.GL_TEXTURE_2D);
60 | glText.begin(getColor().getRed(), getColor().getGreen(), getColor().getBlue(), getColor()
61 | .getAlpha());
62 | glText.draw(text, x, y);
63 | glText.end();
64 | gl.glDisable(GL10.GL_TEXTURE_2D);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/shape/TextShapeFactory.java:
--------------------------------------------------------------------------------
1 | package org.ros.android.view.visualization.shape;
2 |
3 | import android.graphics.Typeface;
4 |
5 | import org.ros.android.view.visualization.VisualizationView;
6 |
7 | import javax.microedition.khronos.opengles.GL10;
8 |
9 | import uk.co.blogspot.fractiousg.texample.GLText;
10 |
11 | public class TextShapeFactory {
12 |
13 | private final GLText glText;
14 |
15 | public TextShapeFactory(final VisualizationView view, final GL10 gl) {
16 | glText = new GLText(gl, view.getContext().getAssets());
17 | }
18 |
19 | public void loadFont(final Typeface typeface, final int size, final int padX, final int padY) {
20 | glText.load(typeface, size, padX, padY);
21 | }
22 |
23 | public void loadFont(final String file, final int size, final int padX, final int padY) {
24 | glText.load(file, size, padX, padY);
25 | }
26 |
27 | public TextShape newTextShape(final String text) {
28 | return new TextShape(glText, text);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/android_core_components/src/org/ros/android/view/visualization/shape/TriangleFanShape.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.view.visualization.shape;
18 |
19 | import org.ros.android.view.visualization.VisualizationView;
20 |
21 | import org.ros.android.view.visualization.Color;
22 | import org.ros.android.view.visualization.Vertices;
23 |
24 | import java.nio.FloatBuffer;
25 |
26 | import javax.microedition.khronos.opengles.GL10;
27 |
28 | /**
29 | * A {@link Shape} defined by vertices using OpenGl's GL_TRIANGLE_FAN method.
30 | *
31 | * Note that this class is intended to be wrapped. No transformations are
32 | * performed in the {@link #draw(VisualizationView, GL10)} method.
33 | *
34 | * @author moesenle@google.com (Lorenz Moesenlechner)
35 | * @author damonkohler@google.com (Damon Kohler)
36 | */
37 | public class TriangleFanShape extends BaseShape {
38 |
39 | private final FloatBuffer vertices;
40 |
41 | /**
42 | * @param vertices
43 | * an array of vertices as defined by OpenGL's GL_TRIANGLE_FAN method
44 | * @param color
45 | * the {@link Color} of the {@link Shape}
46 | */
47 | public TriangleFanShape(float[] vertices, Color color) {
48 | super();
49 | this.vertices = Vertices.toFloatBuffer(vertices);
50 | setColor(color);
51 | }
52 |
53 | @Override
54 | public void drawShape(VisualizationView view, GL10 gl) {
55 | Vertices.drawTriangleFan(gl, vertices, getColor());
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/android_core_components/src/uk/co/blogspot/fractiousg/texample/TextureRegion.java:
--------------------------------------------------------------------------------
1 | package uk.co.blogspot.fractiousg.texample;
2 |
3 | class TextureRegion {
4 |
5 | //--Members--//
6 | public float u1, v1; // Top/Left U,V Coordinates
7 | public float u2, v2; // Bottom/Right U,V Coordinates
8 |
9 | //--Constructor--//
10 | // D: calculate U,V coordinates from specified texture coordinates
11 | // A: texWidth, texHeight - the width and height of the texture the region is for
12 | // x, y - the top/left (x,y) of the region on the texture (in pixels)
13 | // width, height - the width and height of the region on the texture (in pixels)
14 | public TextureRegion(float texWidth, float texHeight, float x, float y, float width, float height) {
15 | this.u1 = x / texWidth; // Calculate U1
16 | this.v1 = y / texHeight; // Calculate V1
17 | this.u2 = this.u1 + ( width / texWidth ); // Calculate U2
18 | this.v2 = this.v1 + ( height / texHeight ); // Calculate V2
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/android_tutorial_camera/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
16 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/android_tutorial_camera/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | dependencies {
18 | compile project(':android_core_components')
19 | }
20 |
21 | apply plugin: 'com.android.application'
22 |
23 | android {
24 | compileSdkVersion 28
25 |
26 | defaultConfig {
27 | minSdkVersion 16
28 | applicationId "org.ros.android.android_tutorial_camera"
29 | targetSdkVersion 28
30 | versionCode 1
31 | versionName "1.0"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/android_tutorial_camera/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/android_tutorial_camera/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | CameraTutorial
4 |
5 |
--------------------------------------------------------------------------------
/android_tutorial_camera/src/org/ros/android/android_tutorial_camera/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_tutorial_camera;
18 |
19 | import android.hardware.Camera;
20 | import android.os.Build;
21 | import android.os.Bundle;
22 | import android.view.MotionEvent;
23 | import android.view.Window;
24 | import android.view.WindowManager;
25 | import android.widget.Toast;
26 | import org.ros.address.InetAddressFactory;
27 | import org.ros.android.RosActivity;
28 | import org.ros.android.view.camera.RosCameraPreviewView;
29 | import org.ros.node.NodeConfiguration;
30 | import org.ros.node.NodeMainExecutor;
31 | import android.util.Log;
32 | import java.io.IOException;
33 |
34 | /**
35 | * @author ethan.rublee@gmail.com (Ethan Rublee)
36 | * @author damonkohler@google.com (Damon Kohler)
37 | */
38 | public class MainActivity extends RosActivity {
39 |
40 | private int cameraId;
41 | private RosCameraPreviewView rosCameraPreviewView;
42 |
43 | public MainActivity() {
44 | super("CameraTutorial", "CameraTutorial");
45 | }
46 |
47 | @Override
48 | protected void onCreate(Bundle savedInstanceState) {
49 | super.onCreate(savedInstanceState);
50 | requestWindowFeature(Window.FEATURE_NO_TITLE);
51 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
52 | setContentView(R.layout.main);
53 | rosCameraPreviewView = (RosCameraPreviewView) findViewById(R.id.ros_camera_preview_view);
54 | }
55 |
56 | @Override
57 | public boolean onTouchEvent(MotionEvent event) {
58 | if (event.getAction() == MotionEvent.ACTION_UP) {
59 | int numberOfCameras = Camera.getNumberOfCameras();
60 | final Toast toast;
61 | if (numberOfCameras > 1) {
62 | cameraId = (cameraId + 1) % numberOfCameras;
63 | rosCameraPreviewView.releaseCamera();
64 | rosCameraPreviewView.setCamera(getCamera());
65 | toast = Toast.makeText(this, "Switching cameras.", Toast.LENGTH_SHORT);
66 | } else {
67 | toast = Toast.makeText(this, "No alternative cameras to switch to.", Toast.LENGTH_SHORT);
68 | }
69 | runOnUiThread(new Runnable() {
70 | @Override
71 | public void run() {
72 | toast.show();
73 | }
74 | });
75 | }
76 | return true;
77 | }
78 |
79 | @Override
80 | protected void init(NodeMainExecutor nodeMainExecutor) {
81 | cameraId = 0;
82 |
83 | rosCameraPreviewView.setCamera(getCamera());
84 | try {
85 | java.net.Socket socket = new java.net.Socket(getMasterUri().getHost(), getMasterUri().getPort());
86 | java.net.InetAddress local_network_address = socket.getLocalAddress();
87 | socket.close();
88 | NodeConfiguration nodeConfiguration =
89 | NodeConfiguration.newPublic(local_network_address.getHostAddress(), getMasterUri());
90 | nodeMainExecutor.execute(rosCameraPreviewView, nodeConfiguration);
91 | } catch (IOException e) {
92 | // Socket problem
93 | Log.e("Camera Tutorial", "socket error trying to get networking information from the master uri");
94 | }
95 |
96 | }
97 |
98 | private Camera getCamera() {
99 | Camera cam = Camera.open(cameraId);
100 | Camera.Parameters camParams = cam.getParameters();
101 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
102 | if (camParams.getSupportedFocusModes().contains(
103 | Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
104 | camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
105 | } else {
106 | camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
107 | }
108 | }
109 | cam.setParameters(camParams);
110 | return cam;
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/android_tutorial_image_transport/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/android_tutorial_image_transport/README:
--------------------------------------------------------------------------------
1 | 1. Install usb_cam module.
2 | 2. roslaunch usb_cam.launch
3 | 3. Run MainAcitivity on the Android device.
4 |
--------------------------------------------------------------------------------
/android_tutorial_image_transport/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | dependencies {
18 | compile project(':android_core_components')
19 | }
20 |
21 | apply plugin: 'com.android.application'
22 |
23 | android {
24 | compileSdkVersion 28
25 |
26 | defaultConfig {
27 | minSdkVersion 16
28 | applicationId "org.ros.android.android_tutorial_image_transport"
29 | targetSdkVersion 28
30 | versionCode 1
31 | versionName "1.0"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/android_tutorial_image_transport/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/android_tutorial_image_transport/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | ImageTransportTutorial
4 |
5 |
--------------------------------------------------------------------------------
/android_tutorial_image_transport/src/org/ros/android/android_tutorial_image_transport/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_tutorial_image_transport;
18 |
19 | import android.os.Bundle;
20 | import org.ros.address.InetAddressFactory;
21 | import org.ros.android.BitmapFromCompressedImage;
22 | import org.ros.android.RosActivity;
23 | import org.ros.android.view.RosImageView;
24 | import org.ros.node.NodeConfiguration;
25 | import org.ros.node.NodeMainExecutor;
26 |
27 | /**
28 | * @author ethan.rublee@gmail.com (Ethan Rublee)
29 | * @author damonkohler@google.com (Damon Kohler)
30 | */
31 | public class MainActivity extends RosActivity {
32 |
33 | private RosImageView image;
34 |
35 | public MainActivity() {
36 | super("ImageTransportTutorial", "ImageTransportTutorial");
37 | }
38 |
39 | @SuppressWarnings("unchecked")
40 | @Override
41 | public void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 | setContentView(R.layout.main);
44 | image = (RosImageView) findViewById(R.id.image);
45 | image.setTopicName("/usb_cam/image_raw/compressed");
46 | image.setMessageType(sensor_msgs.CompressedImage._TYPE);
47 | image.setMessageToBitmapCallable(new BitmapFromCompressedImage());
48 | }
49 |
50 | @Override
51 | protected void init(NodeMainExecutor nodeMainExecutor) {
52 | NodeConfiguration nodeConfiguration =
53 | NodeConfiguration.newPublic(InetAddressFactory.newNonLoopback().getHostAddress(),
54 | getMasterUri());
55 | nodeMainExecutor.execute(image, nodeConfiguration.setNodeName("android/video_view"));
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/android_tutorial_image_transport/usb_cam.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/android_tutorial_map_viewer/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/android_tutorial_map_viewer/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | dependencies {
18 | compile project(':android_core_components')
19 | }
20 |
21 | apply plugin: 'com.android.application'
22 |
23 | android {
24 | compileSdkVersion 28
25 |
26 | defaultConfig {
27 | minSdkVersion 16
28 | applicationId "org.ros.android.android_tutorial_map_viewer"
29 | targetSdkVersion 28
30 | versionCode 1
31 | versionName "1.0"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/android_tutorial_map_viewer/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
17 |
18 |
26 |
27 |
34 |
35 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/android_tutorial_map_viewer/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Map Viewer
4 |
5 |
--------------------------------------------------------------------------------
/android_tutorial_map_viewer/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
--------------------------------------------------------------------------------
/android_tutorial_map_viewer/src/org/ros/android/android_tutorial_map_viewer/SystemCommands.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_tutorial_map_viewer;
18 |
19 | import org.ros.namespace.GraphName;
20 | import org.ros.node.AbstractNodeMain;
21 | import org.ros.node.ConnectedNode;
22 | import org.ros.node.Node;
23 | import org.ros.node.topic.Publisher;
24 |
25 | /**
26 | * @author damonkohler@google.com (Damon Kohler)
27 | */
28 | public class SystemCommands extends AbstractNodeMain {
29 |
30 | private Publisher publisher;
31 |
32 | @Override
33 | public GraphName getDefaultNodeName() {
34 | return GraphName.of("system_commands");
35 | }
36 |
37 | @Override
38 | public void onStart(ConnectedNode connectedNode) {
39 | publisher = connectedNode.newPublisher("syscommand", std_msgs.String._TYPE);
40 | }
41 |
42 | public void reset() {
43 | publish("reset");
44 | }
45 |
46 | public void saveGeotiff() {
47 | publish("savegeotiff");
48 | }
49 |
50 | private void publish(String command) {
51 | if (publisher != null) {
52 | std_msgs.String message = publisher.newMessage();
53 | message.setData(command);
54 | publisher.publish(message);
55 | }
56 | }
57 |
58 | @Override
59 | public void onShutdown(Node arg0) {
60 | publisher = null;
61 | }
62 | }
--------------------------------------------------------------------------------
/android_tutorial_pubsub/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/android_tutorial_pubsub/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | dependencies {
18 | compile 'org.ros.rosjava_core:rosjava_tutorial_pubsub:[0.3,0.4)'
19 | compile project(':android_core_components')
20 | }
21 |
22 | apply plugin: 'com.android.application'
23 |
24 | android {
25 | compileSdkVersion 28
26 |
27 | defaultConfig {
28 | minSdkVersion 16
29 | applicationId "org.ros.android.android_tutorial_pubsub"
30 | targetSdkVersion 28
31 | versionCode 1
32 | versionName "1.0"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/android_tutorial_pubsub/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/android_tutorial_pubsub/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PubSubTutorial
5 |
6 |
--------------------------------------------------------------------------------
/android_tutorial_pubsub/src/org/ros/android/android_tutorial_pubsub/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_tutorial_pubsub;
18 |
19 | import android.os.Bundle;
20 | import org.ros.android.MessageCallable;
21 | import org.ros.android.RosActivity;
22 | import org.ros.android.view.RosTextView;
23 | import org.ros.node.NodeConfiguration;
24 | import org.ros.node.NodeMainExecutor;
25 | import org.ros.rosjava_tutorial_pubsub.Talker;
26 |
27 | /**
28 | * @author damonkohler@google.com (Damon Kohler)
29 | */
30 | public class MainActivity extends RosActivity {
31 |
32 | private RosTextView rosTextView;
33 | private Talker talker;
34 |
35 | public MainActivity() {
36 | // The RosActivity constructor configures the notification title and ticker
37 | // messages.
38 | super("Pubsub Tutorial", "Pubsub Tutorial");
39 | }
40 |
41 | @SuppressWarnings("unchecked")
42 | @Override
43 | public void onCreate(Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.main);
46 | rosTextView = (RosTextView) findViewById(R.id.text);
47 | rosTextView.setTopicName("chatter");
48 | rosTextView.setMessageType(std_msgs.String._TYPE);
49 | rosTextView.setMessageToStringCallable(new MessageCallable() {
50 | @Override
51 | public String call(std_msgs.String message) {
52 | return message.getData();
53 | }
54 | });
55 | }
56 |
57 | @Override
58 | protected void init(NodeMainExecutor nodeMainExecutor) {
59 | talker = new Talker();
60 |
61 | // At this point, the user has already been prompted to either enter the URI
62 | // of a master to use or to start a master locally.
63 |
64 | // The user can easily use the selected ROS Hostname in the master chooser
65 | // activity.
66 | NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(getRosHostname());
67 | nodeConfiguration.setMasterUri(getMasterUri());
68 | nodeMainExecutor.execute(talker, nodeConfiguration);
69 | // The RosTextView is also a NodeMain that must be executed in order to
70 | // start displaying incoming messages.
71 | nodeMainExecutor.execute(rosTextView, nodeConfiguration);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/android_tutorial_teleop/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/android_tutorial_teleop/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | dependencies {
18 | compile project(':android_core_components')
19 | }
20 |
21 | apply plugin: 'com.android.application'
22 |
23 | android {
24 | compileSdkVersion 28
25 |
26 | defaultConfig {
27 | minSdkVersion 16
28 | applicationId "org.ros.android.android_tutorial_teleop"
29 | targetSdkVersion 28
30 | versionCode 1
31 | versionName "1.0"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/android_tutorial_teleop/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
17 |
18 |
--------------------------------------------------------------------------------
/android_tutorial_teleop/res/menu/settings_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/android_tutorial_teleop/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Teleop
4 |
--------------------------------------------------------------------------------
/android_tutorial_teleop/src/org/ros/android/android_tutorial_teleop/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.android_tutorial_teleop;
18 |
19 | import com.google.common.collect.Lists;
20 |
21 | import android.os.Bundle;
22 | import android.view.Menu;
23 | import android.view.MenuInflater;
24 | import android.view.MenuItem;
25 | import org.ros.address.InetAddressFactory;
26 | import org.ros.android.RosActivity;
27 | import org.ros.android.view.VirtualJoystickView;
28 | import org.ros.android.view.visualization.VisualizationView;
29 | import org.ros.android.view.visualization.layer.CameraControlLayer;
30 | import org.ros.android.view.visualization.layer.LaserScanLayer;
31 | import org.ros.android.view.visualization.layer.Layer;
32 | import org.ros.android.view.visualization.layer.OccupancyGridLayer;
33 | import org.ros.android.view.visualization.layer.PathLayer;
34 | import org.ros.android.view.visualization.layer.PosePublisherLayer;
35 | import org.ros.android.view.visualization.layer.PoseSubscriberLayer;
36 | import org.ros.android.view.visualization.layer.RobotLayer;
37 | import org.ros.node.NodeConfiguration;
38 | import org.ros.node.NodeMainExecutor;
39 |
40 | /**
41 | * An app that can be used to control a remote robot. This app also demonstrates
42 | * how to use some of views from the rosjava android library.
43 | *
44 | * @author munjaldesai@google.com (Munjal Desai)
45 | * @author moesenle@google.com (Lorenz Moesenlechner)
46 | */
47 | public class MainActivity extends RosActivity {
48 |
49 | private VirtualJoystickView virtualJoystickView;
50 | private VisualizationView visualizationView;
51 |
52 | public MainActivity() {
53 | super("Teleop", "Teleop");
54 | }
55 |
56 | @Override
57 | public boolean onCreateOptionsMenu(Menu menu) {
58 | MenuInflater inflater = getMenuInflater();
59 | inflater.inflate(R.menu.settings_menu, menu);
60 | return true;
61 | }
62 |
63 | @Override
64 | public boolean onOptionsItemSelected(MenuItem item) {
65 | switch (item.getItemId()) {
66 | case R.id.virtual_joystick_snap:
67 | if (!item.isChecked()) {
68 | item.setChecked(true);
69 | virtualJoystickView.EnableSnapping();
70 | } else {
71 | item.setChecked(false);
72 | virtualJoystickView.DisableSnapping();
73 | }
74 | return true;
75 | default:
76 | return super.onOptionsItemSelected(item);
77 | }
78 | }
79 |
80 | @Override
81 | public void onCreate(Bundle savedInstanceState) {
82 | super.onCreate(savedInstanceState);
83 | setContentView(R.layout.main);
84 | virtualJoystickView = (VirtualJoystickView) findViewById(R.id.virtual_joystick);
85 | visualizationView = (VisualizationView) findViewById(R.id.visualization);
86 | visualizationView.getCamera().jumpToFrame("map");
87 | visualizationView.onCreate(Lists.newArrayList(new CameraControlLayer(),
88 | new OccupancyGridLayer("map"), new PathLayer("move_base/NavfnROS/plan"), new PathLayer(
89 | "move_base_dynamic/NavfnROS/plan"), new LaserScanLayer("base_scan"),
90 | new PoseSubscriberLayer("simple_waypoints_server/goal_pose"), new PosePublisherLayer(
91 | "simple_waypoints_server/goal_pose"), new RobotLayer("base_footprint")));
92 | }
93 |
94 | @Override
95 | protected void init(NodeMainExecutor nodeMainExecutor) {
96 | visualizationView.init(nodeMainExecutor);
97 | NodeConfiguration nodeConfiguration =
98 | NodeConfiguration.newPublic(InetAddressFactory.newNonLoopback().getHostAddress(),
99 | getMasterUri());
100 | nodeMainExecutor
101 | .execute(virtualJoystickView, nodeConfiguration.setNodeName("virtual_joystick"));
102 | nodeMainExecutor.execute(visualizationView, nodeConfiguration.setNodeName("android/map_view"));
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | task wrapper(type: Wrapper) {
18 | gradleVersion = "4.10.2"
19 | }
20 |
21 | buildscript {
22 | apply from: project.file("buildscript.gradle")
23 | }
24 |
25 | apply plugin: "catkin"
26 |
27 | allprojects {
28 | group "org.ros.android_core"
29 | version = project.catkin.pkg.version
30 | }
31 |
32 | configure(subprojects.findAll { it.name.startsWith("android_") }) {
33 | /*
34 | * The android plugin configures a few things:
35 | *
36 | * - local deployment repository : where it dumps the jars and packaged artifacts)
37 | * - local maven repositories : where it finds your locally installed/built artifacts)
38 | * - external maven repositories : where it goes looking if it can't find dependencies locally
39 | * - android build tools version : which version we use across the board
40 | *
41 | * To modify, or add repos to the default external maven repositories list, pull request against this code:
42 | *
43 | * https://github.com/rosjava/rosjava_bootstrap/blob/kinetic/gradle_plugins/src/main/groovy/org/ros/gradle_plugins/RosPlugin.groovy#L31
44 | *
45 | * To modify the build tools version, pull request against this code:
46 | *
47 | * https://github.com/rosjava/rosjava_bootstrap/blob/kinetic/gradle_plugins/src/main/groovy/org/ros/gradle_plugins/RosAndroid.groovy#L14
48 | */
49 | apply plugin: "ros-android"
50 | afterEvaluate { project ->
51 | // Change the layout of Android projects to be compatible with Eclipse.
52 | android {
53 | sourceSets {
54 | //noinspection GroovyAssignabilityCheck
55 | main {
56 | manifest.srcFile "AndroidManifest.xml"
57 | res.srcDirs "res"
58 | assets.srcDirs "assets"
59 | java.srcDirs "src"
60 | }
61 | }
62 |
63 | // Copy JAR dependencies into the libs directory for Eclipse.
64 | task deployLibs(type: Copy) {
65 | from { configurations.compile }
66 | into { "${project.projectDir}/libs" }
67 | }
68 |
69 | // Exclude a few files that are duplicated across our dependencies and
70 | // prevent packaging Android applications.
71 | packagingOptions {
72 | /* https://github.com/rosjava/android_core/issues/194 */
73 | exclude "META-INF/LICENSE.txt"
74 | exclude "META-INF/NOTICE.txt"
75 | }
76 |
77 | lintOptions {
78 | abortOnError false
79 | }
80 | }
81 | }
82 | }
83 |
84 | defaultTasks 'assembleRelease', 'uploadArchives'
85 |
--------------------------------------------------------------------------------
/buildscript.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | rootProject.buildscript {
18 | apply from: "https://github.com/rosjava/rosjava_bootstrap/raw/kinetic/buildscript.gradle"
19 | dependencies {
20 | classpath "com.android.tools.build:gradle:3.5.2"
21 | }
22 |
23 | allprojects {
24 | repositories {
25 | google()
26 | jcenter()
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/compressed_map_transport/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | group 'ros.android_core'
18 | version = '0.0.0-SNAPSHOT'
19 |
20 | apply plugin: 'java'
21 | apply plugin: 'eclipse'
22 | apply plugin: 'maven'
23 | apply plugin: 'application'
24 |
25 | sourceCompatibility = 1.6
26 | targetCompatibility = 1.6
27 |
28 | mainClassName = 'org.ros.RosRun'
29 |
30 | repositories {
31 | mavenLocal()
32 | maven {
33 | url 'http://robotbrains.hideho.org/nexus/content/groups/ros-public'
34 | }
35 | }
36 |
37 | dependencies {
38 | compile 'ros.rosjava_core:rosjava:0.0.0-SNAPSHOT'
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/docs/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | import org.apache.tools.ant.filters.ReplaceTokens
18 |
19 | task javadoc(type: Javadoc) {
20 | def javaProjects = rootProject.subprojects.findResults {
21 | (it.name != 'docs') ? it : null
22 | }
23 | source javaProjects.collect { fileTree(dir: "${it.projectDir}/src/main/java") }
24 | classpath = files(javaProjects.collect { it.configurations.compile })
25 | destinationDir = new File("${buildDir}/html", 'javadoc')
26 | }
27 |
28 | task copySphinxConf(type: Copy) {
29 | from('src/main/sphinx/conf.py.in') {
30 | filter(ReplaceTokens, tokens: ['version': rootProject.version])
31 | }
32 | into 'src/main/sphinx'
33 | rename 'conf.py.in', 'conf.py'
34 | }
35 |
36 | task docs(type: Exec, dependsOn: [copySphinxConf, javadoc]) {
37 | commandLine 'make', 'html'
38 | }
39 |
40 | task clean {
41 | doLast {
42 | ant.delete dir: 'build'
43 | ant.delete file: 'src/main/sphinx/conf.py'
44 | }
45 | }
46 |
47 | /* Dummy task to stop android studio barfing */
48 | task assembleDebug {}
49 | task assembleRelease {}
50 | task assemble {}
51 |
--------------------------------------------------------------------------------
/docs/src/main/sphinx/building.rst:
--------------------------------------------------------------------------------
1 | .. _building:
2 |
3 | Building
4 | ========
5 |
6 | android_core uses the `Gradle`_ build system in tandem with an external maven
7 | repository which supplies dependencies (.jar's and .aar's).
8 |
9 | To build debug APKs for all android_core packages, execute the `gradle wrapper`_.
10 |
11 | .. code-block:: bash
12 |
13 | cd android_core
14 | ./gradlew assemble
15 |
16 | You may deploy the android libraries (.aar's) to your local maven repository so
17 | that other android packages outside android_core can use them with:
18 |
19 | .. code-block:: bash
20 | ./gradlew publishToMavenLocal
21 |
22 | To build the documentation, you may execute the docs task:
23 |
24 | .. code-block:: bash
25 |
26 | ./gradlew docs
27 |
28 | At this point, you may interact with your Android projects via Android Studio as described
29 | in the `RosWiki`_ pages.
30 |
31 | .. _RosWiki: http://wiki.ros.org/android/Android Studio
32 | .. _Gradle: http://www.gradle.org/
33 | .. _gradle wrapper: http://gradle.org/docs/current/userguide/gradle_wrapper.html
34 | .. _Android documentation: http://developer.android.com/guide/developing/building/building-cmdline.html
35 |
36 |
--------------------------------------------------------------------------------
/docs/src/main/sphinx/index.rst:
--------------------------------------------------------------------------------
1 | android_core
2 | ============
3 |
4 | android_core is a collection of components and examples that are useful for
5 | developing ROS applications on Android.
6 |
7 | Support is best found on http://answers.ros.org/ and ros-related documentation
8 | for all things ros-android on the `ros wiki`_.
9 |
10 | Please file bugs and feature requests on the rosjava `issues`_ page. Starring
11 | issues that are important to you will help developers prioritize their work.
12 |
13 | In addition to the following documentation, android_core makes liberal use of
14 | `Javadoc`_.
15 |
16 | .. _issues: http://github.com/rosjava/android_core/issues
17 | .. _Javadoc: javadoc/index.html
18 | .. _ros wiki: http://wiki.ros.org/android
19 |
20 | Contents:
21 |
22 | .. toctree::
23 | :maxdepth: 2
24 |
25 | overview
26 | installing
27 | building
28 | getting_started
29 |
30 |
--------------------------------------------------------------------------------
/docs/src/main/sphinx/installing.rst:
--------------------------------------------------------------------------------
1 | Installing
2 | ==========
3 |
4 | These instructions assume that you have already completed the rosjava_core
5 | :ref:`installation ` and :ref:`build
6 | ` instructions.
7 |
8 | Prerequisites
9 | -------------
10 |
11 | There are a few additional dependencies required for building android_core:
12 |
13 | * `Android Studio & SDK`_
14 |
15 | If you would like to build the android_core documentation, you will also need
16 | Pygments 1.5+ and Sphinx 1.1.3+.
17 |
18 | .. code-block:: bash
19 |
20 | sudo pip install --upgrade sphinx Pygments
21 |
22 | Non-ROS Installation
23 | --------------------
24 |
25 | As with rosjava_core, this repository no longer requires a ros environment to be
26 | installed. In this case,
27 |
28 | you simply need to clone the github repository
29 |
30 | .. code-block:: bash
31 |
32 | git clone https://github.com/rosjava/android_core
33 | git checkout -b hydro origin/hydro
34 |
35 | and proceed immediately to the section on :ref:`building`.
36 |
37 | ROS Installation
38 | ----------------
39 |
40 | If you would like a full ros environment backending your installation (you might
41 | be building rosjava packages at the same time) then refer to the `RosWiki`_
42 | for more details.
43 |
44 | .. _RosWiki: http://wiki.ros.org/android
45 | .. _Android Studio & SDK: http://wiki.ros.org/android/Android%20Studio/Download
46 |
47 |
--------------------------------------------------------------------------------
/docs/src/main/sphinx/javadoc.py:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2012 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 |
15 | __author__ = 'damonkohler@google.com (Damon Kohler)'
16 |
17 | import os
18 |
19 | from docutils import nodes, utils
20 |
21 |
22 | def make_javadoc_link(name, rawtext, text, lineno, inliner, options={}, content=[]):
23 | env = inliner.document.settings.env
24 | javadoc_root = env.config.javadoc_root
25 | class_part, method_part = (text.split('#', 1) + [''])[:2]
26 | refuri = os.path.join(javadoc_root, '%s.html#%s' % (class_part.replace('.', '/'), method_part))
27 | label = class_part.rsplit('.', 1)[-1]
28 | if method_part:
29 | label += '.' + method_part.split('(')[0]
30 | node = nodes.reference(rawtext, label, refuri=refuri, **options)
31 | return [node], []
32 |
33 |
34 | def setup(app):
35 | app.add_config_value('javadoc_root', None, 'env')
36 | app.add_role('javadoc', make_javadoc_link)
37 |
38 |
--------------------------------------------------------------------------------
/docs/src/main/sphinx/overview.rst:
--------------------------------------------------------------------------------
1 | Overview
2 | ========
3 |
4 | The android_core stack is currently under active development. Consider all
5 | APIs and documentation to be volatile.
6 |
7 | `Javadoc `_ is used extensively and cross referenced from
8 | this documentation.
9 |
10 | ROS-enabling Android applications
11 | ----------------------------------
12 |
13 | android_core provides `Android Library Projects`_ to help you write ROS
14 | applications for Android (i.e. android_core_components).
15 | Each class or feature is defined in the library project that represents the
16 | minimum version of Android required for it to work.
17 |
18 | Your application can depend on multiple library projects. This allows you to
19 | easily target your application for different API levels.
20 |
21 | Beyond specific features, android_core defines the pattern of combining the
22 | Android `View`_ and :javadoc:`org.ros.node.NodeMain` concepts to enable the
23 | development of data driven Android UIs (e.g.
24 | :javadoc:`org.ros.android.view.RosTextView`).
25 |
26 | .. _Android Library Projects: http://developer.android.com/guide/developing/projects/index.html#LibraryProjects
27 | .. _Android API level: http://developer.android.com/guide/appendix/api-levels.html
28 | .. _View: http://developer.android.com/reference/android/view/View.html
29 |
30 | android_core_components library project
31 | ---------------------------------------
32 | Since version 0.4.0, the previous android_10 and android_15 libraries were merged
33 | in a single project with minimum API level 16, as the amount of Android devices that
34 | still use lower APIs are mostly deprecated as of September 2018.
35 |
36 | See notes below regarding previous library projects.
37 |
38 | android_10 library project
39 | ---------------------------------------
40 |
41 | android_10 (API level 10) is the lowest API level supported. It
42 | provides the base `Activity`_ (:javadoc:`org.ros.android.RosActivity`) and
43 | `Service`_ (:javadoc:`org.ros.android.NodeMainExecutorService`) for executing
44 | and managing the lifecycle of your :javadoc:`org.ros.node.NodeMain`\s.
45 |
46 | A few of the other features provided include:
47 |
48 | * camera publisher
49 | * image view
50 | * orientation publisher
51 |
52 | .. _Activity: http://developer.android.com/reference/android/app/Activity.html
53 | .. _Service: http://developer.android.com/reference/android/app/Service.html
54 |
55 | android_15 library project
56 | -------------------------------------
57 |
58 | android_15 (API level 13) provides features that require multitouch
59 | and other APIs that are only available in devices with Android Honeycomb MR2 or
60 | higher.
61 |
62 | A few of the features provided include:
63 |
64 | * 2D mapping and navigation
65 | * 2D laser scan visualization
66 | * virtual joystick
67 |
--------------------------------------------------------------------------------
/docs/src/main/sphinx/ros.py:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2012 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 |
15 | __author__ = 'damonkohler@google.com (Damon Kohler)'
16 |
17 | from docutils import nodes
18 |
19 |
20 | def make_roswiki_link(name, rawtext, text, lineno, inliner, options={}, content=[]):
21 | refuri = 'http://wiki.ros.org/' + text
22 | node = nodes.reference(rawtext, text, refuri=refuri, **options)
23 | return [node], []
24 |
25 |
26 | def make_rosmsg_link(name, rawtext, text, lineno, inliner, options={}, content=[]):
27 | package, message = text.split('/', 1)
28 | refuri = 'http://ros.org/doc/api/%s/html/msg/%s.html' % (package, message)
29 | node = nodes.reference(rawtext, text, refuri=refuri, **options)
30 | return [node], []
31 |
32 |
33 | def make_rossrv_link(name, rawtext, text, lineno, inliner, options={}, content=[]):
34 | package, message = text.split('/', 1)
35 | refuri = 'http://ros.org/doc/api/%s/html/srv/%s.html' % (package, message)
36 | node = nodes.reference(rawtext, text, refuri=refuri, **options)
37 | return [node], []
38 |
39 |
40 | def setup(app):
41 | app.add_role('roswiki', make_roswiki_link)
42 | app.add_role('rosmsg', make_rosmsg_link)
43 | app.add_role('rossrv', make_rossrv_link)
44 |
45 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.daemon=true
2 | # Disabling the SNI extension fixes "handshake alert: unrecognized_name" error
3 | # in Java 7.
4 | org.gradle.jvmargs=-XX:MaxPermSize=512m -Djsse.enableSNIExtension=false
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rosjava/android_core/8493ebd2f4a6aba8c03eccc3125491c11e2b0375/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | android_core
4 | 0.4.0
5 |
6 | Android support packages for rosjava.
7 |
8 | http://ros.org/wiki/android_core
9 | https://github.com/rosjava/android_core
10 | https://github.com/rosjava/android_core/issues
11 | Daniel Stonier
12 | Damon Kohler
13 | Damon Kohler
14 | Apache 2.0
15 |
16 | catkin
17 | rosjava_build_tools
18 | rosjava_core
19 |
20 |
--------------------------------------------------------------------------------
/polling_input_stream/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | group 'ros.android_core'
18 | version = '0.0.0-SNAPSHOT'
19 |
20 | apply plugin: 'java'
21 | apply plugin: 'eclipse'
22 | apply plugin: 'maven'
23 |
24 | sourceCompatibility = 1.6
25 | targetCompatibility = 1.6
26 |
27 | repositories {
28 | mavenLocal()
29 | maven {
30 | url 'http://robotbrains.hideho.org/nexus/content/groups/ros-public'
31 | }
32 | }
33 |
34 | dependencies {
35 | compile 'ros.rosjava_core:rosjava:0.0.0-SNAPSHOT'
36 | testCompile 'junit:junit:4.8.2'
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/polling_input_stream/src/main/java/org/ros/android/acm_serial/PollingInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.acm_serial;
18 |
19 | import org.apache.commons.logging.Log;
20 | import org.apache.commons.logging.LogFactory;
21 | import org.ros.concurrent.CancellableLoop;
22 | import org.ros.exception.RosRuntimeException;
23 |
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 | import java.util.concurrent.ExecutorService;
27 |
28 | /**
29 | * Constantly reads from an {@link InputStream} into a buffer.
30 | *
31 | * @author damonkohler@google.com (Damon Kohler)
32 | */
33 | public class PollingInputStream extends InputStream {
34 |
35 | private final static boolean DEBUG = false;
36 | private final static Log log = LogFactory.getLog(PollingInputStream.class);
37 |
38 | private final static int BUFFER_CAPACITY = 512 * 1024;
39 | private final static int READ_SIZE = 256;
40 |
41 | private final byte[] readBuffer;
42 |
43 | private int readPosition;
44 | private int writePosition;
45 |
46 | /**
47 | * @param inputStream
48 | * the {@link InputStream} to read from
49 | * @param executorService
50 | * used to execute the read loop
51 | */
52 | public PollingInputStream(final InputStream inputStream, ExecutorService executorService) {
53 | readBuffer = new byte[BUFFER_CAPACITY];
54 | readPosition = 0;
55 | writePosition = 0;
56 | executorService.execute(new CancellableLoop() {
57 | @Override
58 | protected void loop() throws InterruptedException {
59 | try {
60 | while (remaining() < READ_SIZE) {
61 | if (readPosition < remaining()) {
62 | // There isn't enough room to compact the buffer yet. We will most
63 | // likely start dropping messages.
64 | log.error("Not enough room to compact buffer.");
65 | Thread.yield();
66 | continue;
67 | }
68 | synchronized (readBuffer) {
69 | int remaining = remaining();
70 | System.arraycopy(readBuffer, writePosition, readBuffer, 0, remaining);
71 | writePosition = remaining;
72 | readPosition = 0;
73 | if (DEBUG) {
74 | log.info(String.format("Buffer compacted. %d bytes remaining.", remaining()));
75 | }
76 | }
77 | }
78 | int bytesRead = inputStream.read(readBuffer, writePosition, READ_SIZE);
79 | if (bytesRead < 0) {
80 | throw new IOException("Stream closed.");
81 | }
82 | writePosition += bytesRead;
83 | } catch (IOException e) {
84 | throw new RosRuntimeException(e);
85 | }
86 | }
87 | });
88 | }
89 |
90 | @Override
91 | public synchronized int read(byte[] buffer, int offset, int length) throws IOException {
92 | int bytesRead = 0;
93 | if (length > 0) {
94 | while (available() == 0) {
95 | // Block until there are bytes to read.
96 | Thread.yield();
97 | }
98 | synchronized (readBuffer) {
99 | bytesRead = Math.min(length, available());
100 | System.arraycopy(readBuffer, readPosition, buffer, offset, bytesRead);
101 | readPosition += bytesRead;
102 | }
103 | }
104 | return bytesRead;
105 | }
106 |
107 | @Override
108 | public int read() throws IOException {
109 | byte[] buffer = new byte[1];
110 | return read(buffer, 0, 1);
111 | }
112 |
113 | @Override
114 | public int available() throws IOException {
115 | return writePosition - readPosition;
116 | }
117 |
118 | private int remaining() {
119 | return BUFFER_CAPACITY - writePosition;
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/polling_input_stream/src/test/java/org/ros/android/acm_serial/PollingInputStreamTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.ros.android.acm_serial;
18 |
19 | import static org.junit.Assert.assertArrayEquals;
20 | import static org.junit.Assert.assertEquals;
21 |
22 | import org.junit.Test;
23 |
24 | import java.io.IOException;
25 | import java.io.PipedInputStream;
26 | import java.io.PipedOutputStream;
27 | import java.util.concurrent.Executors;
28 |
29 | /**
30 | * @author damonkohler@google.com (Damon Kohler)
31 | */
32 | public class PollingInputStreamTest {
33 |
34 | @Test
35 | public void testSplitUpWrites() throws IOException {
36 | PipedInputStream pipedInputStream = new PipedInputStream();
37 | PipedOutputStream pipedOutputStream = new PipedOutputStream(pipedInputStream);
38 | PollingInputStream pollingInputStream =
39 | new PollingInputStream(pipedInputStream, Executors.newCachedThreadPool());
40 | byte[] expectedBuffer = new byte[64];
41 | for (int i = 0; i < expectedBuffer.length; i++) {
42 | expectedBuffer[i] = (byte) i;
43 | }
44 | pipedOutputStream.write(expectedBuffer, 0, 16);
45 | pipedOutputStream.write(expectedBuffer, 16, 16);
46 | pipedOutputStream.write(expectedBuffer, 32, 16);
47 | pipedOutputStream.write(expectedBuffer, 48, 16);
48 | byte[] actualBuffer = new byte[64];
49 | assertEquals(64, pollingInputStream.read(actualBuffer));
50 | assertArrayEquals(expectedBuffer, actualBuffer);
51 | }
52 |
53 | @Test
54 | public void testSplitUpReads() throws IOException {
55 | PipedInputStream pipedInputStream = new PipedInputStream();
56 | PipedOutputStream pipedOutputStream = new PipedOutputStream(pipedInputStream);
57 | PollingInputStream pollingInputStream =
58 | new PollingInputStream(pipedInputStream, Executors.newCachedThreadPool());
59 | byte[] expectedBuffer = new byte[64];
60 | for (int i = 0; i < expectedBuffer.length; i++) {
61 | expectedBuffer[i] = (byte) i;
62 | }
63 | pipedOutputStream.write(expectedBuffer, 0, 64);
64 | byte[] actualBuffer = new byte[64];
65 | assertEquals(32, pollingInputStream.read(actualBuffer, 0, 32));
66 | assertEquals(32, pollingInputStream.read(actualBuffer, 32, 32));
67 | assertArrayEquals(expectedBuffer, actualBuffer);
68 | }
69 |
70 | @Test
71 | public void testInterlevedReadAndWrite() throws IOException {
72 | PipedInputStream pipedInputStream = new PipedInputStream();
73 | PipedOutputStream pipedOutputStream = new PipedOutputStream(pipedInputStream);
74 | PollingInputStream pollingInputStream =
75 | new PollingInputStream(pipedInputStream, Executors.newCachedThreadPool());
76 | byte[] expectedBuffer = new byte[64];
77 | for (int i = 0; i < expectedBuffer.length; i++) {
78 | expectedBuffer[i] = (byte) i;
79 | }
80 | byte[] actualBuffer = new byte[64];
81 | pipedOutputStream.write(expectedBuffer, 0, 16);
82 | assertEquals(8, pollingInputStream.read(actualBuffer, 0, 8));
83 | pipedOutputStream.write(expectedBuffer, 16, 48);
84 | int bytesRead = 0;
85 | while (bytesRead < 56) {
86 | bytesRead += pollingInputStream.read(actualBuffer, 8 + bytesRead, 64 - bytesRead);
87 | }
88 | assertArrayEquals(expectedBuffer, actualBuffer);
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | include "android_core_components"
18 | include "android_acm_serial"
19 | include "android_benchmarks"
20 | include "android_tutorial_camera"
21 | include "android_tutorial_image_transport"
22 | include "android_tutorial_map_viewer"
23 | include "android_tutorial_pubsub"
24 | include "android_tutorial_teleop"
25 | include "docs"
26 |
27 | // TODO(damonkohler): The following projects are not included in the
28 | // multi-project yet till its sorted whereabouts they should actually live
29 | // (should they be in a java repo instead?)
30 | // include "compressed_map_transport"
31 | // include "polling_input_stream"
32 |
--------------------------------------------------------------------------------