├── settings.gradle ├── app ├── src │ └── main │ │ ├── res │ │ ├── raw │ │ │ ├── error.ogg │ │ │ ├── sonar.ogg │ │ │ ├── success.ogg │ │ │ ├── processing.ogg │ │ │ ├── menu.top │ │ │ └── localization_menu.top │ │ ├── drawable │ │ │ ├── hiding.png │ │ │ ├── pepper_explanation.png │ │ │ ├── button_shape_disabled.xml │ │ │ ├── button_shape_pressed.xml │ │ │ ├── button_shape_selected.xml │ │ │ ├── button_shape_unselected.xml │ │ │ ├── ic_baseline_back.xml │ │ │ ├── ic_baseline_close.xml │ │ │ ├── ic_check.xml │ │ │ ├── button_background_selector.xml │ │ │ └── ic_warning.xml │ │ ├── font │ │ │ ├── open_sans_bold.ttf │ │ │ └── open_sans_semibold.ttf │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ ├── color │ │ │ ├── navigation_tint_selector.xml │ │ │ └── button_text_color_selector.xml │ │ ├── values │ │ │ ├── dimens.xml │ │ │ ├── colors.xml │ │ │ ├── styles.xml │ │ │ └── strings.xml │ │ ├── animator │ │ │ └── button_state_list_animator.xml │ │ └── layout │ │ │ ├── activity_introduction.xml │ │ │ ├── fragment_localization_menu.xml │ │ │ ├── activity_menu.xml │ │ │ ├── activity_localization.xml │ │ │ ├── fragment_go_to_origin.xml │ │ │ ├── fragment_localize.xml │ │ │ └── activity_mapping.xml │ │ ├── assets │ │ ├── robot │ │ │ └── robotsdk.xml │ │ └── lottie │ │ │ └── splashy_loader.json │ │ ├── java │ │ └── com │ │ │ └── softbankrobotics │ │ │ └── sample │ │ │ └── returntomapframe │ │ │ ├── localization │ │ │ ├── ScreenState.java │ │ │ ├── gotoorigin │ │ │ │ ├── GoToOriginState.java │ │ │ │ ├── GoToOriginEvent.java │ │ │ │ ├── GoToOriginScreen.java │ │ │ │ ├── GoToOriginMachine.java │ │ │ │ ├── GoToOriginRobot.java │ │ │ │ └── GoToOriginFragment.java │ │ │ ├── ScreenEvent.java │ │ │ ├── localize │ │ │ │ ├── LocalizeState.java │ │ │ │ ├── LocalizeEvent.java │ │ │ │ ├── LocalizeScreen.java │ │ │ │ ├── LocalizeMachine.java │ │ │ │ ├── LocalizeRobot.java │ │ │ │ └── LocalizeFragment.java │ │ │ ├── Robot.java │ │ │ ├── Screen.java │ │ │ ├── ScreenMachine.java │ │ │ ├── localizationmenu │ │ │ │ ├── LocalizationMenuScreen.java │ │ │ │ ├── LocalizationMenuFragment.java │ │ │ │ └── LocalizationMenuRobot.java │ │ │ ├── LocalizeManager.java │ │ │ └── LocalizationActivity.java │ │ │ ├── mapping │ │ │ ├── MappingState.java │ │ │ ├── MappingEvent.java │ │ │ ├── MappingMachine.java │ │ │ ├── MappingActivity.java │ │ │ └── MappingRobot.java │ │ │ ├── App.java │ │ │ ├── utils │ │ │ └── FutureCancellations.java │ │ │ ├── introduction │ │ │ └── IntroductionActivity.java │ │ │ ├── core │ │ │ └── MapManager.kt │ │ │ └── menu │ │ │ └── MenuActivity.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── README.md ├── COPYING.md ├── gradlew.bat ├── .gitignore └── gradlew /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/src/main/res/raw/error.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/app/src/main/res/raw/error.ogg -------------------------------------------------------------------------------- /app/src/main/res/raw/sonar.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/app/src/main/res/raw/sonar.ogg -------------------------------------------------------------------------------- /app/src/main/res/raw/success.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/app/src/main/res/raw/success.ogg -------------------------------------------------------------------------------- /app/src/main/res/raw/processing.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/app/src/main/res/raw/processing.ogg -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable/hiding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/app/src/main/res/drawable/hiding.png -------------------------------------------------------------------------------- /app/src/main/assets/robot/robotsdk.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/font/open_sans_bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/app/src/main/res/font/open_sans_bold.ttf -------------------------------------------------------------------------------- /app/src/main/res/font/open_sans_semibold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/app/src/main/res/font/open_sans_semibold.ttf -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/pepper_explanation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aldebaran/qisdk-sample-return-to-map-frame/HEAD/app/src/main/res/drawable/pepper_explanation.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_shape_disabled.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_shape_pressed.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_shape_selected.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 03 15:22:29 CEST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/color/navigation_tint_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_shape_unselected.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_back.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_close.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 32sp 4 | 24sp 5 | 2dp 6 | 7dp 7 | 10dp 8 | 20dp 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/localization/ScreenState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.localization; 6 | 7 | /** 8 | * A state for screens. Indicates the current screen. 9 | */ 10 | public enum ScreenState { 11 | NONE, 12 | LOCALIZATION_MENU, 13 | LOCALIZE, 14 | GO_TO_ORIGIN, 15 | END, 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/localization/gotoorigin/GoToOriginState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.localization.gotoorigin; 6 | 7 | /** 8 | * A state for {@link GoToOriginScreen}. 9 | */ 10 | enum GoToOriginState { 11 | IDLE, 12 | BRIEFING, 13 | MOVING, 14 | ERROR, 15 | SUCCESS, 16 | END, 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/mapping/MappingState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.mapping; 6 | 7 | /** 8 | * A state for {@link MappingActivity}. 9 | */ 10 | enum MappingState { 11 | IDLE, 12 | BRIEFING, 13 | ADVICES, 14 | MAPPING, 15 | SAVING_MAP, 16 | ERROR, 17 | SUCCESS, 18 | END, 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_check.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/localization/ScreenEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.localization; 6 | 7 | /** 8 | * An event for screens. 9 | */ 10 | public enum ScreenEvent { 11 | FOCUS_GAINED, 12 | FOCUS_LOST, 13 | BACK, 14 | LOCALIZE_SELECTED, 15 | GO_TO_ORIGIN_SELECTED, 16 | LOCALIZE_END, 17 | GO_TO_ORIGIN_END, 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/localization/localize/LocalizeState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.localization.localize; 6 | 7 | /** 8 | * A state for {@link LocalizeScreen}. 9 | */ 10 | enum LocalizeState { 11 | IDLE, 12 | BRIEFING, 13 | ADVICES, 14 | LOADING_MAP, 15 | LOCALIZING, 16 | ERROR, 17 | SUCCESS, 18 | END, 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/res/raw/menu.top: -------------------------------------------------------------------------------- 1 | topic: ~menu() 2 | 3 | concept: (create) ["{"create a"} new map" "create"] 4 | concept: (use) ["{use} saved map" "use"] 5 | concept: (ok) ^rand["got it" alright] 6 | 7 | proposal: %start $proposal %start_timer 8 | u1: (~create) %create %stop_timer ~ok %create_end 9 | u1: (~use) %use %stop_timer ^first["%map ~ok %use_end" "You need to create a map first ^sameProposal"] 10 | u1: (repeat) %stop_timer ^sameProposal 11 | u1: (e:Dialog/NotUnderstood) %stop_timer Sorry? ^sameProposal -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/localization/gotoorigin/GoToOriginEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.localization.gotoorigin; 6 | 7 | /** 8 | * An event for {@link GoToOriginScreen}. 9 | */ 10 | enum GoToOriginEvent { 11 | START, 12 | STOP, 13 | START_GO_TO_ORIGIN, 14 | GO_TO_ORIGIN_SUCCEEDED, 15 | GO_TO_ORIGIN_FAILED, 16 | SUCCESS_CONFIRMED, 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/mapping/MappingEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.mapping; 6 | 7 | /** 8 | * An event for {@link MappingActivity}. 9 | */ 10 | enum MappingEvent { 11 | FOCUS_GAINED, 12 | FOCUS_LOST, 13 | START_MAPPING, 14 | ADVICES_ENDED, 15 | MAPPING_SUCCEEDED, 16 | MAPPING_FAILED, 17 | SAVING_MAP_SUCCEEDED, 18 | SAVING_MAP_FAILED, 19 | SUCCESS_CONFIRMED, 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | #9e9e9e 8 | 9 | #e0e0e0 10 | #f5f5f5 11 | #eeeeee 12 | #4caf50 13 | 14 | #888888 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/localization/localize/LocalizeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.localization.localize; 6 | 7 | /** 8 | * An event for {@link LocalizeScreen}. 9 | */ 10 | enum LocalizeEvent { 11 | START, 12 | STOP, 13 | START_LOCALIZE, 14 | ADVICES_ENDED, 15 | LOADING_MAP_SUCCEEDED, 16 | LOADING_MAP_FAILED, 17 | LOCALIZE_SUCCEEDED, 18 | LOCALIZE_FAILED, 19 | SUCCESS_CONFIRMED, 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/res/raw/localization_menu.top: -------------------------------------------------------------------------------- 1 | topic: ~localization_menu() 2 | 3 | concept: (localize) ["localize {yourself}"] 4 | concept: (go_to_origin) ["go to {"{your} [initial origin] position"}"] 5 | concept: (ok) ^rand["got it" alright] 6 | 7 | proposal: %start $proposal %start_timer 8 | u1: (~localize) %localize %stop_timer ~ok %localize_end 9 | u1: (~go_to_origin) %go_to_origin %stop_timer ^first["%localized ~ok %go_to_origin_end" "I need to localize myself first ^sameProposal"] 10 | u1: (repeat) %stop_timer ^sameProposal 11 | u1: (e:Dialog/NotUnderstood) %stop_timer Sorry? ^sameProposal 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/App.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe; 6 | 7 | import android.app.Application; 8 | 9 | import com.crashlytics.android.Crashlytics; 10 | 11 | import io.fabric.sdk.android.Fabric; 12 | 13 | public class App extends Application { 14 | @Override 15 | public void onCreate() { 16 | super.onCreate(); 17 | if (!BuildConfig.DEBUG) { 18 | Fabric.with(this, new Crashlytics()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/res/color/button_text_color_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 10 | 15 | 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/localization/Robot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.localization; 6 | 7 | import com.aldebaran.qi.Future; 8 | 9 | import androidx.annotation.NonNull; 10 | 11 | /** 12 | * A robotic component. 13 | */ 14 | public interface Robot { 15 | /** 16 | * Meant to be called when the robotic component must stop. 17 | * This is the place where related actions must be stopped. 18 | * 19 | * @return A {@link Future} that is a success when the robotic component has correctly stopped. 20 | */ 21 | @NonNull 22 | Future stop(); 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_background_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 10 | 15 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_warning.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | android.enableJetifier=true 10 | android.useAndroidX=true 11 | org.gradle.jvmargs=-Xmx1536m 12 | # When configured, Gradle will run in incubating parallel mode. 13 | # This option should only be used with decoupled projects. More details, visit 14 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 15 | # org.gradle.parallel=true 16 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/localization/Screen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.localization; 6 | 7 | import com.aldebaran.qi.Future; 8 | import com.aldebaran.qi.sdk.QiContext; 9 | 10 | import androidx.annotation.NonNull; 11 | 12 | /** 13 | * A screen. Coordinates a visual UI and a robotic UI. 14 | */ 15 | public interface Screen { 16 | /** 17 | * Meant to be called when the screen must start. 18 | * This is the place where visual UI should be displayed and robotic UI should start its behavior. 19 | * 20 | * @param qiContext the qiContext 21 | */ 22 | void start(@NonNull QiContext qiContext); 23 | 24 | /** 25 | * Meant to be called when the screen must stop. 26 | * This is the place where the visual UI and the robotic UI must be stopped. 27 | * 28 | * @return A {@link Future} that is a success when the screen has correctly stopped. 29 | */ 30 | @NonNull 31 | Future stop(); 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Return To MapFrame 2 | 3 | **Return To MapFrame** is an Android application for **Pepper the robot**. It was developed using the QiSDK (https://qisdk.softbankrobotics.com). 4 | 5 | This sample shows how to use **LocalizeAndMap** and **Localize** actions to: 6 | * Compute a map of an environment. 7 | * Use a map to make Pepper localize himself in the corresponding environment. 8 | * Make Pepper return to his original position, defined as the position where he started mapping his environment (map frame). 9 | 10 | ## Minimum configuration 11 | 12 | * Pepper 1.9. 13 | * API level 3. 14 | * A real robot (does not work on a virtual robot). 15 | 16 | ## Application flow 17 | 18 | ### Introduction 19 | 20 | Pepper will explain the purpose of this sample. 21 | 22 | ### Menu 23 | 24 | Select if you want to map Pepper's environment or use a saved map. 25 | 26 | ### Create a new map 27 | 28 | Follow instructions so that Pepper can map his surroundings and save the resulting map. 29 | 30 | ### Use saved map 31 | 32 | Select if you want Pepper to localize himself or if you want him to go to his initial position. 33 | 34 | ### Localization 35 | 36 | Follow instructions so that Pepper can localize himself in his environment. 37 | 38 | ### Go to initial position 39 | 40 | Follow instructions so that Pepper can go to his original position (map frame). 41 | 42 | ## License 43 | 44 | See the [COPYING](COPYING.md) file for the license. 45 | -------------------------------------------------------------------------------- /app/src/main/res/animator/button_state_list_animator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 14 | 19 | 20 | 21 | 25 | 30 | 31 | 32 | 33 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_introduction.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | 31 | 32 | -------------------------------------------------------------------------------- /COPYING.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018, SoftBank Robotics Europe\ 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the SoftBank Robotics Europe nor the names of 13 | its contributors may be used to endorse or promote products derived 14 | from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 17 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SoftBank Robotics 20 | Europe BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/localization/gotoorigin/GoToOriginScreen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.localization.gotoorigin; 6 | 7 | import com.aldebaran.qi.Future; 8 | import com.aldebaran.qi.sdk.QiContext; 9 | import com.softbankrobotics.sample.returntomapframe.R; 10 | import com.softbankrobotics.sample.returntomapframe.localization.LocalizationActivity; 11 | import com.softbankrobotics.sample.returntomapframe.localization.Screen; 12 | import com.softbankrobotics.sample.returntomapframe.localization.ScreenEvent; 13 | 14 | import androidx.annotation.NonNull; 15 | 16 | /** 17 | * The go to origin screen. 18 | */ 19 | public class GoToOriginScreen implements Screen { 20 | 21 | @NonNull 22 | private final LocalizationActivity activity; 23 | @NonNull 24 | private final GoToOriginRobot robot; 25 | @NonNull 26 | private final GoToOriginMachine machine = new GoToOriginMachine(); 27 | 28 | public GoToOriginScreen(@NonNull LocalizationActivity activity) { 29 | this.activity = activity; 30 | this.robot = new GoToOriginRobot(machine); 31 | } 32 | 33 | @Override 34 | public void start(@NonNull QiContext qiContext) { 35 | activity.setNavigationTitle(R.string.go_to_origin_title); 36 | 37 | GoToOriginFragment fragment = GoToOriginFragment.newInstance(this, machine); 38 | activity.showFragment(fragment); 39 | robot.start(qiContext); 40 | } 41 | 42 | @NonNull 43 | @Override 44 | public Future stop() { 45 | return robot.stop(); 46 | } 47 | 48 | void onGoToOriginEnd() { 49 | activity.getScreenMachine().post(ScreenEvent.GO_TO_ORIGIN_END); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/localization/localize/LocalizeScreen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.localization.localize; 6 | 7 | import com.aldebaran.qi.Future; 8 | import com.aldebaran.qi.sdk.QiContext; 9 | import com.softbankrobotics.sample.returntomapframe.R; 10 | import com.softbankrobotics.sample.returntomapframe.localization.LocalizationActivity; 11 | import com.softbankrobotics.sample.returntomapframe.localization.LocalizeManager; 12 | import com.softbankrobotics.sample.returntomapframe.localization.Screen; 13 | import com.softbankrobotics.sample.returntomapframe.localization.ScreenEvent; 14 | 15 | import androidx.annotation.NonNull; 16 | 17 | /** 18 | * The localize screen. 19 | */ 20 | public class LocalizeScreen implements Screen { 21 | 22 | @NonNull 23 | private final LocalizationActivity activity; 24 | @NonNull 25 | private final LocalizeRobot robot; 26 | @NonNull 27 | private final LocalizeMachine machine; 28 | 29 | public LocalizeScreen(@NonNull LocalizationActivity activity, @NonNull LocalizeManager localizeManager) { 30 | this.activity = activity; 31 | this.machine = new LocalizeMachine(localizeManager); 32 | this.robot = new LocalizeRobot(machine, localizeManager); 33 | } 34 | 35 | @Override 36 | public void start(@NonNull QiContext qiContext) { 37 | activity.setNavigationTitle(R.string.localize_title); 38 | 39 | LocalizeFragment fragment = LocalizeFragment.newInstance(this, machine); 40 | activity.showFragment(fragment); 41 | robot.start(qiContext); 42 | } 43 | 44 | @NonNull 45 | @Override 46 | public Future stop() { 47 | return robot.stop(); 48 | } 49 | 50 | void onLocalizeEnd() { 51 | activity.getScreenMachine().post(ScreenEvent.LOCALIZE_END); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_localization_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 24 | 25 | 39 | 40 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { maven { url 'https://maven.fabric.io/public' } } 3 | dependencies { classpath 'io.fabric.tools:gradle:1.29.0' } 4 | } 5 | 6 | apply plugin: 'com.android.application' 7 | apply plugin: 'kotlin-android' 8 | apply plugin: 'kotlin-android-extensions' 9 | apply plugin: 'io.fabric' 10 | 11 | repositories { maven { url 'https://maven.fabric.io/public' } } 12 | 13 | android { 14 | compileSdkVersion 29 15 | defaultConfig { 16 | applicationId 'com.softbankrobotics.sample.returntomapframe' 17 | minSdkVersion 23 18 | targetSdkVersion 29 19 | versionCode 7 20 | versionName '2.0.5' 21 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 22 | vectorDrawables.useSupportLibrary = true 23 | } 24 | buildTypes { 25 | release { 26 | minifyEnabled false 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 28 | } 29 | } 30 | compileOptions { 31 | sourceCompatibility JavaVersion.VERSION_1_8 32 | targetCompatibility JavaVersion.VERSION_1_8 33 | } 34 | } 35 | 36 | dependencies { 37 | 38 | // "libs" folder 39 | implementation fileTree(include: ['*.jar'], dir: 'libs') 40 | 41 | // Kotlin 42 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 43 | 44 | // AndroidX 45 | implementation 'androidx.appcompat:appcompat:1.1.0' 46 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 47 | 48 | // RxJava 49 | implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' 50 | implementation 'io.reactivex.rxjava2:rxjava:2.2.19' 51 | 52 | // QiSDK 53 | implementation "com.aldebaran:qisdk:$qisdk_version" 54 | implementation "com.aldebaran:qisdk-design:$qisdk_version" 55 | 56 | // Fields & methods binding 57 | implementation "com.jakewharton:butterknife:$butterknife_version" 58 | annotationProcessor "com.jakewharton:butterknife-compiler:$butterknife_version" 59 | 60 | // After Effects animations 61 | implementation 'com.airbnb.android:lottie:2.7.0' 62 | 63 | // Crashlytics 64 | implementation('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') { transitive = true } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/utils/FutureCancellations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.utils; 6 | 7 | import com.aldebaran.qi.Future; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import androidx.annotation.NonNull; 13 | import androidx.annotation.Nullable; 14 | 15 | /** 16 | * Provide utility methods to cancel futures and to be notified when the cancellation is done. 17 | */ 18 | public final class FutureCancellations { 19 | 20 | private FutureCancellations() { 21 | } 22 | 23 | /** 24 | * Cancel all the provided futures. 25 | * 26 | * @param futuresToCancel the futures to cancel 27 | * @return A {@link Future} that can only end in a success state, when all the provided futures are cancelled. 28 | * If the futures to cancel are already done, this method returns immediately. 29 | */ 30 | @NonNull 31 | public static Future cancel(@Nullable Future... futuresToCancel) { 32 | if (futuresToCancel == null) { 33 | return Future.of(null); 34 | } 35 | 36 | List> cancellations = new ArrayList<>(); 37 | 38 | for (Future futureToCancel : futuresToCancel) { 39 | Future cancellation = cancelFuture(futureToCancel); 40 | cancellations.add(cancellation); 41 | } 42 | 43 | Future[] cancellationsArray = new Future[cancellations.size()]; 44 | return Future.waitAll(cancellations.toArray(cancellationsArray)); 45 | } 46 | 47 | /** 48 | * Cancel the provided {@link Future}. 49 | * 50 | * @param futureToCancel the {@link Future} to cancel 51 | * @return A {@link Future} that can only end in a success state, when the provided {@link Future} is cancelled. 52 | * If the {@link Future} to cancel is already done, this method returns immediately. 53 | */ 54 | @NonNull 55 | private static Future cancelFuture(@Nullable Future futureToCancel) { 56 | if (futureToCancel == null) { 57 | return Future.of(null); 58 | } 59 | 60 | futureToCancel.requestCancellation(); 61 | return futureToCancel.thenConsume(future -> {}); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | 35 | 36 | 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_localization.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | 30 | 31 | 44 | 45 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/introduction/IntroductionActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.introduction; 6 | 7 | import android.content.Intent; 8 | import android.os.Bundle; 9 | import android.util.Log; 10 | 11 | import com.aldebaran.qi.sdk.QiContext; 12 | import com.aldebaran.qi.sdk.QiSDK; 13 | import com.aldebaran.qi.sdk.RobotLifecycleCallbacks; 14 | import com.aldebaran.qi.sdk.builder.SayBuilder; 15 | import com.aldebaran.qi.sdk.design.activity.RobotActivity; 16 | import com.aldebaran.qi.sdk.object.conversation.Say; 17 | import com.softbankrobotics.sample.returntomapframe.R; 18 | import com.softbankrobotics.sample.returntomapframe.menu.MenuActivity; 19 | 20 | import androidx.annotation.NonNull; 21 | import butterknife.ButterKnife; 22 | import butterknife.OnClick; 23 | 24 | /** 25 | * The introduction Activity. 26 | */ 27 | public class IntroductionActivity extends RobotActivity implements RobotLifecycleCallbacks { 28 | 29 | @NonNull 30 | private static final String TAG = "IntroductionActivity"; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | 36 | setContentView(R.layout.activity_introduction); 37 | ButterKnife.bind(this); 38 | 39 | QiSDK.register(this, this); 40 | } 41 | 42 | @Override 43 | protected void onDestroy() { 44 | QiSDK.unregister(this, this); 45 | super.onDestroy(); 46 | } 47 | 48 | @Override 49 | public void onRobotFocusGained(QiContext qiContext) { 50 | Say say = SayBuilder.with(qiContext) 51 | .withResource(R.string.intro_speech) 52 | .build(); 53 | 54 | say.async().run() 55 | .andThenConsume(ignored -> goToMenu()); 56 | } 57 | 58 | @Override 59 | public void onRobotFocusLost() { 60 | // Not used. 61 | } 62 | 63 | @Override 64 | public void onRobotFocusRefused(String reason) { 65 | Log.e(TAG, "onRobotFocusRefused: " + reason); 66 | } 67 | 68 | @OnClick(R.id.closeButton) 69 | public void onCloseClicked() { 70 | finishAffinity(); 71 | } 72 | 73 | private void goToMenu() { 74 | runOnUiThread(() -> { 75 | Intent intent = new Intent(this, MenuActivity.class); 76 | startActivity(intent); 77 | finish(); 78 | }); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 23 | 24 | 28 | 29 | 33 | 34 | 46 | 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Android 2 | 3 | 4 | # Built application files 5 | *.apk 6 | *.ap_ 7 | *.aab 8 | 9 | # Files for the ART/Dalvik VM 10 | *.dex 11 | 12 | # Generated files 13 | bin/ 14 | gen/ 15 | out/ 16 | 17 | # Gradle files 18 | .gradle/ 19 | build/ 20 | .gradletasknamecache 21 | gradle-app.setting 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | gradle.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Android Studio Navigation editor temp files 31 | .navigation/ 32 | 33 | # Android Studio captures folder 34 | captures/ 35 | 36 | # IntelliJ 37 | *.iml 38 | .idea/ 39 | .idea_modules/ 40 | 41 | # Keystore files 42 | # Uncomment the following lines if you do not want to check your keystore files in. 43 | #*.jks 44 | #*.keystore 45 | 46 | # External native build folder generated in Android Studio 2.2 and later 47 | .externalNativeBuild 48 | 49 | # Google Services (e.g. APIs or Firebase) 50 | google-services.json 51 | 52 | # Freeline 53 | freeline.py 54 | freeline/ 55 | freeline_project_description.json 56 | 57 | # fastlane 58 | fastlane/report.xml 59 | fastlane/Preview.html 60 | fastlane/screenshots 61 | fastlane/test_output 62 | fastlane/readme.md 63 | 64 | # Crashlytics plugin (for Android Studio and IntelliJ) 65 | com_crashlytics_export_strings.xml 66 | crashlytics.properties 67 | crashlytics-build.properties 68 | fabric.properties 69 | 70 | 71 | 72 | # Java & Kotlin 73 | 74 | 75 | # Compiled class file 76 | *.class 77 | 78 | # Log file 79 | *.log 80 | 81 | # BlueJ files 82 | *.ctxt 83 | 84 | # Mobile Tools for Java (J2ME) 85 | .mtj.tmp/ 86 | 87 | # Package Files # 88 | *.jar 89 | *.war 90 | *.nar 91 | *.ear 92 | *.zip 93 | *.tar.gz 94 | *.rar 95 | 96 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 97 | !gradle-wrapper.jar 98 | 99 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 100 | hs_err_pid* 101 | 102 | 103 | 104 | # Others 105 | 106 | 107 | # Mac OS 108 | .DS_Store 109 | .AppleDouble 110 | .LSOverride 111 | 112 | # CMake 113 | cmake-build-debug/ 114 | cmake-build-release/ 115 | 116 | # File-based project format 117 | *.iws 118 | 119 | # JIRA plugin 120 | atlassian-ide-plugin.xml 121 | 122 | # Files that might appear in the root of a volume 123 | .DocumentRevisions-V100 124 | .fseventsd 125 | .Spotlight-V100 126 | .TemporaryItems 127 | .Trashes 128 | .VolumeIcon.icns 129 | .com.apple.timemachine.donotpresent 130 | 131 | # Directories potentially created on remote AFP share 132 | .AppleDB 133 | .AppleDesktop 134 | Network Trash Folder 135 | Temporary Items 136 | .apdisk 137 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/localization/gotoorigin/GoToOriginMachine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.localization.gotoorigin; 6 | 7 | import androidx.annotation.NonNull; 8 | import io.reactivex.Observable; 9 | import io.reactivex.subjects.BehaviorSubject; 10 | 11 | /** 12 | * The state machine for {@link GoToOriginScreen}. 13 | */ 14 | class GoToOriginMachine { 15 | 16 | @NonNull 17 | private final BehaviorSubject subject = BehaviorSubject.createDefault(GoToOriginState.IDLE); 18 | 19 | /** 20 | * Post an event to the machine. 21 | * 22 | * @param event the event 23 | */ 24 | void post(@NonNull GoToOriginEvent event) { 25 | GoToOriginState currentState = subject.getValue(); 26 | if (currentState == null) { 27 | throw new IllegalStateException("GoToOriginMachine must have a GoToOriginState to be able to handle a GoToOriginEvent."); 28 | } 29 | 30 | GoToOriginState newState = reduce(currentState, event); 31 | subject.onNext(newState); 32 | } 33 | 34 | /** 35 | * Provide the current {@link GoToOriginState}. 36 | * 37 | * @return The current {@link GoToOriginState}. 38 | */ 39 | @NonNull 40 | Observable goToOriginState() { 41 | return subject.distinctUntilChanged(); 42 | } 43 | 44 | @NonNull 45 | private GoToOriginState reduce(@NonNull GoToOriginState currentState, @NonNull GoToOriginEvent event) { 46 | switch (event) { 47 | case START: 48 | if (currentState.equals(GoToOriginState.IDLE)) { 49 | return GoToOriginState.BRIEFING; 50 | } 51 | break; 52 | case STOP: 53 | return GoToOriginState.IDLE; 54 | case START_GO_TO_ORIGIN: 55 | if (currentState.equals(GoToOriginState.BRIEFING) || currentState.equals(GoToOriginState.ERROR)) { 56 | return GoToOriginState.MOVING; 57 | } 58 | break; 59 | case GO_TO_ORIGIN_SUCCEEDED: 60 | if (currentState.equals(GoToOriginState.MOVING)) { 61 | return GoToOriginState.SUCCESS; 62 | } 63 | break; 64 | case GO_TO_ORIGIN_FAILED: 65 | if (currentState.equals(GoToOriginState.MOVING)) { 66 | return GoToOriginState.ERROR; 67 | } 68 | break; 69 | case SUCCESS_CONFIRMED: 70 | if (currentState.equals(GoToOriginState.SUCCESS)) { 71 | return GoToOriginState.END; 72 | } 73 | break; 74 | } 75 | 76 | return currentState; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/localization/ScreenMachine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.localization; 6 | 7 | import androidx.annotation.NonNull; 8 | import io.reactivex.Observable; 9 | import io.reactivex.subjects.BehaviorSubject; 10 | 11 | /** 12 | * The state machine for screens. 13 | */ 14 | public class ScreenMachine { 15 | 16 | @NonNull 17 | private final BehaviorSubject subject = BehaviorSubject.createDefault(ScreenState.NONE); 18 | 19 | /** 20 | * Post an event to the machine. 21 | * 22 | * @param event the event 23 | */ 24 | public void post(@NonNull ScreenEvent event) { 25 | ScreenState currentState = subject.getValue(); 26 | if (currentState == null) { 27 | throw new IllegalStateException("ScreenMachine must have a ScreenState to be able to handle a ScreenEvent."); 28 | } 29 | 30 | ScreenState newState = reduce(currentState, event); 31 | subject.onNext(newState); 32 | } 33 | 34 | /** 35 | * Provide the current {@link ScreenState}. 36 | * 37 | * @return The current {@link ScreenState}. 38 | */ 39 | @NonNull 40 | Observable screenState() { 41 | return subject.distinctUntilChanged(); 42 | } 43 | 44 | @NonNull 45 | private ScreenState reduce(@NonNull ScreenState currentState, @NonNull ScreenEvent event) { 46 | switch (event) { 47 | case FOCUS_GAINED: 48 | if (currentState.equals(ScreenState.NONE)) { 49 | return ScreenState.LOCALIZATION_MENU; 50 | } 51 | break; 52 | case FOCUS_LOST: 53 | return ScreenState.NONE; 54 | case BACK: 55 | switch (currentState) { 56 | case LOCALIZATION_MENU: 57 | return ScreenState.END; 58 | case LOCALIZE: 59 | return ScreenState.LOCALIZATION_MENU; 60 | case GO_TO_ORIGIN: 61 | return ScreenState.LOCALIZATION_MENU; 62 | } 63 | break; 64 | case LOCALIZE_SELECTED: 65 | if (currentState.equals(ScreenState.LOCALIZATION_MENU)) { 66 | return ScreenState.LOCALIZE; 67 | } 68 | break; 69 | case GO_TO_ORIGIN_SELECTED: 70 | if (currentState.equals(ScreenState.LOCALIZATION_MENU)) { 71 | return ScreenState.GO_TO_ORIGIN; 72 | } 73 | break; 74 | case LOCALIZE_END: 75 | if (currentState.equals(ScreenState.LOCALIZE)) { 76 | return ScreenState.LOCALIZATION_MENU; 77 | } 78 | break; 79 | case GO_TO_ORIGIN_END: 80 | if (currentState.equals(ScreenState.GO_TO_ORIGIN)) { 81 | return ScreenState.LOCALIZATION_MENU; 82 | } 83 | break; 84 | } 85 | 86 | return currentState; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/mapping/MappingMachine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.mapping; 6 | 7 | import androidx.annotation.NonNull; 8 | import io.reactivex.Observable; 9 | import io.reactivex.subjects.BehaviorSubject; 10 | 11 | /** 12 | * The state machine for {@link MappingActivity}. 13 | */ 14 | class MappingMachine { 15 | 16 | @NonNull 17 | private final BehaviorSubject subject = BehaviorSubject.createDefault(MappingState.IDLE); 18 | 19 | /** 20 | * Post an event to the machine. 21 | * 22 | * @param event the event 23 | */ 24 | void post(@NonNull MappingEvent event) { 25 | MappingState currentState = subject.getValue(); 26 | if (currentState == null) { 27 | throw new IllegalStateException("MappingMachine must have a MappingState to be able to handle a MappingEvent."); 28 | } 29 | 30 | MappingState newState = reduce(currentState, event); 31 | subject.onNext(newState); 32 | } 33 | 34 | /** 35 | * Provide the current {@link MappingState}. 36 | * 37 | * @return The current {@link MappingState}. 38 | */ 39 | @NonNull 40 | Observable mappingState() { 41 | return subject.distinctUntilChanged(); 42 | } 43 | 44 | @NonNull 45 | private MappingState reduce(@NonNull MappingState currentState, @NonNull MappingEvent event) { 46 | switch (event) { 47 | case FOCUS_GAINED: 48 | if (currentState.equals(MappingState.IDLE)) { 49 | return MappingState.BRIEFING; 50 | } 51 | break; 52 | case FOCUS_LOST: 53 | return MappingState.IDLE; 54 | case START_MAPPING: 55 | if (currentState.equals(MappingState.BRIEFING) || currentState.equals(MappingState.ERROR)) { 56 | return MappingState.ADVICES; 57 | } 58 | break; 59 | case ADVICES_ENDED: 60 | if (currentState.equals(MappingState.ADVICES)) { 61 | return MappingState.MAPPING; 62 | } 63 | break; 64 | case MAPPING_SUCCEEDED: 65 | if (currentState.equals(MappingState.MAPPING)) { 66 | return MappingState.SAVING_MAP; 67 | } 68 | break; 69 | case MAPPING_FAILED: 70 | if (currentState.equals(MappingState.MAPPING)) { 71 | return MappingState.ERROR; 72 | } 73 | break; 74 | case SAVING_MAP_SUCCEEDED: 75 | return MappingState.SUCCESS; 76 | case SAVING_MAP_FAILED: 77 | if (currentState.equals(MappingState.SAVING_MAP)) { 78 | return MappingState.ERROR; 79 | } 80 | break; 81 | case SUCCESS_CONFIRMED: 82 | if (currentState.equals(MappingState.SUCCESS)) { 83 | return MappingState.END; 84 | } 85 | break; 86 | } 87 | 88 | return currentState; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/softbankrobotics/sample/returntomapframe/localization/localizationmenu/LocalizationMenuScreen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoftBank Robotics Europe 3 | * See COPYING for the license 4 | */ 5 | package com.softbankrobotics.sample.returntomapframe.localization.localizationmenu; 6 | 7 | import com.aldebaran.qi.Future; 8 | import com.aldebaran.qi.sdk.QiContext; 9 | import com.softbankrobotics.sample.returntomapframe.R; 10 | import com.softbankrobotics.sample.returntomapframe.localization.LocalizationActivity; 11 | import com.softbankrobotics.sample.returntomapframe.localization.LocalizeManager; 12 | import com.softbankrobotics.sample.returntomapframe.localization.Screen; 13 | import com.softbankrobotics.sample.returntomapframe.localization.ScreenEvent; 14 | 15 | import androidx.annotation.NonNull; 16 | import androidx.annotation.Nullable; 17 | 18 | /** 19 | * The localization menu screen. 20 | */ 21 | public class LocalizationMenuScreen implements Screen { 22 | 23 | @NonNull 24 | private final LocalizationActivity activity; 25 | @NonNull 26 | private final LocalizationMenuRobot robot; 27 | @Nullable 28 | private LocalizationMenuFragment localizationMenuFragment; 29 | 30 | public LocalizationMenuScreen(@NonNull LocalizationActivity activity, @NonNull LocalizeManager localizeManager) { 31 | this.activity = activity; 32 | this.robot = new LocalizationMenuRobot(this, localizeManager); 33 | } 34 | 35 | @Override 36 | public void start(@NonNull QiContext qiContext) { 37 | activity.setNavigationTitle(R.string.localization_menu_title); 38 | 39 | localizationMenuFragment = LocalizationMenuFragment.newInstance(this); 40 | activity.showFragment(localizationMenuFragment); 41 | robot.startDiscussion(qiContext); 42 | } 43 | 44 | @NonNull 45 | @Override 46 | public Future stop() { 47 | return robot.stop(); 48 | } 49 | 50 | void enableGoToOrigin() { 51 | if (localizationMenuFragment != null) { 52 | localizationMenuFragment.enableGoToOrigin(); 53 | } 54 | } 55 | 56 | void disableChoices() { 57 | if (localizationMenuFragment != null) { 58 | localizationMenuFragment.disableChoices(); 59 | } 60 | } 61 | 62 | void selectLocalize() { 63 | if (localizationMenuFragment != null) { 64 | localizationMenuFragment.selectLocalize(); 65 | } 66 | } 67 | 68 | void selectGoToOrigin() { 69 | if (localizationMenuFragment != null) { 70 | localizationMenuFragment.selectGoToOrigin(); 71 | } 72 | } 73 | 74 | void onLocalizeSelected() { 75 | activity.getScreenMachine().post(ScreenEvent.LOCALIZE_SELECTED); 76 | } 77 | 78 | void onGoToOriginSelected() { 79 | activity.getScreenMachine().post(ScreenEvent.GO_TO_ORIGIN_SELECTED); 80 | } 81 | 82 | void onLocalizeClicked() { 83 | if (localizationMenuFragment != null) { 84 | localizationMenuFragment.disableChoices(); 85 | } 86 | robot.goToLocalizeBookmark(); 87 | } 88 | 89 | void onGoToInitialPositionClicked() { 90 | if (localizationMenuFragment != null) { 91 | localizationMenuFragment.disableChoices(); 92 | } 93 | robot.goToGoToInitialPositionBookmark(); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_go_to_origin.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |