diff --git a/uappbase/appcfg/appcfg.hpp b/uappbase/appcfg/appcfg.hpp index d3a93a8..2bed34c 100644 --- a/uappbase/appcfg/appcfg.hpp +++ b/uappbase/appcfg/appcfg.hpp @@ -26,10 +26,9 @@ ***********************************************************************************************************************/ #define MOTOR_SHAFT false #define STEPMOTOR_IHOLD 10 -#define STEPMOTOR_IRUN 20 #define STEPMOTOR_IHOLDDELAY 100 -#define MOTOR_VSTART 200 // 启动速度 -#define MOTOR_A1 100 // 阶段1_加速度 -#define MOTOR_AMAX 300 // 阶段2_加速度 -#define MOTOR_V1 500 // 阶段2_开始速度 +#define MOTOR_VSTART 50 // 启动速度 +#define MOTOR_A1 15 // 阶段1_加速度 +#define MOTOR_AMAX 50 // 阶段2_加速度 +#define MOTOR_V1 300 // 阶段2_开始速度 #define MOTOR_TZEROWAIT 100 // 速度零点点切换时间 diff --git a/uappbase/bean/config_index_enum.hpp b/uappbase/bean/config_index_enum.hpp index 0fdb5a1..94a0988 100644 --- a/uappbase/bean/config_index_enum.hpp +++ b/uappbase/bean/config_index_enum.hpp @@ -63,17 +63,17 @@ typedef enum { * 电机默认配置 * ***********************************************************************************************************************/ - kcfg_1ulTrunsM0, // 电机0 1ul 转数 - kcfg_1ulTrunsM1, // 电机0 1ul 转数 - kcfg_1ulTrunsM2, // 电机0 1ul 转数 - kcfg_1ulTrunsM3, // 电机0 1ul 转数 + kcfg_mLPR0, // 电机0 + kcfg_mLPR1, // 电机0 + kcfg_mLPR2, // 电机0 + kcfg_mLPR3, // 电机0 /*********************************************************************************************************************** * 其他配置 * ***********************************************************************************************************************/ kcfg_lockAcidName, // 锁定酸液名称 kcfg_echDitrUpLi, // 每次分配上限设定值 each distri up-limit - kcfg_pumpDefVel, // 泵机默认速度RPM + kcfg_pumpDefVel, // 泵机默认速度ml/min kcfg_distrInterval, // 每次分配间隔时间 /*********************************************************************************************************************** @@ -81,6 +81,11 @@ typedef enum { ***********************************************************************************************************************/ kcfg_pipeLengthML, // 酸液管路长度 + kcfg_m0irun, // 电机0 irun + kcfg_m1irun, // 电机1 irun + kcfg_m2irun, // 电机2 irun + kcfg_m3irun, // 电机3 irun + kcfg_max, } config_index_t; diff --git a/uappbase/service/config_index.cpp b/uappbase/service/config_index.cpp index 6d75c1f..e2e6668 100644 --- a/uappbase/service/config_index.cpp +++ b/uappbase/service/config_index.cpp @@ -1,8 +1,7 @@ #include "config_index.hpp" namespace iflytop { -#define CFG_ITERM(index, type, initval) \ - { index, #index, type, initval } +#define CFG_ITERM(index, type, initval) {index, #index, type, initval} static cfg_iterm_info_t cfg_iterm_infos[] = { @@ -71,25 +70,29 @@ static cfg_iterm_info_t cfg_iterm_infos[] = { /*********************************************************************************************************************** * 电机默认配置 * ***********************************************************************************************************************/ - CFG_ITERM(kcfg_1ulTrunsM0, kcfgt_int32, "1000"), // - CFG_ITERM(kcfg_1ulTrunsM1, kcfgt_int32, "1000"), // - CFG_ITERM(kcfg_1ulTrunsM2, kcfgt_int32, "1000"), // - CFG_ITERM(kcfg_1ulTrunsM3, kcfgt_int32, "1000"), // + CFG_ITERM(kcfg_mLPR0, kcfgt_int32, "10"), // + CFG_ITERM(kcfg_mLPR1, kcfgt_int32, "10"), // + CFG_ITERM(kcfg_mLPR2, kcfgt_int32, "10"), // + CFG_ITERM(kcfg_mLPR3, kcfgt_int32, "10"), // /*********************************************************************************************************************** * 其他配置 * ***********************************************************************************************************************/ CFG_ITERM(kcfg_lockAcidName, kcfgt_bool, "false"), // CFG_ITERM(kcfg_echDitrUpLi, kcfgt_int32, "40"), // 每次分配上限设定值 each distri up-limit - CFG_ITERM(kcfg_distrInterval, kcfgt_int32, "10"), // 每次分配间隔时间 - CFG_ITERM(kcfg_pumpDefVel, kcfgt_int32, "800"), // + CFG_ITERM(kcfg_distrInterval, kcfgt_float, "1.5"), // 每次分配间隔时间 + CFG_ITERM(kcfg_pumpDefVel, kcfgt_int32, "800"), // + + CFG_ITERM(kcfg_m0irun, kcfgt_int32, "20"), // + CFG_ITERM(kcfg_m1irun, kcfgt_int32, "20"), // + CFG_ITERM(kcfg_m2irun, kcfgt_int32, "20"), // + CFG_ITERM(kcfg_m3irun, kcfgt_int32, "20"), // /*********************************************************************************************************************** * 回流参数配置 * ***********************************************************************************************************************/ - CFG_ITERM(kcfg_pipeLengthML, kcfgt_float, "1000"), // - + CFG_ITERM(kcfg_pipeLengthML, kcfgt_float, "100"), // }; const char *cfgName(int32_t index) { diff --git a/uappbase/service/config_index.hpp b/uappbase/service/config_index.hpp index 9a51330..116a223 100644 --- a/uappbase/service/config_index.hpp +++ b/uappbase/service/config_index.hpp @@ -19,7 +19,7 @@ typedef struct { const char *initval; } cfg_iterm_info_t; -#define CFG_MAX_INDEX 50 +#define CFG_MAX_INDEX 54 const char *cfgName(int32_t index); cfg_iterm_type_t cfgType(int32_t index); diff --git a/uappbase/service/config_service.cpp b/uappbase/service/config_service.cpp index 1c1c19f..4ebc59b 100644 --- a/uappbase/service/config_service.cpp +++ b/uappbase/service/config_service.cpp @@ -3,7 +3,7 @@ #include "uappbase\service\app_event_bus.hpp" // -#define CFG_HEADER 0x12345678 +#define CFG_HEADER 0x12345679 /** * @brief CFG内存使用 * diff --git a/uappbase/service/config_service_utils.cpp b/uappbase/service/config_service_utils.cpp index 54f15f9..135d140 100644 --- a/uappbase/service/config_service_utils.cpp +++ b/uappbase/service/config_service_utils.cpp @@ -1,34 +1,69 @@ #include "config_service_utils.hpp" namespace iflytop { -int32_t getMotorULToTruns(int32_t motorid) { +int32_t getMotorMLPR(int32_t motorid) { switch (motorid) { case 0: - return getCfgInt(kcfg_1ulTrunsM0); + return getCfgInt(kcfg_mLPR0); case 1: - return getCfgInt(kcfg_1ulTrunsM1); + return getCfgInt(kcfg_mLPR1); case 2: - return getCfgInt(kcfg_1ulTrunsM2); + return getCfgInt(kcfg_mLPR2); case 3: - return getCfgInt(kcfg_1ulTrunsM3); + return getCfgInt(kcfg_mLPR3); default: ZASSERT(0); return 0; } } -void setMotorULToTruns(int motorid, int32_t val) { +void setMotorMLPR(int motorid, int32_t val) { // switch (motorid) { case 0: - CS->setcfgAndFlush(kcfg_1ulTrunsM0, val); + CS->setcfgAndFlush(kcfg_mLPR0, val); break; case 1: - CS->setcfgAndFlush(kcfg_1ulTrunsM1, val); + CS->setcfgAndFlush(kcfg_mLPR1, val); break; case 2: - CS->setcfgAndFlush(kcfg_1ulTrunsM2, val); + CS->setcfgAndFlush(kcfg_mLPR2, val); break; case 3: - CS->setcfgAndFlush(kcfg_1ulTrunsM3, val); + CS->setcfgAndFlush(kcfg_mLPR3, val); + break; + default: + ZASSERT(0); + } +} + +int32_t getMxIRun(int motorid) { + switch (motorid) { + case 0: + return getCfgInt(kcfg_m0irun); + case 1: + return getCfgInt(kcfg_m1irun); + case 2: + return getCfgInt(kcfg_m2irun); + case 3: + return getCfgInt(kcfg_m3irun); + default: + ZASSERT(0); + return 0; + } +} + +int32_t setMxIRun(int motorid, int32_t val) { + switch (motorid) { + case 0: + CS->setcfgAndFlush(kcfg_m0irun, val); + break; + case 1: + CS->setcfgAndFlush(kcfg_m1irun, val); + break; + case 2: + CS->setcfgAndFlush(kcfg_m2irun, val); + break; + case 3: + CS->setcfgAndFlush(kcfg_m3irun, val); break; default: ZASSERT(0); diff --git a/uappbase/service/config_service_utils.hpp b/uappbase/service/config_service_utils.hpp index 8dd4538..58b49dd 100644 --- a/uappbase/service/config_service_utils.hpp +++ b/uappbase/service/config_service_utils.hpp @@ -1,8 +1,11 @@ #pragma once #include "config_service.hpp" namespace iflytop { -int32_t getMotorULToTruns(int32_t motorid); -void setMotorULToTruns(int32_t motorid, int32_t val); +int32_t getMotorMLPR(int32_t motorid); +void setMotorMLPR(int32_t motorid, int32_t val); + +int32_t setMxIRun(int motorid, int32_t val); +int32_t getMxIRun(int motorid); const char* getPasswd(const char* usrname, CfgItermCache* cache); const void setPasswd(const char* usrname, const char* passwd); diff --git a/usrc/service/front_end_controler.hpp b/usrc/service/front_end_controler.hpp index c7d1fe2..c96fae5 100644 --- a/usrc/service/front_end_controler.hpp +++ b/usrc/service/front_end_controler.hpp @@ -106,5 +106,13 @@ static inline const char* zitoa(int val) { sprintf(buf, "%d", val); return buf; } +static inline const char* zfmt(const char* fmt, ...) { + static char buf[128]; + va_list args; + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + return buf; +} } // namespace iflytop diff --git a/usrc/service/page/Page_main.cpp b/usrc/service/page/Page_main.cpp index d258981..aaffca7 100644 --- a/usrc/service/page/Page_main.cpp +++ b/usrc/service/page/Page_main.cpp @@ -126,7 +126,7 @@ void Page_main::OnInputFieldContentChange(uint8_t bid, const char* text) { // 设置加酸间隔 if (bid == ob_main_RunModeVal) { - int32_t distrIntervalSecond = atoi(text); + float distrIntervalSecond = atof(text); if (distrIntervalSecond <= 0) { UIS->alert("酸液间隔时间不能小于0"); return; @@ -136,8 +136,8 @@ void Page_main::OnInputFieldContentChange(uint8_t bid, const char* text) { UIS->alert("酸液间隔时间不能大于30"); return; } - UIS->setVal(PAGE, bid, zitoa(distrIntervalSecond)); - CS->setcfgAndFlush(kcfg_distrInterval, distrIntervalSecond); + UIS->setVal(PAGE, bid, zfmt("%.1f", distrIntervalSecond)); + CS->setcfgAndFlush(kcfg_distrInterval, zfmt("%.1f", distrIntervalSecond)); } } diff --git a/usrc/service/page/submenu/Page_muInterval.cpp b/usrc/service/page/submenu/Page_muInterval.cpp index e7fde17..ca0a48f 100644 --- a/usrc/service/page/submenu/Page_muInterval.cpp +++ b/usrc/service/page/submenu/Page_muInterval.cpp @@ -19,7 +19,7 @@ void Page_muInterval::OnPageLoad() { void Page_muInterval::OnInputFieldContentChange(uint8_t bid, const char* text) { if (bid == ob_muInterval_stAcidInte) { - int32_t distrIntervalSecond = atoi(text); + float distrIntervalSecond = atof(text); if (distrIntervalSecond <= 0) { UIS->alert("酸液间隔时间不能小于0"); UIS->setVal(PAGE, ob_muInterval_stAcidInte, CS->getStr(kcfg_distrInterval, &cfgcache)); @@ -31,8 +31,8 @@ void Page_muInterval::OnInputFieldContentChange(uint8_t bid, const char* text) { UIS->setVal(PAGE, ob_muInterval_stAcidInte, CS->getStr(kcfg_distrInterval, &cfgcache)); return; } - UIS->setVal(PAGE, bid, text); - CS->setcfgAndFlush(kcfg_distrInterval, distrIntervalSecond); + UIS->setVal(PAGE, bid, zfmt("%.1f", distrIntervalSecond)); + CS->setcfgAndFlush(kcfg_distrInterval, zfmt("%.1f", distrIntervalSecond)); } }; void Page_muInterval::OnButton(uint8_t bid, uint8_t val) { diff --git a/usrc/service/page/submenu/Page_muPumpTest.hpp b/usrc/service/page/submenu/Page_muPumpTest.hpp index 377a616..dcbcbfa 100644 --- a/usrc/service/page/submenu/Page_muPumpTest.hpp +++ b/usrc/service/page/submenu/Page_muPumpTest.hpp @@ -20,7 +20,6 @@ class Page_muPumpTest : public IPageProcesser { virtual void OnPageLoad() override; virtual void OnInputFieldContentChange(uint8_t bid, const char* text) override; virtual void OnButton(uint8_t bid, uint8_t val) override; - private: }; diff --git a/usrc/service/pump_ctrl_service.cpp b/usrc/service/pump_ctrl_service.cpp index 233ad46..18bd35e 100644 --- a/usrc/service/pump_ctrl_service.cpp +++ b/usrc/service/pump_ctrl_service.cpp @@ -9,7 +9,9 @@ static TMC51X0* m_motors[4]; #define PUMP_NUM 4 static CfgItermCache cfgcache; -void PumpCtrlService::initialize() { +#define APPEND_ML 1 + +void PumpCtrlService::initialize() { m_motors[0] = AppHardware::ins()->getPump(0); m_motors[1] = AppHardware::ins()->getPump(1); m_motors[2] = AppHardware::ins()->getPump(2); @@ -17,13 +19,24 @@ void PumpCtrlService::initialize() { m_thread.init("PumpCtrlService", 1024); updateMotorSetting(); + + AppEventBus::ins()->regOnEvent([this](AppEvent_t* event) { + if (event->type == kAppEvent_ConfigChangeEvent) { + // 电机参数发生改变 + int cfi = event->d.configIndex; + if ((cfi >= kcfg_mLPR0 && cfi <= kcfg_mLPR3) || // + (cfi >= kcfg_m0irun && cfi <= kcfg_m3irun)) { + m_pumpCfgUpdateFlag = true; + } + } + }); } void PumpCtrlService::updateMotorSetting() { for (size_t i = 0; i < PUMP_NUM; i++) { m_motors[i]->enable(false); - - m_motors[i]->setIHOLD_IRUN(STEPMOTOR_IHOLD, STEPMOTOR_IRUN, STEPMOTOR_IHOLDDELAY); + m_motors[i]->setIHOLD_IRUN(STEPMOTOR_IHOLD, getMxIRun(i), STEPMOTOR_IHOLDDELAY); + m_motors[i]->setScale(getMotorMLPR(i) * 1000); m_motors[i]->setScaleDenominator(1); m_motors[i]->setMotorShaft(MOTOR_SHAFT); m_motors[i]->setVstart(MOTOR_VSTART); @@ -34,9 +47,22 @@ void PumpCtrlService::updateMotorSetting() { m_motors[i]->setDmax(MOTOR_AMAX); m_motors[i]->setV1(MOTOR_V1); m_motors[i]->setTzerowait(MOTOR_TZEROWAIT); - m_motors[i]->setScale(getMotorULToTruns(i)); m_motors[i]->enable(true); + + ZLOGI(TAG, "M[%d] setIHOLD_IRUN %d %d %d", i, STEPMOTOR_IHOLD, getMxIRun(i), STEPMOTOR_IHOLDDELAY); + ZLOGI(TAG, "M[%d] setScale %d", i, getMotorMLPR(i)); + ZLOGI(TAG, "M[%d] setScaleDenominator %d", i, 1); + ZLOGI(TAG, "M[%d] setMotorShaft %d", i, MOTOR_SHAFT); + ZLOGI(TAG, "M[%d] setVstart %d", i, MOTOR_VSTART); + ZLOGI(TAG, "M[%d] setVstop %d", i, MOTOR_VSTART); + ZLOGI(TAG, "M[%d] setA1 %d", i, MOTOR_A1); + ZLOGI(TAG, "M[%d] setD1 %d", i, MOTOR_A1); + ZLOGI(TAG, "M[%d] setAmax %d", i, MOTOR_AMAX); + ZLOGI(TAG, "M[%d] setDmax %d", i, MOTOR_AMAX); + ZLOGI(TAG, "M[%d] setV1 %d", i, MOTOR_V1); + ZLOGI(TAG, "M[%d] setTzerowait %d", i, MOTOR_TZEROWAIT); } + m_pumpCfgUpdateFlag = false; } void PumpCtrlService::stop() { @@ -51,6 +77,8 @@ void PumpCtrlService::stop() { ***********************************************************************************************************************/ void PumpCtrlService::reflux() { ZLOGI(TAG, "reflux"); + if (m_pumpCfgUpdateFlag) updateMotorSetting(); + m_thread.start([this]() { int32_t pipeLenML = getCfgInt(kcfg_pipeLengthML); int32_t vel = getCfgInt(config_index_t(kcfg_pumpDefVel)); @@ -76,6 +104,8 @@ void PumpCtrlService::reflux() { } void PumpCtrlService::acidPrefilling() { ZLOGI(TAG, "acidPrefilling"); + if (m_pumpCfgUpdateFlag) updateMotorSetting(); + m_thread.start([this]() { int32_t pipeLenML = getCfgInt(kcfg_pipeLengthML); int32_t vel = getCfgInt(config_index_t(kcfg_pumpDefVel)); @@ -95,6 +125,17 @@ void PumpCtrlService::acidPrefilling() { osDelay(10); } + // 短回流 + for (size_t i = 0; i < PUMP_NUM; i++) { + int32_t vel = getCfgInt(kcfg_pumpDefVel); + TMC51X0* cur_motor = m_motors[i]; + cur_motor->moveBy(-(int32_t)(APPEND_ML) * 1000, vel); + } + + while (!isAllReachTarget()) { + osDelay(10); + } + stopAll(); ZLOGI(TAG, "acidPrefilling end"); }); @@ -103,8 +144,11 @@ void PumpCtrlService::acidPrefilling() { void PumpCtrlService::autoMoveMutiTimes() { // doMoveOnce(); ZLOGI(TAG, "autoMoveMutiTimes"); + if (m_pumpCfgUpdateFlag) updateMotorSetting(); + m_thread.start([this]() { - int32_t delayTime = getCfgInt(kcfg_distrInterval); + float delayTime = getCfgFloat(kcfg_distrInterval); + ZLOGI(TAG, "delayTime %d", delayTime); while (!m_thread.getExitFlag()) { doMoveOnce(); @@ -113,6 +157,7 @@ void PumpCtrlService::autoMoveMutiTimes() { if (m_thread.getExitFlag()) { break; } + delayTime = getCfgFloat(kcfg_distrInterval); } } @@ -121,6 +166,8 @@ void PumpCtrlService::autoMoveMutiTimes() { } void PumpCtrlService::moveOnce() { ZLOGI(TAG, "moveOnce"); + if (m_pumpCfgUpdateFlag) updateMotorSetting(); + m_thread.start([this]() { doMoveOnce(); }); } @@ -133,23 +180,43 @@ bool PumpCtrlService::isWorking() { return m_thread.isworking(); } void PumpCtrlService::doMoveOnce() { // ZLOGI(TAG, "do moveOnce ..."); + for (size_t i = 0; i < PUMP_NUM; i++) { bool pumpselect = GSM->getPumpSelectState(i); float distribut_ml = getCfgFloat(config_index_t(kcfg_acideval0 + i)); - int32_t vel = getCfgInt(config_index_t(kcfg_pumpDefVel)); + int32_t vel = getCfgInt(kcfg_pumpDefVel); TMC51X0* cur_motor = m_motors[i]; cur_motor->stop(); cur_motor->setXACTUAL(0); if (pumpselect) { ZLOGI(TAG, "pump %d move %f ml", i, distribut_ml); - cur_motor->moveBy((int32_t)distribut_ml * 1000, vel); + cur_motor->moveBy((int32_t)(distribut_ml + APPEND_ML) * 1000, vel); + } + } + + while (!isAllReachTarget()) { + osDelay(10); + } + + // 回流 + for (size_t i = 0; i < PUMP_NUM; i++) { + bool pumpselect = GSM->getPumpSelectState(i); + int32_t vel = getCfgInt(kcfg_pumpDefVel); + + TMC51X0* cur_motor = m_motors[i]; + cur_motor->stop(); + cur_motor->setXACTUAL(0); + if (pumpselect) { + cur_motor->moveBy(-(int32_t)(APPEND_ML) * 1000, vel); } } while (!isAllReachTarget()) { osDelay(10); } + + ZLOGI(TAG, "do moveOnce finish"); stopAll(); } diff --git a/usrc/service/pump_ctrl_service.hpp b/usrc/service/pump_ctrl_service.hpp index 49196ed..c0781f4 100644 --- a/usrc/service/pump_ctrl_service.hpp +++ b/usrc/service/pump_ctrl_service.hpp @@ -10,6 +10,7 @@ using namespace std; */ class PumpCtrlService { ZThread m_thread; + bool m_pumpCfgUpdateFlag = false; public: PumpCtrlService() {}; diff --git a/usrc/service/remote_controler_event_processer.cpp b/usrc/service/remote_controler_event_processer.cpp index 137ec4b..a0fc128 100644 --- a/usrc/service/remote_controler_event_processer.cpp +++ b/usrc/service/remote_controler_event_processer.cpp @@ -1,6 +1,7 @@ #include "remote_controler_event_processer.hpp" #include "pump_ctrl_service.hpp" +#include "service/front_end_controler.hpp" #include "service/remote_controler.hpp" using namespace iflytop; @@ -81,6 +82,16 @@ void RemoteControlerEventProcesser::processKeyEventFromRemoter(hand_acid_remoter /** * @brief 如果当前设备处于工作中,则无论什么按键都是停止工作 */ + + if (UIS->getNowPage() == pg_muPumpTest) { + ZLOGW(TAG, "now page is in pump test, remote key event process by pumpTestPage"); + return; + } + + if (UIS->getNowPage() != pg_main) { + UIS->chpage(pg_main); + } + if (PUMPCS->isWorking()) { PUMPCS->stop(); RCTRL->setRemoterState(GSM->getRunMode(), PUMPCS->isWorking()); diff --git a/usrc/service/remote_controler_state_sync_service.cpp b/usrc/service/remote_controler_state_sync_service.cpp index adb92dc..cacad2f 100644 --- a/usrc/service/remote_controler_state_sync_service.cpp +++ b/usrc/service/remote_controler_state_sync_service.cpp @@ -54,7 +54,7 @@ void RemoteControlerStateSyncService::startSync() { } } - osDelay(500); + osDelay(5); } }); }