fix: 禁用舞蹈命令并添加空闲后自动充电逻辑
禁用 MQTT 舞蹈命令以避免意外触发。 添加自动充电功能:当机器人空闲到达非充电桩位置10秒后,自动发起充电。 在开始移动、任务设置或移动取消时,自动取消充电计划。
This commit is contained in:
@@ -96,6 +96,7 @@ class MainActivity : AppCompatActivity(), OnRobotReadyListener, TtsListener, OnG
|
||||
private val idleConfirmDelayMs = 5000L
|
||||
private var blinkJob: Job? = null
|
||||
private var networkErrorJob: Job? = null
|
||||
private var autoRechargeJob: Job? = null
|
||||
private lateinit var telemetryManager: TelemetryManager
|
||||
private lateinit var taskController: TaskController
|
||||
|
||||
@@ -327,10 +328,15 @@ class MainActivity : AppCompatActivity(), OnRobotReadyListener, TtsListener, OnG
|
||||
override fun onGoToLocationStatusChanged(location: String, status: String, descriptionId: Int, description: String) {
|
||||
val normalized = status.lowercase()
|
||||
val isAbort = normalized in setOf("abort", "aborted", "canceled", "cancelled", "stopped", "stop", "failed", "error")
|
||||
val isMoving = normalized in setOf("start", "starting", "going", "moving", "navigating", "calculating", "recalculating")
|
||||
if (isMoving) {
|
||||
cancelAutoRecharge("movement_started:$location/$status")
|
||||
}
|
||||
if (normalized != "complete" && !isAbort) {
|
||||
return
|
||||
}
|
||||
if (isAbort) {
|
||||
cancelAutoRecharge("movement_aborted:$location/$status")
|
||||
taskController.clearLeavingHomeBase()
|
||||
taskController.endNonSpecialTask("goTo aborted: $location, status=$status")
|
||||
return
|
||||
@@ -360,6 +366,7 @@ class MainActivity : AppCompatActivity(), OnRobotReadyListener, TtsListener, OnG
|
||||
val ttsRequest = TtsRequest.create(text, false, language = TtsRequest.Language.ZH_CN)
|
||||
robot.speak(ttsRequest)
|
||||
Log.i("MainActivity", "Arrived at $location, announcement sent.")
|
||||
scheduleAutoRechargeAfterIdleArrival()
|
||||
}
|
||||
|
||||
override fun onDetectionStateChanged(state: Int) {
|
||||
@@ -480,6 +487,9 @@ class MainActivity : AppCompatActivity(), OnRobotReadyListener, TtsListener, OnG
|
||||
}
|
||||
|
||||
fun setCurrentTask(task: String) {
|
||||
if (task.trim().isNotEmpty()) {
|
||||
cancelAutoRecharge("task_set:$task")
|
||||
}
|
||||
taskController.setCurrentTask(task)
|
||||
}
|
||||
|
||||
@@ -723,6 +733,35 @@ class MainActivity : AppCompatActivity(), OnRobotReadyListener, TtsListener, OnG
|
||||
}
|
||||
}
|
||||
|
||||
private fun scheduleAutoRechargeAfterIdleArrival() {
|
||||
if (taskController.currentTask.isNotEmpty()) {
|
||||
return
|
||||
}
|
||||
if (normalizeLocation(lastArrivalLocation) == "homebase") {
|
||||
return
|
||||
}
|
||||
autoRechargeJob?.cancel()
|
||||
autoRechargeJob = mainScope.launch {
|
||||
delay(10_000L)
|
||||
if (taskController.currentTask.isNotEmpty()) {
|
||||
return@launch
|
||||
}
|
||||
if (normalizeLocation(lastArrivalLocation) == "homebase") {
|
||||
return@launch
|
||||
}
|
||||
Log.i("MainActivity", "Auto recharge triggered after idle arrival timeout.")
|
||||
navCon.recharge()
|
||||
}
|
||||
}
|
||||
|
||||
private fun cancelAutoRecharge(reason: String) {
|
||||
if (autoRechargeJob?.isActive == true) {
|
||||
Log.i("MainActivity", "Auto recharge canceled: $reason")
|
||||
}
|
||||
autoRechargeJob?.cancel()
|
||||
autoRechargeJob = null
|
||||
}
|
||||
|
||||
private fun updateConnectionIndicator() {
|
||||
val colorRes = when {
|
||||
!isLiveKitConnected && !isMqttConnected -> android.R.color.holo_red_dark
|
||||
|
||||
@@ -323,7 +323,7 @@ class MqttManager(
|
||||
Log.i(TAG, "Tilt command sent: degrees=$degrees, speed=$speed, result=$ok")
|
||||
}
|
||||
"dance" -> {
|
||||
startDance()
|
||||
// startDance()
|
||||
}
|
||||
"stop" -> {
|
||||
navController.stop()
|
||||
|
||||
Reference in New Issue
Block a user