diff --git a/.cproject b/.cproject
index c89d1ed..2fb2360 100644
--- a/.cproject
+++ b/.cproject
@@ -29,7 +29,7 @@
-
+
@@ -101,6 +101,7 @@
+
diff --git a/a8000_protocol b/a8000_protocol
index 48fe715..befb0cf 160000
--- a/a8000_protocol
+++ b/a8000_protocol
@@ -1 +1 @@
-Subproject commit 48fe71561ae851deea3de371ef04276fa8d777f9
+Subproject commit befb0cfa58db25acb9e3a496e5e4414ac8797f88
diff --git a/sdk/components/pipette_module/pipette_ctrl_module_v2.cpp b/sdk/components/pipette_module/pipette_ctrl_module_v2.cpp
index a71fa29..62c17ec 100644
--- a/sdk/components/pipette_module/pipette_ctrl_module_v2.cpp
+++ b/sdk/components/pipette_module/pipette_ctrl_module_v2.cpp
@@ -31,6 +31,8 @@
} \
}
+#define THREAD_START_WORK(...) thread_start_work(__FUNCTION__, __VA_ARGS__)
+
#define PIPETTE_PREPARE_POS 800
#define LLD_PREPARE_DISTRIBUT_POS 100
#define LLF_DPOS 1000
@@ -57,33 +59,34 @@ void PipetteModuleV2::initialize(int32_t id, config_t *config, hardward_config_t
m_zm = hardwaredcfg->zmotor;
m_zm0p = hardwaredcfg->zmotor_0point;
+
+ m_zm->getGState(); // 读取状态,清空下复位标识
+ module_active_cfg();
}
void PipetteModuleV2::create_default_cfg(config_t *defaultcfg) {
- static config_t cfg;
-
- cfg.limit_ul = 200;
- cfg.pump_acc = 14;
- cfg.pump_dec = 14;
- cfg.pump_vstart = 0;
- cfg.pump_vstop = 900;
- cfg.aspirate_pump_vel = 500; //
- cfg.pump_vmax = 1000;
- cfg.aspirate_zmotor_max_move_by = 400; // 50mm,tip头的长度
- cfg.lld_pump_vel = 100; // lld推荐使用速度为50->200,这里
- cfg.lld_motor_vel_rpm = 200;
- cfg.lld_detect_period_ms = 10; // 100ms
- cfg.lld_prepare_pos = PIPETTE_PREPARE_POS;
- cfg.lld_prepare_pre_distribut_ul = LLD_PREPARE_DISTRIBUT_POS;
-
- cfg.zm_one_circle_pulse = 10000;
- cfg.zm_one_circle_pulse_denominator = 1;
- cfg.zm_ihold = 1;
- cfg.zm_irun = 3;
- cfg.zm_iholddelay = 100;
- cfg.zm_default_velocity = 500;
- cfg.zm_run_to_zero_speed = 100;
- cfg.zm_look_zero_edge_speed = 100;
+ defaultcfg->limit_ul = 200;
+ defaultcfg->pump_acc = 14;
+ defaultcfg->pump_dec = 14;
+ defaultcfg->pump_vstart = 0;
+ defaultcfg->pump_vstop = 900;
+ defaultcfg->aspirate_pump_vel = 500; //
+ defaultcfg->pump_vmax = 1000;
+ defaultcfg->aspirate_zmotor_max_move_by = 400; // 50mm,tip头的长度
+ defaultcfg->lld_pump_vel = 100; // lld推荐使用速度为50->200,这里
+ defaultcfg->lld_motor_vel_rpm = 200;
+ defaultcfg->lld_detect_period_ms = 10; // 100ms
+ defaultcfg->lld_prepare_pos = PIPETTE_PREPARE_POS;
+ defaultcfg->lld_prepare_pre_distribut_ul = LLD_PREPARE_DISTRIBUT_POS;
+
+ defaultcfg->zm_one_circle_pulse = 10000;
+ defaultcfg->zm_one_circle_pulse_denominator = 1;
+ defaultcfg->zm_ihold = 1;
+ defaultcfg->zm_irun = 3;
+ defaultcfg->zm_iholddelay = 100;
+ defaultcfg->zm_default_velocity = 500;
+ defaultcfg->zm_run_to_zero_speed = 100;
+ defaultcfg->zm_look_zero_edge_speed = 100;
}
int32_t PipetteModuleV2::getid(int32_t *id) {
*id = m_id;
@@ -94,9 +97,9 @@ int32_t PipetteModuleV2::module_stop() {
return 0;
}
int32_t PipetteModuleV2::module_active_cfg() {
- DO(m_smtp2.pump_set_acc_and_dec(m_cfg.pump_acc, m_cfg.pump_dec));
- DO(m_smtp2.pump_set_vstart(m_cfg.pump_vstart));
- DO(m_smtp2.pump_set_vstop(m_cfg.pump_vstop));
+ m_smtp2.pump_set_acc_and_dec(m_cfg.pump_acc, m_cfg.pump_dec);
+ m_smtp2.pump_set_vstart(m_cfg.pump_vstart);
+ m_smtp2.pump_set_vstop(m_cfg.pump_vstop);
m_zm->enable(false);
m_zm->setIHOLD_IRUN(m_cfg.zm_ihold, m_cfg.zm_irun, m_cfg.zm_iholddelay);
@@ -133,7 +136,7 @@ int32_t PipetteModuleV2::module_active_cfg() {
} break;
#define XXX_STATE_REG(statekey, action) PROCESS_REG(statekey, action, ACTION_NONE)
-int32_t PipetteModuleV2::_module_xxx_reg(int32_t param_id, bool read, int32_t &val) {
+int32_t PipetteModuleV2::module_xxx_reg_impl(int32_t param_id, bool read, int32_t &val) {
switch (param_id) {
/***********************************************************************************************************************
* STATE *
@@ -196,7 +199,7 @@ int32_t PipetteModuleV2::_module_xxx_reg(int32_t param_id, bool read, int32_t &v
}
int32_t PipetteModuleV2::module_xxx_reg(int32_t param_id, bool read, int32_t &val) {
- int32_t retval = _module_xxx_reg(param_id, read, val);
+ int32_t retval = module_xxx_reg_impl(param_id, read, val);
if (retval == 0 && m_config_update) {
module_active_cfg();
}
@@ -209,7 +212,7 @@ int32_t PipetteModuleV2::module_xxx_reg(int32_t param_id, bool read, int32_t &va
***********************************************************************************************************************/
int32_t PipetteModuleV2::pipette_zmotor_enable(int32_t enable) {
- ZLOGI(TAG, "m%d pipette_zmotor_enable %ld", m_id, enable);
+ // ZLOGI(TAG, "m%d pipette_zmotor_enable %ld", m_id, enable);
m_thread.stop();
m_zm->enable(enable);
m_state.enable = enable;
@@ -225,12 +228,10 @@ int32_t PipetteModuleV2::pipette_zmotor_enable(int32_t enable) {
* @return int32_t
*/
int32_t PipetteModuleV2::pipette_zmotor_move_zero() { //
- thread_start_work([this]() {
- do_zm_move_0p(); // 移动到零点
- if (creg.module_errorcode != 0) { // 计算并更新零点坐标
- zm_set_now_pos(0 + m_cfg.zm_dzero - m_cfg.zm_io_trigger_append_distance);
- m_state.has_move_to_zero = 1;
- }
+ THREAD_START_WORK([this]() {
+ do_zm_move_0p(); // 移动到零点
+ zm_set_now_pos(0 + m_cfg.zm_dzero - m_cfg.zm_io_trigger_append_distance);
+ m_state.has_move_to_zero = 1;
});
return 0;
}
@@ -241,14 +242,14 @@ int32_t PipetteModuleV2::pipette_zmotor_move_zero() { //
* @return int32_t
*/
int32_t PipetteModuleV2::pipette_zmotor_measure_distance() {
- thread_start_work([this]() {
+ THREAD_START_WORK([this]() {
int32_t startpos = zm_get_now_pos();
do_zm_move_0p(); // 移动到零点
int32_t dpos = zm_get_now_pos() - startpos;
- if (creg.module_errorcode != 0) { // 计算并更新零点坐标
- zm_set_now_pos(0 + m_cfg.zm_dzero - m_cfg.zm_io_trigger_append_distance);
- m_state.has_move_to_zero = 1;
- }
+
+ zm_set_now_pos(0 + m_cfg.zm_dzero - m_cfg.zm_io_trigger_append_distance);
+ m_state.has_move_to_zero = 1;
+
m_asynchronous_result.result0 = 0 + m_cfg.zm_dzero - m_cfg.zm_io_trigger_append_distance - dpos;
});
return 0;
@@ -271,7 +272,8 @@ int32_t PipetteModuleV2::pipette_zmotor_read_measure_distance_result(int32_t *re
* @return int32_t
*/
int32_t PipetteModuleV2::pipette_zmotor_move_by(int32_t distance) {
- thread_start_work([this, distance]() {
+ THREAD_START_WORK([this, distance]() {
+ module_active_cfg();
zm_move_by(distance, m_cfg.zm_default_velocity);
zm_waitfor_stop();
});
@@ -284,11 +286,10 @@ int32_t PipetteModuleV2::pipette_zmotor_move_by(int32_t distance) {
* @return int32_t
*/
int32_t PipetteModuleV2::pipette_zmotor_move_to(int32_t tox) {
- if (m_state.has_move_to_zero == 0) return err::kstep_motor_not_move_to_zero;
if (m_cfg.zm_min_d != 0 && tox < m_cfg.zm_min_d) tox = m_cfg.zm_min_d;
if (m_cfg.zm_max_d != 0 && tox > m_cfg.zm_max_d) tox = m_cfg.zm_max_d;
- thread_start_work([this, tox]() {
+ THREAD_START_WORK([this, tox]() {
zm_move_to(tox, m_cfg.zm_default_velocity);
zm_waitfor_stop();
});
@@ -301,13 +302,12 @@ int32_t PipetteModuleV2::pipette_zmotor_move_to(int32_t tox) {
* @return int32_t
*/
int32_t PipetteModuleV2::pipette_zmotor_move_to_zero_point_quick() {
- if (m_state.has_move_to_zero == 0) return err::kstep_motor_not_move_to_zero;
- thread_start_work([this]() { do_pipette_zmotor_move_to_zero_point_quick(); });
+ THREAD_START_WORK([this]() { do_pipette_zmotor_move_to_zero_point_quick(); });
return 0;
}
int32_t PipetteModuleV2::pipette_init_device() {
- thread_start_work([this]() {
+ THREAD_START_WORK([this]() {
DO_IN_THREAD(m_smtp2.pump_init(m_cfg.pump_vmax));
pump_waitfor_stop();
//
@@ -319,14 +319,14 @@ int32_t PipetteModuleV2::pipette_init_device() {
}
int32_t PipetteModuleV2::pipette_put_tip() {
- thread_start_work([this]() { DO_IN_THREAD(m_smtp2.pump_put_tip()); });
+ THREAD_START_WORK([this]() { DO_IN_THREAD(m_smtp2.pump_put_tip()); });
return 0;
}
int32_t PipetteModuleV2::pipette_lld_prepare() {
if (m_state.pipette_is_inited == 0) return err::kpipette_error_uninited;
- thread_start_work([this]() {
+ THREAD_START_WORK([this]() {
DO_IN_THREAD(m_smtp2.pump_move_to_ul(m_cfg.pump_vmax, m_cfg.lld_prepare_pos)); // 移动到中点
pump_waitfor_stop();
m_state.lld_prepared = 1;
@@ -342,7 +342,7 @@ int32_t PipetteModuleV2::pipette_lld(int32_t lldtype, int32_t zdpos, int32_t c_t
DO(m_smtp2.pump_get_tip_state(&tipstate));
if (tipstate != 0) return err::kpipette_error_tipisload_when_lld_prepare;
- thread_start_work([this, lldtype, zdpos, c_threshold, p_threshold]() { //
+ THREAD_START_WORK([this, lldtype, zdpos, c_threshold, p_threshold]() { //
m_state.lld_prepared = 0; // 失效m_state.lld_prepared
int32_t start_capacitance = 0; // 启动时电容数值
@@ -434,7 +434,7 @@ int32_t PipetteModuleV2::pipette_lld(int32_t lldtype, int32_t zdpos, int32_t c_t
int32_t PipetteModuleV2::pipette_aspirate_prepare() {
if (m_state.pipette_is_inited == 0) return err::kpipette_error_uninited;
- thread_start_work([this]() { //
+ THREAD_START_WORK([this]() { //
ZLOGI(TAG, "pipette_aspirate_prepare");
m_state.aspirate_cfg_eigen_time = 0;
m_state.aspirate_cfg_p_thre = 0;
@@ -471,7 +471,7 @@ int32_t PipetteModuleV2::pipette_aspirate_set_operation_verifi_tolerance(int32_t
int32_t PipetteModuleV2::pipette_aspirate(int32_t ul) {
if (m_state.pipette_is_inited == 0) return err::kpipette_error_uninited;
- thread_start_work([this, ul]() {
+ THREAD_START_WORK([this, ul]() {
m_state.lld_prepared = 0;
DO_IN_THREAD(m_smtp2.pump_move_to_ul(m_cfg.pump_vmax, ASPIRATE_POS));
@@ -499,7 +499,7 @@ int32_t PipetteModuleV2::pipette_aspirate(int32_t ul) {
int32_t PipetteModuleV2::pipette_aspirate_and_verify(int32_t ul) {
if (m_state.pipette_is_inited == 0) return err::kpipette_error_uninited;
- thread_start_work([this, ul]() {
+ THREAD_START_WORK([this, ul]() {
m_state.lld_prepared = 0;
// zmotor and pump move
@@ -523,7 +523,7 @@ int32_t PipetteModuleV2::pipette_aspirate_and_verify(int32_t ul) {
int32_t PipetteModuleV2::pipette_shake_up(int32_t ul, int32_t times) {
if (m_state.pipette_is_inited == 0) return err::kpipette_error_uninited;
- thread_start_work([this, ul, times]() {
+ THREAD_START_WORK([this, ul, times]() {
//
int32_t dpos = 0;
@@ -564,7 +564,7 @@ int32_t PipetteModuleV2::pipette_shake_up(int32_t ul, int32_t times) {
int32_t PipetteModuleV2::pipette_aspirate_infer_pressure(int32_t ul) {
if (m_state.pipette_is_inited == 0) return err::kpipette_error_uninited;
- thread_start_work([this, ul]() {
+ THREAD_START_WORK([this, ul]() {
//
ZLOGI(TAG, "pipette_aspirate_infer_pressure %d", ul);
m_asynchronous_result.result0 = 0;
@@ -583,7 +583,7 @@ int32_t PipetteModuleV2::pipette_aspirate_infer_eigen_time(int32_t ul) {
if (m_state.pipette_is_inited == 0) return err::kpipette_error_uninited;
//
- thread_start_work([this, ul]() {
+ THREAD_START_WORK([this, ul]() {
//
ZLOGI(TAG, "pipette_aspirate_infer_eigen_time %d", ul);
m_asynchronous_result.result0 = 0;
@@ -684,12 +684,14 @@ void PipetteModuleV2::zm_set_now_pos(int32_t x) {
m_zm->set_enc_val(x);
}
void PipetteModuleV2::zm_move_to(int32_t x, int32_t v) {
+ ZLOGI(TAG, "zm_move_to %d %d", x, v);
if (m_cfg.zm_enable_enc != 0) {
m_zm->setXACTUAL(m_zm->read_enc_val());
}
m_zm->moveTo(x, v);
}
void PipetteModuleV2::zm_move_by(int32_t dx, int32_t v) {
+ ZLOGI(TAG, "zm_move_by %d %d", dx, v);
if (m_cfg.zm_enable_enc != 0) {
m_zm->setXACTUAL(m_zm->read_enc_val());
}
@@ -787,14 +789,22 @@ int32_t PipetteModuleV2::pipette_get_sensor_sample_data_num(int32_t *num) {
* @brief 参数检查
*/
int32_t PipetteModuleV2::bfcall(int32_t cmdid, uint8_t *param, int32_t len) {
- ZLOGI(TAG, "bfcall %s", cmdid2str(cmdid));
+ if (cmdid == kmodule_get_status) return 0;
+
+ ZLOGI(TAG, "m%d bfcall %s ->", m_id, cmdid2str(cmdid));
if (cmdid == kpipette_zmotor_move_zero) goto check;
- if (cmdid == kpipette_zmotor_move_to_zero_point_quick) goto check;
+ if (cmdid == kpipette_zmotor_move_to_zero_point_quick) {
+ if (m_state.has_move_to_zero == 0) return err::kstep_motor_not_move_to_zero;
+ goto check;
+ }
if (cmdid == kpipette_zmotor_measure_distance) goto check;
if (cmdid == kpipette_zmotor_read_measure_distance_result) goto check;
if (cmdid == kpipette_zmotor_move_by) goto check;
- if (cmdid == kpipette_zmotor_move_to) goto check;
+ if (cmdid == kpipette_zmotor_move_to) {
+ if (m_state.has_move_to_zero == 0) return err::kstep_motor_not_move_to_zero;
+ goto check;
+ }
if (cmdid == kpipette_init_device) goto check;
if (cmdid == kpipette_put_tip) goto check;
if (cmdid == kpipette_lld_prepare) goto check;
@@ -831,11 +841,13 @@ check:
return 0;
}
-void PipetteModuleV2::aftercall(int32_t val) {
- if (val == 0) {
- ZLOGI(TAG, "call success");
+void PipetteModuleV2::aftercall(int32_t cmdid, uint8_t *param, int32_t len, uint8_t *ack, int32_t acklen, int32_t ret) {
+ if (cmdid == kmodule_get_status) return;
+
+ if (ret == 0) {
+ ZLOGI(TAG, "<- call success", m_id);
} else {
- ZLOGI(TAG, "call fail,%s(%d)", err::error2str(val), val);
+ ZLOGI(TAG, "<- call fail,%s(%d)", err::error2str(ret), ret);
}
}
void PipetteModuleV2::runingcheck() {
@@ -860,17 +872,17 @@ void PipetteModuleV2::runingcheck() {
// 检查电机状态
{
- auto state = m_zm->getGState();
- if (state.reset) {
- ZLOGE(TAG, "motor reset when run");
- throw zapp_exception(err::kstep_motor_subic_reset);
- } else if (state.uv_cp) {
- ZLOGE(TAG, "motor uv_cp when run");
- throw zapp_exception(err::kstep_motor_uv_cp);
- } else if (state.drv_err) {
- ZLOGE(TAG, "motor drv_err when run");
- throw zapp_exception(err::kstep_motor_drv_err);
- }
+ // auto state = m_zm->getGState();
+ // if (state.reset) {
+ // ZLOGE(TAG, "motor reset when run");
+ // throw zapp_exception(err::kstep_motor_subic_reset);
+ // } else if (state.uv_cp) {
+ // ZLOGE(TAG, "motor uv_cp when run");
+ // throw zapp_exception(err::kstep_motor_uv_cp);
+ // } else if (state.drv_err) {
+ // ZLOGE(TAG, "motor drv_err when run");
+ // throw zapp_exception(err::kstep_motor_drv_err);
+ // }
}
}
@@ -881,12 +893,14 @@ void PipetteModuleV2::thread_delay(int32_t delayms) { //
throw zapp_thread_stoped_exception();
}
}
-void PipetteModuleV2::thread_start_work(function fn) {
+void PipetteModuleV2::thread_start_work(const char *fnname, function fn) {
m_thread.stop();
creg.module_status = 1;
creg.module_errorcode = 0;
- m_thread.start([this, fn]() {
+ m_thread.start([this, fnname, fn]() {
+ osDelay(1);
+ ZLOGI(TAG, "start work -> %s", fnname);
int32_t pump_before_pos_ul;
int32_t pump_after_pos_ul;
@@ -908,12 +922,17 @@ void PipetteModuleV2::thread_start_work(function fn) {
m_state.dul = pump_after_pos_ul - pump_before_pos_ul;
m_state.dpos = endpos - startpos;
} catch (const zapp_thread_stoped_exception &e) { // break by usr
+ ZLOGI(TAG, "break by usr");
m_zm->stop();
m_smtp2.pump_stop();
} catch (const zapp_exception &e) {
+ ZLOGI(TAG, "catch exception %d", e.ecode());
m_zm->stop();
m_smtp2.pump_stop();
creg.module_errorcode = e.ecode();
}
+
+ creg.module_status = 0;
+ ZLOGI(TAG, "<- end work");
});
}
diff --git a/sdk/components/pipette_module/pipette_ctrl_module_v2.hpp b/sdk/components/pipette_module/pipette_ctrl_module_v2.hpp
index 25e1f7c..c8e320a 100644
--- a/sdk/components/pipette_module/pipette_ctrl_module_v2.hpp
+++ b/sdk/components/pipette_module/pipette_ctrl_module_v2.hpp
@@ -191,7 +191,7 @@ class PipetteModuleV2 : public ZIModule {
virtual int32_t pipette_zmotor_read_dev_status_cache(int32_t *devStatus);
private:
- int32_t _module_xxx_reg(int32_t param_id, bool read, int32_t &val);
+ int32_t module_xxx_reg_impl(int32_t param_id, bool read, int32_t &val);
void beforecallfn(const char *fn);
void aftercallfn(const char *fn);
@@ -230,9 +230,9 @@ class PipetteModuleV2 : public ZIModule {
* SLICE *
***********************************************************************************************************************/
virtual int32_t bfcall(int32_t cmdid, uint8_t *param, int32_t len) override;
- virtual void aftercall(int32_t val);
+ virtual void aftercall(int32_t cmdid, uint8_t *param, int32_t len, uint8_t *ack, int32_t acklen, int32_t ret);
void runingcheck();
void thread_delay(int32_t delayms);
- void thread_start_work(function fn);
+ void thread_start_work(const char *fnname, function fn);
};
} // namespace iflytop
diff --git a/sdk/components/tmc/ic/ztmc5130.cpp b/sdk/components/tmc/ic/ztmc5130.cpp
index b244f2b..9f3c646 100644
--- a/sdk/components/tmc/ic/ztmc5130.cpp
+++ b/sdk/components/tmc/ic/ztmc5130.cpp
@@ -203,7 +203,7 @@ void TMC51X0::moveTo(int32_t position, uint32_t velocityMax) {
}
void TMC51X0::moveToEnd(int32_t direction, uint32_t velocityMax) {
ZLOGI("TMC5130", "moveToEnd %d %d", direction, velocityMax);
- if (direction >= 0) {
+ if (direction > 0) {
writeInt(TMC5130_RAMPMODE, TMC5130_MODE_POSITION);
writeInt(TMC5130_VMAX, to_motor_vel(velocityMax));
writeInt(TMC5130_XTARGET, INT32_MAX / 2 - 1000);
diff --git a/sdk/components/zcancmder/zcan_protocol_parser.cpp b/sdk/components/zcancmder/zcan_protocol_parser.cpp
index bac0970..045e738 100644
--- a/sdk/components/zcancmder/zcan_protocol_parser.cpp
+++ b/sdk/components/zcancmder/zcan_protocol_parser.cpp
@@ -237,7 +237,7 @@ void ZCanProtocolParser::_onRceivePacket(ZIModule* module, zcr_cmd_header_t* rxc
int32_t ecode = module->bfcall(cmdid, param, len);
if (ecode == 0) ecode = fn->cb(&cxt);
- module->aftercall(ecode);
+ module->aftercall(cmdid, param, len, cxt.ackbuf, cxt.acklen, ecode);
if (ecode != 0) {
m_cancmder->sendErrorAck(rxcmd, ecode);