Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.aldebaran:qisdk:1.4.1'
implementation 'com.aldebaran:qisdk-design:1.4.1'
implementation 'com.aldebaran:qisdk:1.4.3'
implementation 'com.aldebaran:qisdk-design:1.4.3'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'com.snatik:storage:2.1.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
Expand Down
16 changes: 11 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".introduction.IntroductionActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".menu.MenuActivity" />
<activity android:name=".menu.MenuActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".mapping.MappingActivity" />
<activity android:name=".localization.LocalizationActivity" />
<activity android:name=".freeframes.GoToWorldTutorialActivity" />
<activity android:name=".GotoAB.GotoActivity" />
<activity android:name=".GotoAB.GotoPointActivity" />
<activity android:name=".GotoAB.GotoWorldActivity" />
</application>

</manifest>
2 changes: 1 addition & 1 deletion app/src/main/assets/robot/robotsdk.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?>
<robot>
<users-robotsdk minSdkVersion='API 3' />
<users-robotsdk minSdkVersion='API 4' />
</robot>
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Copyright (C) 2018 Softbank Robotics Europe
* See COPYING for the license
*/

package com.softbankrobotics.sample.returntomapframe.GotoAB;

import android.os.Bundle;
import android.util.Log;

import com.aldebaran.qi.Future;
import com.aldebaran.qi.sdk.QiContext;
import com.aldebaran.qi.sdk.QiSDK;
import com.aldebaran.qi.sdk.RobotLifecycleCallbacks;
import com.aldebaran.qi.sdk.builder.GoToBuilder;
import com.aldebaran.qi.sdk.builder.SayBuilder;
import com.aldebaran.qi.sdk.builder.TransformBuilder;
import com.aldebaran.qi.sdk.design.activity.RobotActivity;
import com.aldebaran.qi.sdk.object.actuation.Actuation;
import com.aldebaran.qi.sdk.object.actuation.Frame;
import com.aldebaran.qi.sdk.object.actuation.FreeFrame;
import com.aldebaran.qi.sdk.object.actuation.GoTo;
import com.aldebaran.qi.sdk.object.actuation.Mapping;
import com.aldebaran.qi.sdk.object.conversation.ConversationStatus;
import com.aldebaran.qi.sdk.object.conversation.Say;
import com.aldebaran.qi.sdk.object.geometry.Transform;

/**
* The activity for the GoTo tutorial.
*/
public class GotoActivity extends RobotActivity implements RobotLifecycleCallbacks {

private static final String TAG = "GotoActivity";

// Store the GoTo action.
private GoTo goTo;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Register the RobotLifecycleCallbacks to this Activity.
QiSDK.register(this, this);
}

@Override
protected void onDestroy() {
// Unregister the RobotLifecycleCallbacks for this Activity.
QiSDK.unregister(this, this);
super.onDestroy();
}

@Override
public void onRobotFocusGained(QiContext qiContext) {
// Bind the conversational events to the view.
ConversationStatus conversationStatus = qiContext.getConversation().status(qiContext.getRobotContext());

Say say = SayBuilder.with(qiContext)
.withText("I can move around: I will go 1 meter backward.")
.build();

say.run();

// Get the Actuation service from the QiContext.
Actuation actuation = qiContext.getActuation();

// Get the robot frame.
Frame robotFrame = actuation.robotFrame();

// Create a transform corresponding to a 1 meter forward translation.
Transform transform = TransformBuilder.create().fromXTranslation(2.5);

// Get the Mapping service from the QiContext.
Mapping mapping = qiContext.getMapping();

// Create a FreeFrame with the Mapping service.
FreeFrame targetFrame = mapping.makeFreeFrame();

// Update the target location relatively to Pepper's current location.
targetFrame.update(robotFrame, transform, 0L);

// Create a GoTo action.
goTo = GoToBuilder.with(qiContext) // Create the builder with the QiContext.
.withFrame(targetFrame.frame()) // Set the target frame.
.build(); // Build the GoTo action.

// Add an on started listener on the GoTo action.
goTo.addOnStartedListener(() -> {
String message = "GoTo action started.";
Log.i(TAG, message);
});

// Execute the GoTo action asynchronously.
Future<Void> goToFuture = goTo.async().run();

// Add a lambda to the action execution.
goToFuture.thenConsume(future -> {
if (future.isSuccess()) {
String message = "GoTo action finished with success.";
Actuation actuation1 = qiContext.getActuation();

Frame robotFrame1 = actuation1.robotFrame();

Transform transform1 = TransformBuilder.create().fromXTranslation(0.4);

// Get the Mapping service from the QiContext.
Mapping mapping1 = qiContext.getMapping();

// Create a FreeFrame with the Mapping service.
FreeFrame targetFrame1 = mapping1.makeFreeFrame();

// Update the target location relatively to Pepper's current location.
targetFrame1.update(robotFrame1, transform1, 0L);

// Create a GoTo action.
goTo = GoToBuilder.with(qiContext) // Create the builder with the QiContext.
.withFrame(targetFrame1.frame()) // Set the target frame.
.build(); // Build the GoTo action.
Future<Void> goToFuture1 =goTo.async().run();

goToFuture1.thenConsume(future1 -> {
if (future1.isSuccess()) {
String message1 = "GoTo action finished with success.";
Log.i(TAG, message1);
} else if (future.hasError()) {
String message1 = "GoTo action finished with error.";
Log.e(TAG, message1, future.getError());
}
});

Log.i(TAG, message);
} else if (future.hasError()) {
String message = "GoTo action finished with error.";
Say say1 = SayBuilder.with(qiContext)
.withText("GoTo action finished with error. Try again")
.build();

say1.run();

Log.e(TAG, message, future.getError());
}
});
}

