Skip to content

Commit b4ccbb8

Browse files
authored
Merge pull request #502 from robotemi/sprint_136/goto_speed_0.1_1.5
Goto speed 0.1 to 1.5
2 parents 187f753 + 11fe7ef commit b4ccbb8

File tree

6 files changed

+78
-9
lines changed

6 files changed

+78
-9
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ android.enableJetifier=true
2121
kotlin.code.style=official
2222

2323
GROUP=com.robotemi
24-
VERSION_NAME=1.136.0.12-SNAPSHOT
24+
VERSION_NAME=1.136.0.13-SNAPSHOT
2525
POM_URL=https://github.com/robotemi/sdk/
2626
POM_SCM_URL=https://github.com/robotemi/sdk/
2727
POM_SCM_CONNECTION=scm:git:git://github.com/robotemi/sdk.git
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.robotemi.sdk.sample;
2+
3+
import android.app.Activity;
4+
5+
import com.robotemi.sdk.Robot;
6+
import com.robotemi.sdk.navigation.model.SpeedLevel;
7+
import com.robotemi.sdk.voice.WakeupRequest;
8+
9+
import java.util.ArrayList;
10+
11+
public class MainJavaActivity extends Activity {
12+
13+
/**
14+
* This is sample code to test SDK Java compatibility
15+
*/
16+
private void test() {
17+
Robot.getInstance().setVolume(10);
18+
Robot.getInstance().setVolume(11);
19+
Robot.getInstance().repose();
20+
int volume = Robot.getInstance().getVolume();
21+
Robot.getInstance().setKioskModeOn(false);
22+
23+
Robot.getInstance().wakeup(new ArrayList<>(), new WakeupRequest());
24+
Robot.getInstance().goTo("a", false, false, SpeedLevel.Companion.customSpeed(1.5f));
25+
}
26+
}

sample/src/main/java/com/robotemi/sdk/sample/TemiBroadcastReceiver.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import com.robotemi.sdk.SttLanguage
99
import com.robotemi.sdk.SttRequest
1010
import com.robotemi.sdk.TtsRequest
1111
import com.robotemi.sdk.constants.SequenceCommand
12+
import com.robotemi.sdk.navigation.model.Position
13+
import com.robotemi.sdk.navigation.model.SpeedLevel
1214
import com.robotemi.sdk.voice.WakeupRequest
1315

1416
class TemiBroadcastReceiver : BroadcastReceiver() {
@@ -176,8 +178,9 @@ class TemiBroadcastReceiver : BroadcastReceiver() {
176178
}
177179
}
178180
ACTION_GOTO -> {
179-
// adb shell am broadcast -a temi.debug.sdk --es action "temi.debug.goto" --ei test 1
181+
// adb shell am broadcast -a temi.debug.sdk --es action "temi.debug.goto" --ei test 1 --ef speed 0.5
180182
val test = intent.getIntExtra("test", 1)
183+
val speed = intent.getFloatExtra("speed", 0.0f)
181184
val robot = Robot.getInstance()
182185
val position = robot.getPosition()
183186
when (test) {
@@ -188,6 +191,14 @@ class TemiBroadcastReceiver : BroadcastReceiver() {
188191
5 -> robot.goTo("a", highAccuracyArrival = true)
189192
6 -> robot.goTo("a", highAccuracyArrival = true, noRotationAtEnd = true)
190193
7 -> robot.goTo("a", noRotationAtEnd = true)
194+
8 -> robot.goTo("a", speedLevel = SpeedLevel.HIGH)
195+
9 -> robot.goTo("a", speedLevel = SpeedLevel.MEDIUM)
196+
10 -> robot.goTo("a", speedLevel = SpeedLevel.SLOW, backwards = true)
197+
11 -> robot.goTo("a", speedLevel = SpeedLevel.customSpeed(1.5f), highAccuracyArrival = true)
198+
12 -> robot.goToPosition(Position(1f, 2f, 3f), speedLevel = SpeedLevel.customSpeed(speed), highAccuracyArrival = true)
199+
13 -> robot.goToPosition(Position(1f, 2f, 3f), speedLevel = SpeedLevel.MEDIUM, highAccuracyArrival = true)
200+
14 -> robot.goTo("a", speedLevel = SpeedLevel.customSpeed(speed), highAccuracyArrival = true)
201+
15 -> robot.goTo("b", speedLevel = SpeedLevel.customSpeed(speed), highAccuracyArrival = true)
191202
}
192203
}
193204
}

