Skip to content

Commit

Permalink
Merge pull request #406 from robotemi/sprint_131/minimum_obstacle_dis…
Browse files Browse the repository at this point in the history
…tance

Support minimum obstacle distance
  • Loading branch information
zjn0505 authored Aug 7, 2023
2 parents d741257 + d69dc73 commit add8e17
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android.enableJetifier=true
kotlin.code.style=official

GROUP=com.robotemi
VERSION_NAME=1.131.3
VERSION_NAME=1.131.4.0-SNAPSHOT
POM_URL=https://github.com/robotemi/sdk/
POM_SCM_URL=https://github.com/robotemi/sdk/
POM_SCM_CONNECTION=scm:git:git://github.com/robotemi/sdk.git
Expand Down
43 changes: 43 additions & 0 deletions sample/src/main/java/com/robotemi/sdk/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import android.view.inputmethod.InputMethodManager
import android.widget.AdapterView
import android.widget.AdapterView.OnItemClickListener
import android.widget.ArrayAdapter
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.Toast
import androidx.annotation.CheckResult
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -472,6 +474,47 @@ class MainActivity : AppCompatActivity(), NlpListener, OnRobotReadyListener,
btnIsFrontTOFEnabled.setOnClickListener { isFrontTOFEnabled() }
btnToggleBackTOF.setOnClickListener { toggleBackTOF() }
btnIsBackTOFEnabled.setOnClickListener { isBackTOFEnabled() }
btnMinimumObstacleDistance.setOnClickListener {
if (requestPermissionIfNeeded(Permission.SETTINGS, REQUEST_CODE_NORMAL)) {
return@setOnClickListener
}
if (robot.minimumObstacleDistance == -1) {
Toast.makeText(this, "Minimum Obstacle Distance settings is not supported on your robot.", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}

if (groupMinimumObstacleDistance.visibility == View.GONE) {
groupMinimumObstacleDistance.visibility = View.VISIBLE
}
val distance = robot.minimumObstacleDistance
textMinimumObstacleDistance.text = "$distance"
seekbarMinimumObstacleDistance.progress = distance.coerceIn(0, 100)
seekbarMinimumObstacleDistance.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
override fun onProgressChanged(
seekBar: SeekBar?,
progress: Int,
fromUser: Boolean
) {
seekBar ?: return
// Round to 5x
val value = seekBar.progress / 5 * 5
seekBar.progress = value
textMinimumObstacleDistance.text = "$value"
}

override fun onStartTrackingTouch(seekBar: SeekBar?) {
// nothing
}

override fun onStopTrackingTouch(seekBar: SeekBar?) {
seekBar ?: return
// Round to 5x
val value = seekBar.progress / 5 * 5
robot.minimumObstacleDistance = value
}

})
}
btnGetAllFloors.setOnClickListener { getAllFloors() }
btnLoadFloorAtElevator.setOnClickListener { loadFloorAtElevator() }
btnGetCurrentFloor.setOnClickListener {
Expand Down
1 change: 0 additions & 1 deletion sample/src/main/res/layout/group_map_and_movement.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
style="@style/ButtonCommon"
android:text="tiltBy" />


<Button
android:id="@+id/btnStopMovement"
style="@style/ButtonCommon"
Expand Down
32 changes: 32 additions & 0 deletions sample/src/main/res/layout/group_settings_and_status.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
Expand Down Expand Up @@ -60,6 +61,37 @@
style="@style/ButtonCommon"
android:text="Toggle Ground Depth Cliff Detection" />

<LinearLayout
android:id="@+id/groupMinimumObstacleDistance"
android:layout_width="325dp"
android:layout_height="wrap_content"
android:gravity="center"
android:visibility="gone"
tools:visibility="visible">

<TextView
android:id="@+id/textMinimumObstacleDistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/temi_primary_green"
android:textSize="18sp"
tools:text="1" />

<SeekBar
android:id="@+id/seekbarMinimumObstacleDistance"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:max="100"
android:layout_weight="1"
android:paddingVertical="20dp" />

</LinearLayout>

<Button
android:id="@+id/btnMinimumObstacleDistance"
style="@style/ButtonCommon"
android:text="Minimum Obstacle Distance" />

<Button
android:id="@+id/btnGetSupportedKeyboard"
style="@style/ButtonCommon"
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/main/aidl/com/robotemi/sdk/ISdkService.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,6 @@ interface ISdkService {
int enableStandBy(in String packageName, boolean enabled, in String password);

String startMeeting(in String packageName, in List<Participant> participants, boolean firstParticipantJoinedAsHost);

int configMinimumObstacleDistance(in String packageName, int value);
}
31 changes: 31 additions & 0 deletions sdk/src/main/java/com/robotemi/sdk/Robot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,7 @@ class Robot private constructor(private val context: Context) {

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

/**
* Getter and setter of minimumObstacleDistance
*
* Range shall be 0 to 100, with step of 5.
*
*
* If it is not supported in your robot version yet, value will be 0.
*
* Require [Permission.SETTINGS] permission to change the value
*/
@get:JvmName("minimumObstacleDistance")
@get:CheckResult
var minimumObstacleDistance: Int
get() {
return try {
sdkService?.configMinimumObstacleDistance(applicationInfo.packageName, -1) ?: 0
} catch (e: RemoteException) {
Log.d(TAG, "get MinimumObstacleDistance error")
0
}
}
set(value) {
try {
val ret = sdkService?.configMinimumObstacleDistance(applicationInfo.packageName, value)
Log.d(TAG, "set MinimumObstacleDistance ret $ret")
} catch (e: RemoteException) {
Log.d(TAG, "set MinimumObstacleDistance error")
}
}

@Throws(RemoteException::class)
fun showNormalNotification(notification: NormalNotification) {
if (sdkService != null) {
Expand Down

0 comments on commit add8e17

Please sign in to comment.