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")
|
val isMoving = normalized in setOf("start", "starting", "going", "moving", "navigating", "calculating", "recalculating")
|
||||||
if (isMoving) {
|
if (isMoving) {
|
||||||
cancelAutoRecharge("movement_started:$location/$status")
|
cancelAutoRecharge("movement_started:$location/$status")
|
||||||
|
taskController.cancelTaskWaitTimeout()
|
||||||
}
|
}
|
||||||
if (normalized != "complete" && !isAbort) {
|
if (normalized != "complete" && !isAbort) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (isAbort) {
|
if (isAbort) {
|
||||||
cancelAutoRecharge("movement_aborted:$location/$status")
|
cancelAutoRecharge("movement_aborted:$location/$status")
|
||||||
|
taskController.cancelTaskWaitTimeout()
|
||||||
taskController.clearLeavingHomeBase()
|
taskController.clearLeavingHomeBase()
|
||||||
taskController.endNonSpecialTask("goTo aborted: $location, status=$status")
|
taskController.endNonSpecialTask("goTo aborted: $location, status=$status")
|
||||||
return
|
return
|
||||||
@@ -362,6 +364,7 @@ class MainActivity : AppCompatActivity(), OnRobotReadyListener, TtsListener, OnG
|
|||||||
location.equals(taskController.getReceptionLocation(), ignoreCase = true)
|
location.equals(taskController.getReceptionLocation(), ignoreCase = true)
|
||||||
) {
|
) {
|
||||||
captureReceptionAnchorYawIfNeeded()
|
captureReceptionAnchorYawIfNeeded()
|
||||||
|
taskController.startTaskWaitTimeout()
|
||||||
}
|
}
|
||||||
if (taskController.currentTask != "reception") {
|
if (taskController.currentTask != "reception") {
|
||||||
receptionAnchorYaw = null
|
receptionAnchorYaw = null
|
||||||
|
|||||||
@@ -33,6 +33,24 @@ class TaskController(
|
|||||||
private var patrolWaitingSeconds: Int = 3
|
private var patrolWaitingSeconds: Int = 3
|
||||||
private var patrolNonStop: Boolean = false
|
private var patrolNonStop: Boolean = false
|
||||||
private var patrolMoveJob: Job? = null
|
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(
|
fun restoreState(
|
||||||
task: String,
|
task: String,
|
||||||
@@ -65,6 +83,7 @@ class TaskController(
|
|||||||
if (currentTask == finalTask) {
|
if (currentTask == finalTask) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
cancelTaskWaitTimeout()
|
||||||
currentTask = finalTask
|
currentTask = finalTask
|
||||||
if (finalTask == "patrol") {
|
if (finalTask == "patrol") {
|
||||||
setEmoji(AnimatedEmojiView.Expression.ANGRY)
|
setEmoji(AnimatedEmojiView.Expression.ANGRY)
|
||||||
@@ -109,6 +128,8 @@ class TaskController(
|
|||||||
setReceptionButtonVisible(false)
|
setReceptionButtonVisible(false)
|
||||||
if (getLastArrivalLocation() != location) {
|
if (getLastArrivalLocation() != location) {
|
||||||
navController.goTo(location, false)
|
navController.goTo(location, false)
|
||||||
|
} else {
|
||||||
|
startTaskWaitTimeout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,6 +182,7 @@ class TaskController(
|
|||||||
) {
|
) {
|
||||||
when (state) {
|
when (state) {
|
||||||
DETECTED -> {
|
DETECTED -> {
|
||||||
|
startTaskWaitTimeout()
|
||||||
if (!isReceptionPromptVisible) {
|
if (!isReceptionPromptVisible) {
|
||||||
isReceptionPromptVisible = true
|
isReceptionPromptVisible = true
|
||||||
setReceptionButtonVisible(true)
|
setReceptionButtonVisible(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user