sdk/src/main/aidl/com/robotemi/sdk/ISdkService.aidl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ interface ISdkService {
9898
*
9999
* @param location - Saved location name.
100100
*/
101-
void goTo(in String location, int backwards, int noBypass, in String speedLevel, int highAccuracyArrival, int noRotationAtEnd);
101+
void goTo(in String location, int backwards, int noBypass, in String speedLevel, int highAccuracyArrival, int noRotationAtEnd, in float floatSpeedLevel);
102102

103103
/**
104104
* Retrieve list of previously saved locations.
@@ -249,7 +249,7 @@ interface ISdkService {
249249

250250
void playSequence(in String packageName, in String sequenceId, boolean withPlayer, int repeat, int startFromStep);
251251

252-
void goToPosition(in Position position, int backwards, int noBypass, in String speedLevel, int highAccuracyArrival);
252+
void goToPosition(in Position position, int backwards, int noBypass, in String speedLevel, int highAccuracyArrival, in float floatSpeedLevel);
253253

254254
MapDataModel getMapData(in String packageName);
255255

sdk/src/main/java/com/robotemi/sdk/Robot.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,7 @@ class Robot private constructor(private val context: Context) {
13851385
speedLevel?.value ?: "",
13861386
highAccuracyArrivalInt,
13871387
noRotationAtEndInt,
1388+
speedLevel?.floatSpeedLevel ?: 0.0f,
13881389
)
13891390
} catch (e: RemoteException) {
13901391
Log.e(TAG, "goTo(String) error")
@@ -1421,7 +1422,8 @@ class Robot private constructor(private val context: Context) {
14211422
allowBackwardsInt,
14221423
noBypassInt,
14231424
speedLevel?.value ?: "",
1424-
highAccuracyArrivalInt
1425+
highAccuracyArrivalInt,
1426+
speedLevel?.floatSpeedLevel ?: 0.0f,
14251427
)
14261428
} catch (e: RemoteException) {
14271429
Log.e(TAG, "goToPosition() error")

sdk/src/main/java/com/robotemi/sdk/navigation/model/SpeedLevel.kt

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
package com.robotemi.sdk.navigation.model
22

3-
enum class SpeedLevel(val value: String) {
3+
import androidx.annotation.FloatRange
44

5-
HIGH("high"),
6-
MEDIUM("medium"),
7-
SLOW("slow");
5+
6+
enum class SpeedLevel(
7+
val value: String,
8+
private var floatValue: Float? = null
9+
) {
10+
11+
HIGH("high"), // 0.9 m/s
12+
MEDIUM("medium"), // 0.7 m/s
13+
SLOW("slow"); // 0.5 m/s
14+
15+
internal val floatSpeedLevel: Float
16+
get() = floatValue ?: 0.0f
817

918
companion object {
1019

@@ -20,5 +29,26 @@ enum class SpeedLevel(val value: String) {
2029
else -> DEFAULT
2130
}
2231
}
32+
33+
/**
34+
* Added in 136 version, use a float value to control the max goto speed level.
35+
* It will fallback to predefined speed level is the temi launcher doesn't support custom speed
36+
*
37+
* @param floatValue the custom max goto speed value, range from 0.1 to 1.5
38+
* Currently V3 and temi platform might not be able to go as fast as 1.5 m/s
39+
* due to obstacle avoidance and ground surface conditions.
40+
* The max speed might be around 1.2 m/s.
41+
* But in the future the limit might be changed to go faster.
42+
*/
43+
fun customSpeed(@FloatRange(from = 0.1, to = 1.5) floatValue: Float): SpeedLevel {
44+
return when {
45+
floatValue < 0.7f - EPSILON -> SLOW
46+
floatValue > 0.9f - EPSILON -> HIGH
47+
else -> MEDIUM
48+
}.apply { this.floatValue = floatValue.coerceAtLeast(0.1f) }
49+
}
50+
51+
// Fix the float precision issue
52+
private const val EPSILON = 1e-6f
2353
}
2454
}

0 commit comments

Comments
 (0)