feat: 添加任务等待超时机制
在机器人开始移动时取消超时计时,在到达接待点或检测到人时启动15分钟超时 超时后自动取消任务并返回充电,避免任务卡死
This commit is contained in:
@@ -334,12 +334,14 @@ class MainActivity : AppCompatActivity(), OnRobotReadyListener, TtsListener, OnG
|
||||
val isMoving = normalized in setOf("start", "starting", "going", "moving", "navigating", "calculating", "recalculating")
|
||||
if (isMoving) {
|
||||
cancelAutoRecharge("movement_started:$location/$status")
|
||||
taskController.cancelTaskWaitTimeout()
|
||||
}
|
||||
if (normalized != "complete" && !isAbort) {
|
||||
return
|
||||
}
|
||||
if (isAbort) {
|
||||
cancelAutoRecharge("movement_aborted:$location/$status")
|
||||
taskController.cancelTaskWaitTimeout()
|
||||
taskController.clearLeavingHomeBase()
|
||||
taskController.endNonSpecialTask("goTo aborted: $location, status=$status")
|
||||
return
|
||||
@@ -362,6 +364,7 @@ class MainActivity : AppCompatActivity(), OnRobotReadyListener, TtsListener, OnG
|
||||
location.equals(taskController.getReceptionLocation(), ignoreCase = true)
|
||||
) {
|
||||
captureReceptionAnchorYawIfNeeded()
|
||||
taskController.startTaskWaitTimeout()
|
||||
}
|
||||
if (taskController.currentTask != "reception") {
|
||||
receptionAnchorYaw = null
|
||||
|
||||
@@ -33,6 +33,24 @@ class TaskController(
|
||||
private var patrolWaitingSeconds: Int = 3
|
||||
private var patrolNonStop: Boolean = false
|
||||
private var patrolMoveJob: Job? = null
|
||||
private var taskWaitTimeoutJob: Job? = null
|
||||
|
||||
fun startTaskWaitTimeout() {
|
||||
taskWaitTimeoutJob?.cancel()
|
||||
taskWaitTimeoutJob = scope.launch {
|
||||
delay(15 * 60 * 1000L) // 15 minutes
|
||||
if (currentTask.isNotEmpty()) {
|
||||
speak("任务超时了,任务被取消,我先回充电桩了")
|
||||
setCurrentTask("")
|
||||
navController.recharge()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun cancelTaskWaitTimeout() {
|
||||
taskWaitTimeoutJob?.cancel()
|
||||
taskWaitTimeoutJob = null
|
||||
}
|
||||
|
||||
fun restoreState(
|
||||
task: String,
|
||||
@@ -65,6 +83,7 @@ class TaskController(
|
||||
if (currentTask == finalTask) {
|
||||
return
|
||||
}
|
||||
cancelTaskWaitTimeout()
|
||||
currentTask = finalTask
|
||||
if (finalTask == "patrol") {
|
||||
setEmoji(AnimatedEmojiView.Expression.ANGRY)
|
||||
@@ -109,6 +128,8 @@ class TaskController(
|
||||
setReceptionButtonVisible(false)
|
||||
if (getLastArrivalLocation() != location) {
|
||||
navController.goTo(location, false)
|
||||
} else {
|
||||
startTaskWaitTimeout()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +182,7 @@ class TaskController(
|
||||
) {
|
||||
when (state) {
|
||||
DETECTED -> {
|
||||
startTaskWaitTimeout()
|
||||
if (!isReceptionPromptVisible) {
|
||||
isReceptionPromptVisible = true
|
||||
setReceptionButtonVisible(true)
|
||||
|
||||
Reference in New Issue
Block a user