From a2715e8c3078ed9ba6ab10f1f270e6e7cd1f2a5c Mon Sep 17 00:00:00 2001 From: zhaohe Date: Tue, 24 Oct 2023 18:34:07 +0800 Subject: [PATCH] update --- .../mini_servo_motor_ctrl_module.cpp | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/components/mini_servo_motor/mini_servo_motor_ctrl_module.cpp b/components/mini_servo_motor/mini_servo_motor_ctrl_module.cpp index ec33fe4..a68296e 100644 --- a/components/mini_servo_motor/mini_servo_motor_ctrl_module.cpp +++ b/components/mini_servo_motor/mini_servo_motor_ctrl_module.cpp @@ -113,12 +113,17 @@ int32_t MiniRobotCtrlModule::move_forward(s32 torque) { m_thread.stop(); if (!m_bus->moveTo(m_id, 4095, 0, torque)) return err::ksubdevice_overtime; m_thread.start([this, torque]() { + uint8_t moveflag = 0; while (true) { if (m_thread.getExitFlag()) break; m_thread.sleep(10); + + m_bus->getMoveFlag(m_id, moveflag); + if (moveflag == 0) { + // ²»Í£Ö¹¶æ»ú + break; + } } - stop(0); - ZLOGI(TAG, "%d move_forward stop", m_module_id); }); return 0; @@ -132,12 +137,17 @@ int32_t MiniRobotCtrlModule::move_backward(s32 torque) { m_thread.stop(); if (!m_bus->moveTo(m_id, 0, 0, torque)) return err::ksubdevice_overtime; m_thread.start([this, torque]() { + uint8_t moveflag = 0; while (true) { if (m_thread.getExitFlag()) break; m_thread.sleep(10); + + m_bus->getMoveFlag(m_id, moveflag); + if (moveflag == 0) { + // ²»Í£Ö¹¶æ»ú + break; + } } - stop(0); - ZLOGI(TAG, "%d move_forward stop", m_module_id); }); return 0; @@ -274,8 +284,14 @@ int32_t MiniRobotCtrlModule::getid(int32_t *id) { *id = m_module_id; return 0; } -int32_t MiniRobotCtrlModule::module_stop() { return stop(0); } -int32_t MiniRobotCtrlModule::module_break() { return stop(0); } +int32_t MiniRobotCtrlModule::module_stop() { + m_thread.stop(); + return stop(0); +} +int32_t MiniRobotCtrlModule::module_break() { + m_thread.stop(); + return stop(0); +} int32_t MiniRobotCtrlModule::module_get_last_exec_status(int32_t *status) { *status = m_last_exec_status; return 0;