diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 0c68457..68ccc9d 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/sdk/components/pipette_module/pipette_ctrl_module_v2.cpp b/sdk/components/pipette_module/pipette_ctrl_module_v2.cpp index 153f6e2..375fc50 100644 --- a/sdk/components/pipette_module/pipette_ctrl_module_v2.cpp +++ b/sdk/components/pipette_module/pipette_ctrl_module_v2.cpp @@ -622,7 +622,6 @@ int32_t PipetteModule::do_pipette_shake_up(int32_t ul, int32_t zmotor_v, int32_t DO_IN_THREAD(m_smtp2.pump_aspirate(m_config.aspirate_distribut_pump_vel, ul)); while (true) { if (!check_when_run()) break; - if (m_thread.getExitFlag()) break; int32_t isbusy = 0; DO_IN_THREAD(m_smtp2.pump_get_state(&isbusy)); @@ -640,7 +639,6 @@ int32_t PipetteModule::do_pipette_shake_up(int32_t ul, int32_t zmotor_v, int32_t if (zmotor_v != 0) submotor->moveBy(-dpos, zmotor_v); while (true) { if (!check_when_run()) return; - if (m_thread.getExitFlag()) return; int32_t isbusy = 0; bool motorIsReachTarget = false; @@ -652,7 +650,7 @@ int32_t PipetteModule::do_pipette_shake_up(int32_t ul, int32_t zmotor_v, int32_t m_thread.sleep(10); } dotimes++; - if (dotimes >= times) { + if (dotimes >= times || m_thread.getExitFlag()) { ZLOGI(TAG, "shake end ...") break; } @@ -663,7 +661,6 @@ int32_t PipetteModule::do_pipette_shake_up(int32_t ul, int32_t zmotor_v, int32_t DO_IN_THREAD(m_smtp2.pump_aspirate(m_config.aspirate_distribut_pump_vel, ul)); while (true) { if (!check_when_run()) return; - if (m_thread.getExitFlag()) return; int32_t isbusy = 0; bool motorIsReachTarget = false; diff --git a/sdk/components/sensors/smtp2_v2/smtp2_v2.cpp b/sdk/components/sensors/smtp2_v2/smtp2_v2.cpp index eb6d5f0..82009c6 100644 --- a/sdk/components/sensors/smtp2_v2/smtp2_v2.cpp +++ b/sdk/components/sensors/smtp2_v2/smtp2_v2.cpp @@ -11,11 +11,8 @@ using namespace smtp2; #define TAG "SMTP2" #define OVERTIME 100 -#define DUMP_HEX 0 +#define DUMP_HEX 1 -#define SEND_CMD(fmt, ...) sendcmd(true, 1, "/1" fmt "R\r", ##__VA_ARGS__); -#define SEND_CMD_AUTO_RETRY(retry_times, fmt, ...) sendcmd(true, retry_times, "/1" fmt "R\r", ##__VA_ARGS__); -#define SEND_CMD_NLOG(fmt, ...) sendcmd(false, 1, "/1" fmt "R\r", ##__VA_ARGS__); // 模式2 void SMTP2V2::initialize(UART_HandleTypeDef* uart, uint8_t id, DMA_HandleTypeDef* hdma_rx, DMA_HandleTypeDef* hdma_tx) { m_uart = uart; @@ -30,7 +27,7 @@ bool SMTP2V2::pump_ping() { } int32_t SMTP2V2::pump_get_state(int32_t* isbusy) { size_t rxlen = 0; - int ret = sendcmd(false /*dump*/, 5 /*retry_times*/, "/1QR\r"); + int ret = readstate(false, "/1QR\r"); if (ret != 0) return ret; uint8_t errorcode = (uint8_t)m_rxbuf[2]; @@ -43,7 +40,7 @@ int32_t SMTP2V2::pump_get_state(int32_t* isbusy) { } int32_t SMTP2V2::pump_get_state_as_int(int32_t state_index, int32_t* val) { size_t rxlen = 0; - int ret = SEND_CMD_AUTO_RETRY(3, "?%d\r", state_index); + int ret = readstate(true, "/1?%d\r", state_index); if (ret != 0) { return ret; } @@ -67,20 +64,20 @@ int32_t SMTP2V2::pump_get_motor_pos_ul(int32_t* ul) { return ret; } -int32_t SMTP2V2::pump_stop() { return sendcmd(true, 1, "/1TR\r"); } -int32_t SMTP2V2::pump_set_vstart(int32_t vel) { return SEND_CMD("N2v%d", vel * 319); } -int32_t SMTP2V2::pump_set_vstop(int32_t vel) { return SEND_CMD("N2c%d", vel * 319); } -int32_t SMTP2V2::pump_set_vmax(int32_t vel) { return SEND_CMD("N2V%d", vel * 319); } -int32_t SMTP2V2::pump_set_acc_and_dec(int32_t acc, int32_t dec) { return SEND_CMD("L%d,%d", acc, dec); } -int32_t SMTP2V2::pump_set_plld_start_delay(int32_t delay_ms) { return SEND_CMD("T%d", delay_ms); } +int32_t SMTP2V2::pump_stop() { return setstate(true, "/1TR\r"); } +int32_t SMTP2V2::pump_set_vstart(int32_t vel) { return setstate(true, "/1N2v%dR\r", vel * 319); } +int32_t SMTP2V2::pump_set_vstop(int32_t vel) { return setstate(true, "/1N2c%dR\r", vel * 319); } +int32_t SMTP2V2::pump_set_vmax(int32_t vel) { return setstate(true, "/1N2V%dR\r", vel * 319); } +int32_t SMTP2V2::pump_set_acc_and_dec(int32_t acc, int32_t dec) { return setstate(true, "/1L%d,%dR\r", acc, dec); } +int32_t SMTP2V2::pump_set_plld_start_delay(int32_t delay_ms) { return setstate(true, "/1T%dR\r", delay_ms); } -int32_t SMTP2V2::pump_put_tip() { return SEND_CMD("E1"); } -int32_t SMTP2V2::pump_init(int32_t v) { return SEND_CMD("N2V%dZ", v * 319); } +int32_t SMTP2V2::pump_put_tip() { return runaction(true, "/1E1R\r"); } +int32_t SMTP2V2::pump_init(int32_t v) { return runaction(true, "/1N2V%dZR\r", v * 319); } int32_t SMTP2V2::pump_reset() { _sendcmd(true, "/1!0R\r"); // 复位指令没有回执,所以这里只能使用方法_sendcmd return 0; } - +#if 0 static int32_t Get1fromfloat(const float& val) { float temp1 = val; int32_t t1 = (uint32_t)(temp1 * 10) % 10; @@ -91,6 +88,7 @@ static int32_t Get1fromfloat(const float& val) { } return (int32_t)temp1; } +#endif int32_t SMTP2V2::pump_move_to_ul(int32_t v, int32_t ul) { /** @@ -102,13 +100,23 @@ int32_t SMTP2V2::pump_move_to_ul(int32_t v, int32_t ul) { */ ZLOGI(TAG, "pump_move_to_ul %d", ul); int stepNum = ul * 1000; //+0.5 是为了浮点数强转成正数时采用四舍五入的方式 - return SEND_CMD("V%dA%d", v * 319, stepNum); + return pump_move_to_nl(v, ul * 1000); +} + +int32_t SMTP2V2::pump_move_to_nl(int32_t v, int32_t nl) { + ZLOGI(TAG, "pump_move_to_nl %d", nl); + return runaction(true, "/1V%dA%dR\r", v * 319, nl); } int32_t SMTP2V2::pump_aspirate(int32_t v, int32_t ul) { ZLOGI(TAG, "pump_aspirate %d", ul); - int stepNum = ul * 1000; - return SEND_CMD("V%dP%d", v * 319, stepNum); + int32_t nownl; + + int32_t ret = pump_get_state_as_int(kstate_pump_pos_nl, &nownl); + if (ret != 0) return ret; + + int targetnl = nownl + ul * 1000; + return pump_move_to_nl(v, targetnl); } int32_t SMTP2V2::pump_distribut(int32_t v, int32_t ul) { ZLOGI(TAG, "pump_distribut %d", ul); @@ -118,19 +126,15 @@ int32_t SMTP2V2::pump_distribut(int32_t v, int32_t ul) { int32_t ret = pump_get_state_as_int(kstate_pump_pos_nl, &nownl); if (ret != 0) return ret; - int stepNum = ul * 1000; - - if (stepNum > nownl) { - stepNum = nownl; - } - - return SEND_CMD("V%dD%d", v * 319, stepNum); + int targetnl = nownl - ul * 1000; + if (targetnl < 0) targetnl = 0; + return pump_move_to_nl(v, targetnl); } int32_t SMTP2V2::pump_distribut_plld(int32_t pumpv, int32_t pressure_threshold) { // M100V100t50,0R ZLOGI(TAG, "pump_distribut_plld %d %d", pumpv, pressure_threshold); - return SEND_CMD("V%dt%d,0", pumpv * 319, pressure_threshold); + return runaction(true, "/1V%dt%d,0R\r", pumpv * 319, pressure_threshold); } int32_t SMTP2V2::pump_distribut_plld_get_state(int32_t* detected) { @@ -146,7 +150,7 @@ int32_t SMTP2V2::pump_distribut_plld_get_state(int32_t* detected) { int32_t SMTP2V2::pump_clld(int32_t c_threshold) { // ZLOGI(TAG, "pump_clld %d", c_threshold); - return SEND_CMD("^%d", c_threshold); + return runaction(true, "/1^%dR\r", c_threshold); } int32_t SMTP2V2::pump_clld_get_state(int32_t* detected) { int32_t isbusy; @@ -161,7 +165,7 @@ int32_t SMTP2V2::pump_clld_get_state(int32_t* detected) { // B, int32_t SMTP2V2::pump_distribut_mlld(int32_t pumpv, int32_t c_threshold, int32_t pressure_threshold) { ZLOGI(TAG, "pump_distribut_mlld %d %d %d", pumpv, c_threshold, pressure_threshold); - return SEND_CMD("V%dB%d,%d", pumpv * 319, c_threshold, pressure_threshold); + return runaction(true, "/1V%dB%d,%dR\r", pumpv * 319, c_threshold, pressure_threshold); } int32_t SMTP2V2::pump_distribut_mlld_get_state(int32_t* detected) { int32_t isbusy; @@ -179,7 +183,7 @@ int32_t SMTP2V2::pump_distribut_mlld_get_state(int32_t* detected) { ***********************************************************************************************************************/ bool SMTP2V2::write_cmd(const char* cmd) { int32_t ret = 0; - ret = sendcmd(true, 1, cmd); + ret = _sendcmd(true, cmd); return ret == 0; } void SMTP2V2::getack(char* rx, int32_t* rxbufsize) { @@ -228,28 +232,96 @@ int32_t SMTP2V2::getAck0AsInt() { int intval = atoi(&m_rxprocessbuf[3]); return intval; } +int32_t SMTP2V2::runaction(bool dump, const char* format, ...) { + static char cmdbuf[256]; + va_list args; + va_start(args, format); + vsnprintf(cmdbuf, sizeof(cmdbuf), format, args); + va_end(args); + return _runaction(dump, cmdbuf); +} -int32_t SMTP2V2::sendcmd(bool dump, int auto_retry_times, const char* format, ...) { - static char buf[256]; +int32_t SMTP2V2::_runaction(bool dump, const char* cmd) { + for (size_t i = 0; i < 3; i++) { + if (i != 0) { + ZLOGE(TAG, "resend cmd ......................................................."); + osDelay(10); + } + + if (!_sendcmd(dump, "/1T\r")) continue; + if (!_sendcmd(dump, "/1CR\r")) continue; + if (!_sendcmd(dump, cmd)) continue; + return getAckEcode(); + } + return getAckEcode(); +} +int32_t SMTP2V2::readstate(bool dump, const char* format, ...) { + static char cmdbuf[256]; + va_list args; + va_start(args, format); + vsnprintf(cmdbuf, sizeof(cmdbuf), format, args); + va_end(args); + + for (size_t i = 0; i < 3; i++) { + if (_sendcmd(dump, cmdbuf)) { + return getAckEcode(); + } + osDelay(20); + } + return getAckEcode(); +} +int32_t SMTP2V2::setstate(bool dump, const char* format, ...) { + static char cmdbuf[256]; va_list args; va_start(args, format); - vsnprintf(buf, sizeof(buf), format, args); + vsnprintf(cmdbuf, sizeof(cmdbuf), format, args); va_end(args); - sendcmd_auto_retry(dump, auto_retry_times, buf); + for (size_t i = 0; i < 3; i++) { + if (_sendcmd(dump, cmdbuf)) { + return getAckEcode(); + } + osDelay(20); + } return getAckEcode(); } -bool SMTP2V2::sendcmd_auto_retry(bool dump, int auto_retry_times, const char* cmd) { +#if 0 +int32_t SMTP2V2::sendcmd(bool dump, int auto_retry_times, const char* format, ...) { + static char cmdbuf[256]; + va_list args; + va_start(args, format); + vsnprintf(cmdbuf, sizeof(cmdbuf), format, args); + va_end(args); + for (size_t i = 0; i < auto_retry_times; i++) { - if (_sendcmd(dump, cmd)) { + if (_sendcmd(dump, cmdbuf)) { return true; } osDelay(50); m_rxNum = 0; } - return false; + return getAckEcode(); } +int32_t SMTP2V2::send_action_cmd(bool dump, int auto_retry_times, const char* format, ...) { + static char cmdbuf[256]; + va_list args; + va_start(args, format); + vsnprintf(cmdbuf, sizeof(cmdbuf), format, args); + va_end(args); + + for (size_t i = 0; i < auto_retry_times; i++) { + if (_sendcmd(dump, cmdbuf)) { + return true; + } + ZLOGI(TAG, "send_action_cmd retry %d", i); + osDelay(10); + sendcmd(true, 2, "/1TR\r"); + osDelay(20); + } + return getAckEcode(); +} +#endif static const char* hex2str(const char* hex, size_t len) { static char buf[256]; @@ -259,6 +331,7 @@ static const char* hex2str(const char* hex, size_t len) { } return buf; } + bool SMTP2V2::_sendcmd(bool dump, const char* cmd) { m_rxNum = 0; diff --git a/sdk/components/sensors/smtp2_v2/smtp2_v2.hpp b/sdk/components/sensors/smtp2_v2/smtp2_v2.hpp index 9807523..cd8edf0 100644 --- a/sdk/components/sensors/smtp2_v2/smtp2_v2.hpp +++ b/sdk/components/sensors/smtp2_v2/smtp2_v2.hpp @@ -181,11 +181,12 @@ class SMTP2V2 { /*********************************************************************************************************************** * ACTION * ***********************************************************************************************************************/ - int32_t pump_init(int32_t v); // 泵机初始化(归零) - int32_t pump_reset(); // 泵机复位 - int32_t pump_stop(); // 停止 - int32_t pump_put_tip(); // 丢弃TIP + int32_t pump_init(int32_t v); // 泵机初始化(归零) + int32_t pump_reset(); // 泵机复位 + int32_t pump_stop(); // 停止 + int32_t pump_put_tip(); // 丢弃TIP int32_t pump_move_to_ul(int32_t v, int32_t ul); // + int32_t pump_move_to_nl(int32_t v, int32_t nl); // int32_t pump_distribut_plld(int32_t pumpv, int32_t pressure_threshold); // plld,分配探测 int32_t pump_distribut_plld_get_state(int32_t* detected); @@ -206,10 +207,18 @@ class SMTP2V2 { void getack(char* rx, int32_t* rxbufsize); private: + int32_t runaction(bool dump, const char* format, ...); + int32_t _runaction(bool dump, const char* cmd); + int32_t readstate(bool dump, const char* format, ...); + int32_t setstate(bool dump, const char* format, ...); +#if 0 int32_t sendcmd(bool dump, int auto_retry_times, const char* format, ...); + int32_t send_action_cmd(bool dump, int auto_retry_times, const char* format, ...); bool sendcmd_auto_retry(bool dump, int auto_retry_times, const char* cmd); - bool _sendcmd(bool dump, const char* cmd); - bool _sendcmd_dma(const char* cmd); +#endif + + bool _sendcmd(bool dump, const char* cmd); + bool _sendcmd_dma(const char* cmd); int32_t getAckEcode(); int32_t getAck0AsInt(); diff --git a/sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp b/sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp index 853e000..5e3aade 100644 --- a/sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp +++ b/sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp @@ -479,9 +479,9 @@ int32_t StepMotorCtrlModule::step_motor_easy_reciprocating_motion(int32_t startp int32_t ecode = check_befor_run(); if (ecode != 0) return ecode; - + int32_t x_startpos = startpos; - int32_t x_endpos = endpos; + int32_t x_endpos = endpos; int32_t x_beginpos; getnowpos(x_beginpos); @@ -499,19 +499,19 @@ int32_t StepMotorCtrlModule::step_motor_easy_reciprocating_motion(int32_t startp ZLOGI(TAG, "reciprocating_motion move pos:%d", x_startpos); moveTo(x_startpos, m_cfg.motor_default_velocity); while (!m_stepM1->isReachTarget()) { + osDelay(50); + if (m_thread.getExitFlag()) break; if (!check_when_run()) break; - - vTaskDelay(5); } ZLOGI(TAG, "reciprocating_motion move pos:%d", x_endpos); moveTo(x_endpos, m_cfg.motor_default_velocity); while (!m_stepM1->isReachTarget()) { + osDelay(50); + if (m_thread.getExitFlag()) break; if (!check_when_run()) break; - - vTaskDelay(5); } } @@ -521,7 +521,7 @@ int32_t StepMotorCtrlModule::step_motor_easy_reciprocating_motion(int32_t startp if (m_thread.getExitFlag()) break; if (!check_when_run()) break; - vTaskDelay(5); + osDelay(50); } after_motor_move(); @@ -542,7 +542,7 @@ int32_t StepMotorCtrlModule::do_step_motor_easy_rotate(int32_t direction) { while (true) { if (m_thread.getExitFlag()) break; if (!check_when_run()) break; - vTaskDelay(5); + osDelay(50); } } @@ -565,7 +565,7 @@ int32_t StepMotorCtrlModule::do_step_motor_easy_move_to(int32_t tox) { if (m_thread.getExitFlag()) break; if (!check_when_run()) break; - vTaskDelay(5); + osDelay(50); } } diff --git a/usrc/project_configs.h b/usrc/project_configs.h index 4023082..d3fa874 100644 --- a/usrc/project_configs.h +++ b/usrc/project_configs.h @@ -1,5 +1,5 @@ #pragma once -#define PC_VERSION 508 +#define PC_VERSION 509 #define PC_MANUFACTURER "http://www.iflytop.com/" #define PC_PROJECT_NAME "a8000_subboard" #define PC_IFLYTOP_ENABLE_OS 1