Skip to content

Commit add8e17

Browse files
authored
Merge pull request #406 from robotemi/sprint_131/minimum_obstacle_distance
Support minimum obstacle distance
2 parents d741257 + d69dc73 commit add8e17

6 files changed

Lines changed: 109 additions & 2 deletions

File tree

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.131.3
24+
VERSION_NAME=1.131.4.0-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

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import android.view.inputmethod.InputMethodManager
2828
import android.widget.AdapterView
2929
import android.widget.AdapterView.OnItemClickListener
3030
import android.widget.ArrayAdapter
31+
import android.widget.SeekBar
32+
import android.widget.SeekBar.OnSeekBarChangeListener
3133
import android.widget.Toast
3234
import androidx.annotation.CheckResult
3335
import androidx.appcompat.app.AppCompatActivity
@@ -472,6 +474,47 @@ class MainActivity : AppCompatActivity(), NlpListener, OnRobotReadyListener,
472474
btnIsFrontTOFEnabled.setOnClickListener { isFrontTOFEnabled() }
473475
btnToggleBackTOF.setOnClickListener { toggleBackTOF() }
474476
btnIsBackTOFEnabled.setOnClickListener { isBackTOFEnabled() }
477+
btnMinimumObstacleDistance.setOnClickListener {
478+
if (requestPermissionIfNeeded(Permission.SETTINGS, REQUEST_CODE_NORMAL)) {
479+
return@setOnClickListener
480+
}
481+
if (robot.minimumObstacleDistance == -1) {
482+
Toast.makeText(this, "Minimum Obstacle Distance settings is not supported on your robot.", Toast.LENGTH_SHORT).show()
483+
return@setOnClickListener
484+
}
485+
486+
if (groupMinimumObstacleDistance.visibility == View.GONE) {
487+
groupMinimumObstacleDistance.visibility = View.VISIBLE
488+
}
489+
val distance = robot.minimumObstacleDistance
490+
textMinimumObstacleDistance.text = "$distance"
491+
seekbarMinimumObstacleDistance.progress = distance.coerceIn(0, 100)
492+
seekbarMinimumObstacleDistance.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
493+
override fun onProgressChanged(
494+
seekBar: SeekBar?,
495+
progress: Int,
496+
fromUser: Boolean
497+
) {
498+
seekBar ?: return
499+
// Round to 5x
500+
val value = seekBar.progress / 5 * 5
501+
seekBar.progress = value
502+
textMinimumObstacleDistance.text = "$value"
503+
}
504+
505+
override fun onStartTrackingTouch(seekBar: SeekBar?) {
506+
// nothing
507+
}
508+
509+
override fun onStopTrackingTouch(seekBar: SeekBar?) {
510+
seekBar ?: return
511+
// Round to 5x
512+
val value = seekBar.progress / 5 * 5
513+
robot.minimumObstacleDistance = value
514+
}
515+
516+
})
517+
}
475518
btnGetAllFloors.setOnClickListener { getAllFloors() }
476519
btnLoadFloorAtElevator.setOnClickListener { loadFloorAtElevator() }
477520
btnGetCurrentFloor.setOnClickListener {

sample/src/main/res/layout/group_map_and_movement.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
style="@style/ButtonCommon"
9898
android:text="tiltBy" />
9999

100-
101100
<Button
102101
android:id="@+id/btnStopMovement"
103102
style="@style/ButtonCommon"

sample/src/main/res/layout/group_settings_and_status.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
android:layout_width="match_parent"
45
android:layout_height="match_parent"
56
android:gravity="center_horizontal"
@@ -60,6 +61,37 @@
6061
style="@style/ButtonCommon"
6162
android:text="Toggle Ground Depth Cliff Detection" />
6263

64+
<LinearLayout
65+
android:id="@+id/groupMinimumObstacleDistance"
66+
android:layout_width="325dp"
67+
android:layout_height="wrap_content"
68+
android:gravity="center"
69+
android:visibility="gone"
70+
tools:visibility="visible">
71+
72+
<TextView
73+
android:id="@+id/textMinimumObstacleDistance"
74+
android:layout_width="wrap_content"
75+
android:layout_height="wrap_content"
76+
android:textColor="@color/temi_primary_green"
77+
android:textSize="18sp"
78+
tools:text="1" />
79+
80+
<SeekBar
81+
android:id="@+id/seekbarMinimumObstacleDistance"
82+
android:layout_width="0dp"
83+
android:layout_height="wrap_content"
84+
android:max="100"
85+
android:layout_weight="1"
86+
android:paddingVertical="20dp" />
87+
88+
</LinearLayout>
89+
90+
<Button
91+
android:id="@+id/btnMinimumObstacleDistance"
92+
style="@style/ButtonCommon"
93+
android:text="Minimum Obstacle Distance" />
94+
6395
<Button
6496
android:id="@+id/btnGetSupportedKeyboard"
6597
style="@style/ButtonCommon"

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,6 @@ interface ISdkService {
359359
int enableStandBy(in String packageName, boolean enabled, in String password);
360360

361361
String startMeeting(in String packageName, in List<Participant> participants, boolean firstParticipantJoinedAsHost);
362+
363+
int configMinimumObstacleDistance(in String packageName, int value);
362364
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,6 +2346,7 @@ class Robot private constructor(private val context: Context) {
23462346

23472347
/**
23482348
* Check or set if the back TOF is enabled.
2349+
* Require [Permission.SETTINGS] permission to change the value
23492350
*/
23502351
@get:JvmName("isBackTOFEnabled")
23512352
@get:CheckResult
@@ -2366,6 +2367,36 @@ class Robot private constructor(private val context: Context) {
23662367
}
23672368
}
23682369

2370+
/**
2371+
* Getter and setter of minimumObstacleDistance
2372+
*
2373+
* Range shall be 0 to 100, with step of 5.
2374+
*
2375+
*
2376+
* If it is not supported in your robot version yet, value will be 0.
2377+
*
2378+
* Require [Permission.SETTINGS] permission to change the value
2379+
*/
2380+
@get:JvmName("minimumObstacleDistance")
2381+
@get:CheckResult
2382+
var minimumObstacleDistance: Int
2383+
get() {
2384+
return try {
2385+
sdkService?.configMinimumObstacleDistance(applicationInfo.packageName, -1) ?: 0
2386+
} catch (e: RemoteException) {
2387+
Log.d(TAG, "get MinimumObstacleDistance error")
2388+
0
2389+
}
2390+
}
2391+
set(value) {
2392+
try {
2393+
val ret = sdkService?.configMinimumObstacleDistance(applicationInfo.packageName, value)
2394+
Log.d(TAG, "set MinimumObstacleDistance ret $ret")
2395+
} catch (e: RemoteException) {
2396+
Log.d(TAG, "set MinimumObstacleDistance error")
2397+
}
2398+
}
2399+
23692400
@Throws(RemoteException::class)
23702401
fun showNormalNotification(notification: NormalNotification) {
23712402
if (sdkService != null) {

0 commit comments

Comments
 (0)