@Override
public void onRobotFocusLost() {
// Remove on started listeners from the GoTo action.
if (goTo != null) {
goTo.removeAllOnStartedListeners();
}
}

@Override
public void onRobotFocusRefused(String reason) {
// Nothing here.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package com.softbankrobotics.sample.returntomapframe.GotoAB;

import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;

import com.aldebaran.qi.Future;
import com.aldebaran.qi.sdk.QiContext;
import com.aldebaran.qi.sdk.QiSDK;
import com.aldebaran.qi.sdk.RobotLifecycleCallbacks;
import com.aldebaran.qi.sdk.builder.GoToBuilder;
import com.aldebaran.qi.sdk.builder.TransformBuilder;
import com.aldebaran.qi.sdk.design.activity.RobotActivity;
import com.aldebaran.qi.sdk.object.actuation.Actuation;
import com.aldebaran.qi.sdk.object.actuation.Frame;
import com.aldebaran.qi.sdk.object.actuation.FreeFrame;
import com.aldebaran.qi.sdk.object.actuation.GoTo;
import com.aldebaran.qi.sdk.object.actuation.Mapping;
import com.aldebaran.qi.sdk.object.geometry.Transform;
import com.softbankrobotics.sample.returntomapframe.R;

public class GotoPointActivity extends RobotActivity implements RobotLifecycleCallbacks {
private static final String TAG = "GotoPointActivity";
private Button gotoButton;
private Button saveButton;
private EditText xCoordinate;
private EditText yCoordinate;
private EditText thetaInRad;

private Double xValue;
private Double yValue;
private Double rotValue;
private GoTo goTo;
private QiContext qiContext;
private Actuation actuation;
// Store the Mapping service.
private Mapping mapping;
private Frame robotFrame;
private FreeFrame targetFrame;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_go_to_world_tutorial);

this.gotoButton = findViewById(R.id.goto_button);
this.saveButton = findViewById(R.id.save_button);
this.xCoordinate = findViewById(R.id.editText2);
this.yCoordinate = findViewById(R.id.editText);
this.thetaInRad = findViewById(R.id.editText3);

this.gotoButton.setOnClickListener(v -> handleGotoClick());
this.saveButton.setOnClickListener(v -> handleSaveClick());

QiSDK.register(this, this);
}

private void handleSaveClick() {
setxValue(Double.valueOf(this.xCoordinate.getText().toString()));
setyValue(Double.valueOf(this.yCoordinate.getText().toString()));
setRotValue(Double.valueOf(this.thetaInRad.getText().toString()));
Log.i(TAG, "X Coordinate: " + getxValue() + "Y Coordinate: " + getyValue() + "Rotation in rad: " + getRotValue());
}

private void handleGotoClick() {

setxValue(Double.valueOf(this.xCoordinate.getText().toString()));
setyValue(Double.valueOf(this.yCoordinate.getText().toString()));
setRotValue(Double.valueOf(this.thetaInRad.getText().toString()));
// Get the Actuation service from the QiContext.

// Get the robot frame.
Thread thread = new Thread(() -> {
try {
robotFrame = actuation.robotFrame();
targetFrame = mapping.makeFreeFrame();
// Create a transform corresponding to a 1 meter forward translation.
Log.i(TAG, "goto X Coordinate: " + getxValue() + " Y Coordinate: " + getyValue() + " Rotation in rad: " + getRotValue());

Transform transform = TransformBuilder.create().from2DTransform(getxValue(), getyValue(), getRotValue());

targetFrame.update(robotFrame, transform, 0L);

// Create a GoTo action.
goTo = GoToBuilder.with(qiContext) // Create the builder with the QiContext.
.withFrame(targetFrame.frame())// Set the target frame.
.build(); // Build the GoTo action.

// Add an on started listener on the GoTo action.
goTo.addOnStartedListener(() -> {
String message = "GoTo action started.";

Log.i(TAG, message);
});

Future<Void> goToFuture = goTo.async().run();
goToFuture.thenConsume(future -> {
if (future.isSuccess()) {
String message = "GoTo action finished with success.";
Log.i(TAG, message);
} else if (future.hasError()) {
String message = "GoTo action finished with error.";
Log.e(TAG, message, future.getError());
}
});
} catch (Exception e) {
e.printStackTrace();
}
});
thread.start();
}


@Override
public void onRobotFocusGained(QiContext qiContext) {
Log.i(TAG, "Focus gained.");
// Store the provided QiContext and services.
this.qiContext = qiContext;

actuation = qiContext.getActuation();
mapping = qiContext.getMapping();



}

@Override
public void onRobotFocusLost() {
Log.i(TAG, "Focus lost.");
// Remove the QiContext.
qiContext = null;

if (goTo != null) {
goTo.removeAllOnStartedListeners();
}
}

@Override
public void onRobotFocusRefused(String reason) {
// Nothing here.
}

public Double getxValue() {
if (xValue == null)
return 0.0;
else
return xValue;
}

public void setxValue(Double xValue) {
this.xValue = xValue;
}

public Double getyValue() {
if (yValue == null)
return 0.0;
else
return yValue;
}

public void setyValue(Double yValue) {
this.yValue = yValue;
}

public Double getRotValue() {
if (rotValue == null)
return 0.0;
else
return (rotValue * ((22/7)/180));
}

public void setRotValue(Double rotValue) {
this.rotValue = rotValue;
}
}
Loading