From 0c656364957c84f81d075df65cb2da3adf61d6bb Mon Sep 17 00:00:00 2001 From: zhaohe Date: Wed, 21 May 2025 19:52:24 +0800 Subject: [PATCH] update --- sdk/chip/exhal/stm32_exhal_uart.cpp | 15 ++- sdk/chip/exhal/stm32_exhal_uart.hpp | 2 + sdk/components/pipette_module/base/pipette_cfg.hpp | 139 +++++++++++---------- .../pipette_module/pipette_ctrl_module.cpp | 130 ++++++++++++------- .../pipette_module/pipette_ctrl_module.hpp | 17 ++- sdk/components/sensors/smtp2_v2/smtp2_v2.cpp | 10 +- sdk/components/sensors/smtp2_v2/smtp2_v2.hpp | 1 + .../subboard80_cliptip/subboard80_cliptip.cpp | 50 +++----- .../subboard80_cliptip/subboard80_cliptip_board.c | 71 +++++++++++ 9 files changed, 279 insertions(+), 156 deletions(-) diff --git a/sdk/chip/exhal/stm32_exhal_uart.cpp b/sdk/chip/exhal/stm32_exhal_uart.cpp index b9072e4..8afacac 100644 --- a/sdk/chip/exhal/stm32_exhal_uart.cpp +++ b/sdk/chip/exhal/stm32_exhal_uart.cpp @@ -1,6 +1,7 @@ #include "stm32_exhal_uart.hpp" #include +#include #include "sdk/chip/irq_dispatcher/zuart_irq_dispatcher.hpp" #include "sdk/utils/hexutils.h" @@ -40,8 +41,6 @@ static EXHAL_UART_t* EXHAL_UART_Get(UART_HandleTypeDef* huart) { return &Local_exhalUart[i]; } } - - ZEARLY_ASSERT(0); return NULL; } @@ -172,6 +171,7 @@ HAL_StatusTypeDef EXHAL_UART_BindRS485Uart(const char* name, UART_HandleTypeDef* void EXHAL_UART_RS485_EnTx(UART_HandleTypeDef* huart, bool en) { EXHAL_UART_t* exhal_uart = EXHAL_UART_Get(huart); + ZEARLY_ASSERT(exhal_uart != NULL); if (exhal_uart->rs485_txen_port == NULL) return; if (en) { HAL_GPIO_WritePin(exhal_uart->rs485_txen_port, exhal_uart->rs485_txen_pin, GPIO_PIN_SET); @@ -182,12 +182,14 @@ void EXHAL_UART_RS485_EnTx(UART_HandleTypeDef* huart, bool en) { HAL_StatusTypeDef EXHAL_UART_RegListener(UART_HandleTypeDef* huart, EXHAL_UART_Listener_t listener) { EXHAL_UART_t* exhal_uart = EXHAL_UART_Get(huart); + ZEARLY_ASSERT(exhal_uart != NULL); exhal_uart->listener = listener; return HAL_OK; } HAL_StatusTypeDef EXHAL_UART_TransmitBlock_DMA(UART_HandleTypeDef* huart, uint8_t* data, size_t len) { EXHAL_UART_t* exhal_uart = EXHAL_UART_Get(huart); + ZEARLY_ASSERT(exhal_uart != NULL); exhal_uart->rxstate = TRANSMIT_BLOCK_DMA; HAL_StatusTypeDef ret = HAL_UART_Transmit_DMA(huart, data, len); @@ -202,6 +204,9 @@ HAL_StatusTypeDef EXHAL_UART_TransmitBlock_DMA(UART_HandleTypeDef* huart, uint8_ return HAL_OK; } +HAL_StatusTypeDef EXHAL_UART_TransmitStringBlock(UART_HandleTypeDef* huart, const char* data){// + return HAL_UART_Transmit(huart, (uint8_t*)data, strlen(data),100); +} static void __attribute__((noinline)) clearUartRxCache(UART_HandleTypeDef* huart) { // volatile uint32_t rxcache = huart->Instance->DR; @@ -209,6 +214,7 @@ static void __attribute__((noinline)) clearUartRxCache(UART_HandleTypeDef* huart HAL_StatusTypeDef EXHAL_UARTEx_ReceiveToIdle_DMA_Start(UART_HandleTypeDef* huart, uint8_t* data, int32_t len) { EXHAL_UART_t* exhal_uart = EXHAL_UART_Get(huart); + ZEARLY_ASSERT(exhal_uart != NULL); exhal_uart->rxstate = RECEIVE_TO_IDLE_DMA; exhal_uart->receiveToIdleDmaRxSize = 0; @@ -226,6 +232,7 @@ HAL_StatusTypeDef EXHAL_UARTEx_ReceiveToIdle_DMA_Start(UART_HandleTypeDef* huart HAL_StatusTypeDef EXHAL_UARTEx_ReceiveToIdle_DMA_Wait(UART_HandleTypeDef* huart, size_t* rxlen, int32_t overtime) { EXHAL_UART_t* exhal_uart = EXHAL_UART_Get(huart); + ZEARLY_ASSERT(exhal_uart != NULL); uint32_t enterTicket = HAL_GetTick(); @@ -254,6 +261,8 @@ HAL_StatusTypeDef EXHAL_UART_DMAStartAutoRead(UART_HandleTypeDef* huart) { clearUartRxCache(huart); EXHAL_UART_t* exhal_uart = EXHAL_UART_Get(huart); + ZEARLY_ASSERT(exhal_uart != NULL); + exhal_uart->rxstate = AUTO_READ_DMA; HAL_UARTEx_ReceiveToIdle_DMA_force(huart, exhal_uart->autoRxBuffer, sizeof(exhal_uart->autoRxBuffer)); __HAL_DMA_DISABLE_IT(huart->hdmarx, DMA_IT_HT); @@ -290,6 +299,8 @@ HAL_StatusTypeDef EXHAL_UART_DMAStopAutoRead(UART_HandleTypeDef* huart) { HAL_StatusTypeDef EXHAL_UART_ITStartAutoRead(UART_HandleTypeDef* huart) { clearUartRxCache(huart); EXHAL_UART_t* exhal_uart = EXHAL_UART_Get(huart); + ZEARLY_ASSERT(exhal_uart != NULL); + exhal_uart->rxstate = AUTO_READ_IT; while (true) { diff --git a/sdk/chip/exhal/stm32_exhal_uart.hpp b/sdk/chip/exhal/stm32_exhal_uart.hpp index cd95571..f8a876d 100644 --- a/sdk/chip/exhal/stm32_exhal_uart.hpp +++ b/sdk/chip/exhal/stm32_exhal_uart.hpp @@ -21,6 +21,8 @@ void EXHAL_UART_RS485_EnTx(UART_HandleTypeDef* huart, bool en); // tx block HAL_StatusTypeDef EXHAL_UART_TransmitBlock_DMA(UART_HandleTypeDef* huart, uint8_t* data, size_t len); +HAL_StatusTypeDef EXHAL_UART_TransmitStringBlock(UART_HandleTypeDef* huart, const char* data); + // rx blcok HAL_StatusTypeDef EXHAL_UARTEx_ReceiveToIdle_DMA_Start(UART_HandleTypeDef* huart, uint8_t* data, int32_t len); diff --git a/sdk/components/pipette_module/base/pipette_cfg.hpp b/sdk/components/pipette_module/base/pipette_cfg.hpp index 1c0099d..0d7c4e0 100644 --- a/sdk/components/pipette_module/base/pipette_cfg.hpp +++ b/sdk/components/pipette_module/base/pipette_cfg.hpp @@ -6,14 +6,16 @@ typedef struct { /** * @brief 工作参考平面 - * + * 代码中并不使用这个位置,这个参数只是为了后续 + * 如果平台高度发生变化时,可以通过调整dzero使得 + * work_ref_plane数值不变。 */ - int32_t work_ref_plane; // 移液枪带上tip后,tip刚好与平面接触时候,z轴的坐标,后续系统中非特殊情况,所有坐标参考这个坐标 + int32_t work_ref_pos; // - int32_t tip_picking_pos; // 开始取tip位置(参考位0.1mm) + int32_t tip_picking_pos; // 开始取tip位置(绝对位置0.1mm) int32_t tip_picking_search_range; // 取tip的范围 - int32_t tip_deposit_pos; // 丢tip位置(参考位0.1mm) - // int32_t transform_pos; // 移液枪安全移动的高度(参考位0.1mm) + int32_t tip_deposit_pos; // 丢tip位置(绝对位置0.1mm) + int32_t transform_pos; // 移液枪安全移动的高度(绝对位置0.1mm) /** * @brief tip类型 * @@ -27,13 +29,13 @@ typedef struct { } platinfo_t; typedef enum { - kplatinfo_work_ref_plane = 100, - kplatinfo_tip_picking_pos = 101, - kplatinfo_tip_picking_search_range = 102, - kplatinfo_tip_deposit_pos = 103, - // kplatinfo_transform_pos = 104, - kplatinfo_tip_type = 105, - kplatinfo_tip_length = 106, + kplatinfo_work_ref_pos = 100, + kplatinfo_tip_picking_pos, + kplatinfo_tip_picking_search_range, + kplatinfo_tip_deposit_pos, + kplatinfo_transform_pos, + kplatinfo_tip_type, + kplatinfo_tip_length, } platinfo_index_t; /*********************************************************************************************************************** @@ -59,22 +61,22 @@ typedef struct { } zm_bcfg_t; typedef enum { - kzm_bcfg_shaft = 200, - kzm_bcfg_one_circle_pulse = 201, - kzm_bcfg_one_circle_pulse_denominator = 202, - kzm_bcfg_ihold = 203, - kzm_bcfg_irun = 204, - kzm_bcfg_iholddelay = 205, - kzm_bcfg_iglobalscaler = 206, - kzm_bcfg_min_d = 207, - kzm_bcfg_max_d = 208, - kzm_bcfg_tzerowait = 209, - kzm_bcfg_enc_resolution = 210, - kzm_bcfg_enable_enc = 211, - kzm_bcfg_dzero = 212, - kzm_bcfg_io_trigger_append_distance = 213, - kzm_bcfg_pos_devi_tolerance = 214, - kzm_bcfg_mres = 215, + kzm_bcfg_shaft = 200, + kzm_bcfg_one_circle_pulse, + kzm_bcfg_one_circle_pulse_denominator, + kzm_bcfg_ihold, + kzm_bcfg_irun, + kzm_bcfg_iholddelay, + kzm_bcfg_iglobalscaler, + kzm_bcfg_min_d, + kzm_bcfg_max_d, + kzm_bcfg_tzerowait, + kzm_bcfg_enc_resolution, + kzm_bcfg_enable_enc, + kzm_bcfg_dzero, + kzm_bcfg_io_trigger_append_distance, + kzm_bcfg_pos_devi_tolerance, + kzm_bcfg_mres, } zm_bcfg_index_t; /*********************************************************************************************************************** @@ -103,13 +105,13 @@ typedef struct { typedef enum { kzm_vcfg_vstart = 400, - kzm_vcfg_a1 = 401, - kzm_vcfg_amax = 402, - kzm_vcfg_v1 = 403, - kzm_vcfg_dmax = 404, - kzm_vcfg_d1 = 405, - kzm_vcfg_vstop = 406, - kzm_vcfg_vmax = 407, + kzm_vcfg_a1, + kzm_vcfg_amax, + kzm_vcfg_v1, + kzm_vcfg_dmax, + kzm_vcfg_d1, + kzm_vcfg_vstop, + kzm_vcfg_vmax, } zm_vcfg_index_t; /*********************************************************************************************************************** @@ -124,11 +126,11 @@ typedef struct { } pm_vcfg_t; typedef enum { - kpm_vcfg_acc = 500, - kpm_vcfg_dec = 501, - kpm_vcfg_vstart = 502, - kpm_vcfg_vstop = 503, - kpm_vcfg_vmax = 504, + kpm_vcfg_acc = 500, + kpm_vcfg_dec, + kpm_vcfg_vstart, + kpm_vcfg_vstop, + kpm_vcfg_vmax, } pm_vcfg_index_t; /*********************************************************************************************************************** @@ -149,17 +151,17 @@ typedef struct { } container_info_t; typedef enum { - kcontainer_info_container_type = 600, - kcontainer_info_container_neck_pos = 601, - kcontainer_info_container_depth = 602, - kcontainer_info_container_round = 603, - kcontainer_info_container_bottom_section_height = 604, - kcontainer_info_immersion_depth = 605, - kcontainer_info_leaving_height = 606, - kcontainer_info_jet_height = 607, - kcontainer_info_lld_start_search_depth = 608, - kcontainer_info_fix_aspiration_depth = 609, - kcontainer_info_llf_vconvert_coneff = 610, + kcontainer_info_container_type = 600, + kcontainer_info_container_neck_pos, + kcontainer_info_container_depth, + kcontainer_info_container_round, + kcontainer_info_container_bottom_section_height, + kcontainer_info_immersion_depth, + kcontainer_info_leaving_height, + kcontainer_info_jet_height, + kcontainer_info_lld_start_search_depth, + kcontainer_info_fix_aspiration_depth, + kcontainer_info_llf_vconvert_coneff, } container_info_index_t; /*********************************************************************************************************************** @@ -185,6 +187,7 @@ typedef struct { // int32_t plld_pm_vindex; // 液面探测时泵机速率 int32_t plld_threshold; // 液面探测阈值 + int32_t plld_zm_vel; // 液面探测时泵机速率 // // 清空tip配置 @@ -250,20 +253,22 @@ typedef struct { } liquid_info_t; typedef enum { - kliquid_info_plld_pm_vindex = 800, - kliquid_info_plld_threshold = 801, - kliquid_info_empty_tip_pm_vindex = 802, - kliquid_info_blowout_air_volume = 803, - kliquid_info_blowout_air_pm_vindex = 804, - kliquid_info_over_aspirated_volume = 805, - kliquid_info_over_aspirated_pm_vindex = 806, - kliquid_info_aspiration_pm_vindex_low = 807, - kliquid_info_aspiration_pm_vindex_high = 808, - kliquid_info_aspiration_volume_break_val = 809, - kliquid_info_volume_calibration_coefficient_b = 810, - kliquid_info_volume_calibration_coefficient_k = 811, - kliquid_info_settling_time = 812, - kliquid_info_transport_volume = 813, - kliquid_info_transport_volume_pm_vindex = 814, - kliquid_info_mix_pm_vindex = 815, + kliquid_info_plld_pm_vindex = 800, + kliquid_info_plld_threshold, + kliquid_info_plld_zm_vel, + kliquid_info_empty_tip_pm_vindex, + kliquid_info_blowout_air_volume, + kliquid_info_blowout_air_pm_vindex, + kliquid_info_over_aspirated_volume, + kliquid_info_over_aspirated_pm_vindex, + kliquid_info_aspiration_pm_vindex_low, + kliquid_info_aspiration_pm_vindex_high, + kliquid_info_aspiration_volume_break_val, + kliquid_info_volume_calibration_coefficient_b, + kliquid_info_volume_calibration_coefficient_k, + kliquid_info_settling_time, + kliquid_info_transport_volume, + kliquid_info_transport_volume_pm_vindex, + kliquid_info_mix_pm_vindex, + } liquid_info_index_t; \ No newline at end of file diff --git a/sdk/components/pipette_module/pipette_ctrl_module.cpp b/sdk/components/pipette_module/pipette_ctrl_module.cpp index 5f7fc7a..22217bc 100644 --- a/sdk/components/pipette_module/pipette_ctrl_module.cpp +++ b/sdk/components/pipette_module/pipette_ctrl_module.cpp @@ -5,9 +5,9 @@ #include "sdk\components\zcancmder\protocol_event_bus_sender.hpp" // #include "base/pipette_marco_utils.hpp" +#include "sdk/chip/exhal/stm32_exhal_uart.hpp" #include "sdk\components\exception\zapp_exception.hpp" #include "sdk\components\exception\zapp_thread_stoped_exception.hpp" - #define TAG "PipetteModule" using namespace iflytop; @@ -22,27 +22,71 @@ void PipetteModule::initialize(int32_t id, hardward_config_t *hardwaredcfg) { / m_zm = hardwaredcfg->zmotor; m_zm0p = hardwaredcfg->zmotor_0point; - // m_smtp2.pump_init(zm_default_cfg.pump_vmax); - // osDelay(3000); - // m_smtp2.write_cmd("/1?23R\r"); - m_zm->getGState(); // 读取状态,清空下复位标识 + m_piette_gun_io1.initAsInput(hardwaredcfg->IO1, ZGPIO::kMode_pullup, ZGPIO::kIRQ_noIrq, hardwaredcfg->IO1Mirror); + + // ZASSERT(hardwaredcfg->uart232); + // EXHAL_UART_BindUart("pipette-uart232", hardwaredcfg->uart232); + // EXHAL_UART_RegListener(hardwaredcfg->uart232, [this](UART_HandleTypeDef *huart, uint8_t *data, size_t len) { + // printf("!rx(%d): ", len); + // if (len > 0) { + // printf("%c", data[0]); + // } + // printf("\n"); + // }); + // EXHAL_UART_ITStartAutoRead(hardwaredcfg->uart232); + m_smtp2.pump_set_pressure_data_stream_port(0); // + // EXHAL_UART_BindUart("pipette-uart", hardwaredcfg->uart); + // EXHAL_UART_RegListener(hardwaredcfg->uart, [this](UART_HandleTypeDef *huart, uint8_t *data, size_t len) { + // printf("!rx(%d): ", len); + // for (size_t i = 0; i < len; i++) { + // printf("%c", data[i]); + // } + // printf("\n"); + // }); + // EXHAL_UART_DMAStartAutoRead(hardwaredcfg->uart); + // EXHAL_UART_TransmitStringBlock(hardwaredcfg->uart, "/1QR\r"); + // HAL_Delay(1000); + // EXHAL_UART_TransmitStringBlock(hardwaredcfg->uart232, "/1QR\r"); + + test_connectivity(); + parameter_init(); +} + +void PipetteModule::test_connectivity() { + bool io1_connected = false; + bool io1_reverse = false; + bool uart485_connected = false; + bool uart232_connected = false; - //! TODO: 将初始化代码移动到模块外部 - m_piette_gun_io1.initAsInput(PB1, ZGPIO::kMode_pullup, ZGPIO::kIRQ_noIrq, true); // lld输入高 + uart485_connected = m_smtp2.pump_ping(); //! 测试IO1是否联通 - m_smtp2.pump_set_io1_mode(2); // lld输入高 - m_smtp2.pump_set_io1_state(0); - osDelay(100); - ZLOGI(TAG, "read io1 state:%d", m_piette_gun_io1.getState()); - - m_smtp2.pump_set_io1_state(1); // lld输入高 - osDelay(100); - ZLOGI(TAG, "read io1 state:%d", m_piette_gun_io1.getState()); - m_smtp2.pump_set_io1_mode(0); // lld输入高 + if (uart485_connected) { + // 设置IO1为通用输出模式 + m_smtp2.pump_set_io1_mode(2); - parameter_init(); + // 设置IO1为低电平 + m_smtp2.pump_set_io1_state(0); + osDelay(2); + bool io1_state1 = m_piette_gun_io1.getState(); + + // 设置IO1为高电平 + m_smtp2.pump_set_io1_state(1); // lld输入高 + osDelay(2); + bool io1_state2 = m_piette_gun_io1.getState(); + io1_connected = (!io1_state1 && io1_state2) || (io1_state1 && !io1_state2); + io1_reverse = io1_state1 && !io1_state2; + } + + //! 测试232是否联通 + uart232_connected = false; + + ZLOGI(TAG, "===================== connectivity test report =========================="); + ZLOGI(TAG, "= uart485_connected :%d", uart485_connected); + ZLOGI(TAG, "= io1_connected :%d(%s)", io1_connected, io1_reverse ? "Err:Reverse" : ""); + ZLOGI(TAG, "= uart232_connected :%d", uart232_connected); + ZLOGI(TAG, "="); } int32_t PipetteModule::module_stop() { @@ -129,11 +173,11 @@ int32_t PipetteModule::pipette_set_platinfo(int32_t cpyid, platinfo_index_t inde platinfo_t *platinfo = &m_platinfo[cpyid]; switch (index) { - SET_CFG(kplatinfo_work_ref_plane, platinfo->work_ref_plane, val); + SET_CFG(kplatinfo_work_ref_pos, platinfo->work_ref_pos, val); SET_CFG(kplatinfo_tip_picking_pos, platinfo->tip_picking_pos, val); SET_CFG(kplatinfo_tip_picking_search_range, platinfo->tip_picking_search_range, val); SET_CFG(kplatinfo_tip_deposit_pos, platinfo->tip_deposit_pos, val); - // SET_CFG(kplatinfo_transform_pos, platinfo->transform_pos, val); + SET_CFG(kplatinfo_transform_pos, platinfo->transform_pos, val); SET_CFG(kplatinfo_tip_type, platinfo->tip_type, val); SET_CFG(kplatinfo_tip_length, platinfo->tip_length, val); default: { @@ -151,11 +195,11 @@ int32_t PipetteModule::pipette_get_platinfo(int32_t cpyid, platinfo_index_t inde platinfo_t *platinfo = &m_platinfo[cpyid]; switch (index) { - GET_CFG(kplatinfo_work_ref_plane, platinfo->work_ref_plane, val); + GET_CFG(kplatinfo_work_ref_pos, platinfo->work_ref_pos, val); GET_CFG(kplatinfo_tip_picking_pos, platinfo->tip_picking_pos, val); GET_CFG(kplatinfo_tip_picking_search_range, platinfo->tip_picking_search_range, val); GET_CFG(kplatinfo_tip_deposit_pos, platinfo->tip_deposit_pos, val); - // GET_CFG(kplatinfo_transform_pos, platinfo->transform_pos, val); + GET_CFG(kplatinfo_transform_pos, platinfo->transform_pos, val); GET_CFG(kplatinfo_tip_type, platinfo->tip_type, val); GET_CFG(kplatinfo_tip_length, platinfo->tip_length, val); default: { @@ -311,6 +355,7 @@ int32_t PipetteModule::pipette_set_liquid_info(int32_t cpyid, liquid_info_index_ switch (index) { SET_CFG(kliquid_info_plld_pm_vindex, cfg->plld_pm_vindex, val); SET_CFG(kliquid_info_plld_threshold, cfg->plld_threshold, val); + SET_CFG(kliquid_info_plld_zm_vel, cfg->plld_zm_vel, val); SET_CFG(kliquid_info_empty_tip_pm_vindex, cfg->empty_tip_pm_vindex, val); SET_CFG(kliquid_info_blowout_air_volume, cfg->blowout_air_volume, val); SET_CFG(kliquid_info_blowout_air_pm_vindex, cfg->blowout_air_pm_vindex, val); @@ -343,6 +388,7 @@ int32_t PipetteModule::pipette_get_liquid_info(int32_t cpyid, liquid_info_index_ switch (index) { GET_CFG(kliquid_info_plld_pm_vindex, cfg->plld_pm_vindex, val); GET_CFG(kliquid_info_plld_threshold, cfg->plld_threshold, val); + GET_CFG(kliquid_info_plld_zm_vel, cfg->plld_zm_vel, val); GET_CFG(kliquid_info_empty_tip_pm_vindex, cfg->empty_tip_pm_vindex, val); GET_CFG(kliquid_info_blowout_air_volume, cfg->blowout_air_volume, val); GET_CFG(kliquid_info_blowout_air_pm_vindex, cfg->blowout_air_pm_vindex, val); @@ -658,7 +704,7 @@ int32_t PipetteModule::pipette_pump_aspirate() { if (acfg->lld_type != 0) { _do_lld(platform_info, container_cfg, liquidinfo, acfg); } else { - m_state.water_level = platform_info->work_ref_plane - container_cfg->container_neck_pos + container_cfg->fix_aspiration_depth; + m_state.water_level = container_cfg->container_neck_pos + container_cfg->fix_aspiration_depth; ZLOGI(TAG, "lld isn't enable,use fix depth %d", m_state.water_level); zm_move_to_block(m_state.water_level - 150, kzm_v_default, 0); // pump_move_to_x100nl_block(0, liquidinfo->empty_tip_pm_vindex); // 清空tip @@ -680,8 +726,8 @@ void PipetteModule::_do_lld(platinfo_t *platform_info, container_info_t *contain pump_move_to_x100nl_block(0, liquidinfo->empty_tip_pm_vindex); // 移动到瓶口 - zm_wp_move_to_block(platform_info, container_cfg->container_neck_pos + 50 /*5mm*/, // - kzm_v_default, 0); + zm_move_to_block(container_cfg->container_neck_pos + 50 /*5mm*/, // + kzm_v_default, 0); pump_move_to_x100nl_block(0, kpm_v_default); // 回转一下,消除齿轮间隙 // 启动lld @@ -691,10 +737,10 @@ void PipetteModule::_do_lld(platinfo_t *platform_info, container_info_t *contain DO_IN_THREAD(m_smtp2.pump_aspirate_plld(liquidinfo->plld_threshold)); // 快速移动到瓶口 - zm_wp_move_to_block(platform_info, container_cfg->container_neck_pos + container_cfg->lld_start_search_depth, // - kzm_v_default, 0); + zm_move_to_block(container_cfg->container_neck_pos + container_cfg->lld_start_search_depth, // + kzm_v_default, 0); // lld,zm移动到瓶底 - zm_wp_move_to(platform_info, container_cfg->container_neck_pos - container_cfg->container_depth, kzm_v_lld, 0); + zm_move_to(container_cfg->container_neck_pos + container_cfg->container_depth, kzm_v_lld, liquidinfo->plld_zm_vel); /** * @brief 等待压力大于阈值 @@ -770,10 +816,9 @@ void PipetteModule::_do_sapirate(platinfo_t *platform_info, container_info_t *co int32_t mix_start_pos = zm_get_now_pos(); for (size_t i = 0; i < acfg->mix_times; i++) { if (acfg->mix_llf_enable > 0) { - zm_wp_move_to(platform_info, - container_cfg->container_neck_pos - container_cfg->container_depth, // 瓶底 - kzm_v_llf, // 基础速度配置 - compute_zm_llf_vel(liquidinfo->mix_pm_vindex, container_cfg)); // 计算llf速度 + zm_move_to(container_cfg->container_neck_pos + container_cfg->container_depth, // 瓶底 + kzm_v_llf, // 基础速度配置 + compute_zm_llf_vel(liquidinfo->mix_pm_vindex, container_cfg)); // 计算llf速度 } pump_move_by_x100nl_block(acfg->mix_volume, liquidinfo->mix_pm_vindex); if (acfg->mix_llf_enable > 0) zm_stop(); @@ -796,10 +841,10 @@ void PipetteModule::_do_sapirate(platinfo_t *platform_info, container_info_t *co int32_t x100nl = acfg->x100nl * liquidinfo->volume_calibration_coefficient_k * 0.0001 + liquidinfo->volume_calibration_coefficient_b * 0.0001; if (acfg->llf_enable > 0) { - zm_wp_move_to(platform_info, // - container_cfg->container_neck_pos - container_cfg->container_depth, // 瓶底 - kzm_v_llf, // - compute_zm_llf_vel(aspiration_pm_index, container_cfg) // + zm_move_to( // + container_cfg->container_neck_pos + container_cfg->container_depth, // 瓶底 + kzm_v_llf, // + compute_zm_llf_vel(aspiration_pm_index, container_cfg) // ); } pump_move_by_x100nl_block(x100nl, aspiration_pm_index); @@ -890,18 +935,6 @@ void PipetteModule::zm_move_to_block(int32_t x, int32_t vbaseindex, int32_t vel) zm_move_to(x, vbaseindex, vel); zm_waitfor_stop(); } -void PipetteModule::zm_wp_move_to(platinfo_t *platform, int32_t x, int32_t vbaseindex, int32_t vel) { - /** - * @brief 以平台的参考位置为基准,向上为正向,向下为负向 - */ - zm_move_to(platform->work_ref_plane - x, vbaseindex, vel); -} - -void PipetteModule::zm_wp_move_to_block(platinfo_t *platform, int32_t x, int32_t vbaseindex, int32_t vel) { - zm_wp_move_to(platform, x, vbaseindex, vel); - zm_waitfor_stop(); -} - void PipetteModule::zm_move_by(int32_t dx, int32_t vindex, int32_t vel) { ZLOGI(TAG, "zm_move_by %d %d", dx); if (zm_base_cfg.enable_enc != 0) { @@ -1302,7 +1335,7 @@ void PipetteModule::parameter_init() { * m_platinfo * ***********************************************************************************************************************/ for (int32_t i = 0; i < ARRARY_SIZE(m_platinfo); i++) { - m_platinfo[i].work_ref_plane = 0; + m_platinfo[i].work_ref_pos = 0; m_platinfo[i].tip_picking_pos = 0; m_platinfo[i].tip_picking_search_range = 0; m_platinfo[i].tip_deposit_pos = 0; @@ -1383,6 +1416,7 @@ void PipetteModule::parameter_init() { for (int32_t i = 0; i < ARRARY_SIZE(m_liquid_info); i++) { m_liquid_info[i].plld_pm_vindex = kpm_v_lld; m_liquid_info[i].plld_threshold = 30; + m_liquid_info[i].plld_zm_vel = 0; m_liquid_info[i].empty_tip_pm_vindex = kpm_v_max; m_liquid_info[i].blowout_air_volume = 0; m_liquid_info[i].blowout_air_pm_vindex = kpm_v_quick; diff --git a/sdk/components/pipette_module/pipette_ctrl_module.hpp b/sdk/components/pipette_module/pipette_ctrl_module.hpp index 8f78f40..ea5d9f1 100644 --- a/sdk/components/pipette_module/pipette_ctrl_module.hpp +++ b/sdk/components/pipette_module/pipette_ctrl_module.hpp @@ -43,6 +43,13 @@ class PipetteModule : public ZIModule { UART_HandleTypeDef *uart; DMA_HandleTypeDef *hdma_rx; DMA_HandleTypeDef *hdma_tx; + + // uart232 + UART_HandleTypeDef *uart232; + + Pin_t IO1; + bool IO1Mirror; + // 泵机Z轴驱动 TMC51X0 *zmotor = nullptr; ZGPIO *zmotor_0point = nullptr; @@ -90,6 +97,10 @@ class PipetteModule : public ZIModule { public: void initialize(int32_t id, hardward_config_t *hardwaredcfg); + private: + void test_connectivity(); + + public: /******************************************************************************* * Module * *******************************************************************************/ @@ -142,7 +153,7 @@ class PipetteModule : public ZIModule { virtual int32_t pipette_pump_init_device(); virtual int32_t pipette_pump_take_tip(int32_t tip_pos); virtual int32_t pipette_pump_put_tip(int32_t pos); - virtual int32_t pipette_pump_pierce_through(int32_t pos); + virtual int32_t pipette_pump_pierce_through(int32_t pos) { return 0; } virtual int32_t pipette_pump_aspirate_set_param(aspiration_paramid_t param, int32_t val); virtual int32_t pipette_pump_aspirate(); @@ -172,8 +183,8 @@ class PipetteModule : public ZIModule { void zm_move_to(int32_t x, int32_t vbaseindex, int32_t vel); void zm_move_to_block(int32_t x, int32_t vbaseindex, int32_t vel); - void zm_wp_move_to(platinfo_t *platform, int32_t x, int32_t vbaseindex, int32_t vel); - void zm_wp_move_to_block(platinfo_t *platform, int32_t x, int32_t vbaseindex, int32_t vel); + // void zm_wp_move_to(platinfo_t *platform, int32_t x, int32_t vbaseindex, int32_t vel); + // void zm_wp_move_to_block(platinfo_t *platform, int32_t x, int32_t vbaseindex, int32_t vel); void zm_move_by(int32_t dx, int32_t vindex, int32_t vel); void zm_stop(); void zm_move_to_end(int32_t direction, int32_t vindex); diff --git a/sdk/components/sensors/smtp2_v2/smtp2_v2.cpp b/sdk/components/sensors/smtp2_v2/smtp2_v2.cpp index f89d09e..d1aa7a9 100644 --- a/sdk/components/sensors/smtp2_v2/smtp2_v2.cpp +++ b/sdk/components/sensors/smtp2_v2/smtp2_v2.cpp @@ -34,7 +34,7 @@ void SMTP2V2::initialize(UART_HandleTypeDef* uart, uint8_t id, DMA_HandleTypeDef bool SMTP2V2::pump_ping() { int32_t isbusy; - return pump_get_state(&isbusy); + return pump_get_state(&isbusy) == 0; } int32_t SMTP2V2::pump_get_state(int32_t* isbusy) { size_t rxlen = 0; @@ -54,7 +54,7 @@ int32_t SMTP2V2::pump_get_capacitance(int32_t* capacitance) { return pump_get_st int32_t SMTP2V2::pump_get_pressure(int32_t* pressure) { return pump_get_state_as_int(kstate_pressure_ad, pressure); } int32_t SMTP2V2::pump_get_tip_state(int32_t* tipison) { return pump_get_state_as_int(kstate_tip_state, tipison); } int32_t SMTP2V2::pump_get_nl(int32_t* nl) { return pump_get_state_as_int(kstate_pump_pos_nl, nl); } -int32_t SMTP2V2::pump_set_io1_mode(int32_t mode) { +int32_t SMTP2V2::pump_set_io1_mode(int32_t mode) { // 0LLD输出高 1LLD输出低 2通用输出 ZLOGI(TAG, "pump_set_io1_mode %d", mode); return setstate(true, "/1u%d,%dR\r", kcfg_io1_mode, mode); } @@ -66,6 +66,12 @@ int32_t SMTP2V2::pump_set_io2_mode(int32_t mode) { ZLOGI(TAG, "pump_set_io2_mode %d", mode); return setstate(true, "/1u%d,%dR\r", kcfg_io2_mode, mode); } + +int32_t SMTP2V2::pump_set_pressure_data_stream_port(int32_t val /*0:无 1:232 3:CAN*/) { + ZLOGI(TAG, "pump_set_pressure_data_stream_port %d", val); + return setstate(true, "/1u%d,%dR\r", kcfg_pressure_data_port_channel, val); +} + int32_t SMTP2V2::pump_set_tip_size(TipSize_t size) { ZLOGI(TAG, "pump_set_tip_size %d", size); return setstate(true, "/1u%d,%dR\r", kcfg_tip_size, size); diff --git a/sdk/components/sensors/smtp2_v2/smtp2_v2.hpp b/sdk/components/sensors/smtp2_v2/smtp2_v2.hpp index ceedb37..2a21b1d 100644 --- a/sdk/components/sensors/smtp2_v2/smtp2_v2.hpp +++ b/sdk/components/sensors/smtp2_v2/smtp2_v2.hpp @@ -198,6 +198,7 @@ class SMTP2V2 { int32_t pump_set_tip_size(TipSize_t size); // Tip大小 0:1ml 1:200ul(max:250ul) 2:50ul(max:62ul) 3=20ul(max:40ul) int32_t pump_enable_temp_compensation(int32_t enable); // 0:关闭 1:开启 int32_t pump_set_back_clearance(int32_t val); + int32_t pump_set_pressure_data_stream_port(int32_t val /*0:无 1:232 3:CAN*/); /*********************************************************************************************************************** * STATE * diff --git a/usrc/subboards/subboard80_cliptip/subboard80_cliptip.cpp b/usrc/subboards/subboard80_cliptip/subboard80_cliptip.cpp index a079472..483824b 100644 --- a/usrc/subboards/subboard80_cliptip/subboard80_cliptip.cpp +++ b/usrc/subboards/subboard80_cliptip/subboard80_cliptip.cpp @@ -6,6 +6,7 @@ extern "C" { #include "public_service/public_service.hpp" #include "sdk/components/mini_servo_motor/feite_servo_motor.hpp" #include "sdk/components/mini_servo_motor/mini_servo_motor_ctrl_module.hpp" +#include "sdk/components/pipette_module/pipette_ctrl_module.hpp" #include "sdk/components/sensors/m3078/m3078_code_scaner.hpp" #include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp" @@ -48,57 +49,38 @@ void Subboard80Cliptip::initialize() { // &hardwarecfg); // GService::inst()->getZCanProtocolParser()->registerModule(&module); // } -#if 0 +#if 1 { - static TMC51X0 motor; - static PipetteModuleV2 module; - int subid = 2; - TMC51X0::cfg_t tmc5130cfg = { - .spi = &hspi1, - .csgpio = MOTOR1_CSN, - .ennPin = MOTOR1_ENN, + static TMC51X0 motor; + static PipetteModule module; + int subid = 2; + TMC51X0::cfg_t tmc5130cfg = { + .spi = &hspi1, + .csgpio = MOTOR1_CSN, + .ennPin = MOTOR1_ENN, }; motor.initialize(&tmc5130cfg); motor.setMotorShaft(false); static ZGPIO input[2]; input[0].initAsInput(MOTOR1_REFL, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, MOTOR1_REFL_MIRROR); input[1].initAsInput(MOTOR1_REFR, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, MOTOR1_REFR_MIRROR); - PipetteModuleV2::config_t cfg = {0}; - PipetteModuleV2::create_default_cfg(&cfg); - cfg.zm_shaft = MOTOR1_MOTOR_SHAFT; - cfg.zm_one_circle_pulse = MOTOR1_MOTOR_ONE_CIRCLE_PULSE; - cfg.zm_one_circle_pulse_denominator = MOTOR1_MOTOR_ONE_CIRCLE_PULSE_DENOMINATOR; - cfg.zm_ihold = MOTOR1_STEPMOTOR_IHOLD; - cfg.zm_irun = MOTOR1_STEPMOTOR_IRUN; - cfg.zm_iholddelay = MOTOR1_STEPMOTOR_IHOLDDELAY; - cfg.zm_iglobalscaler = MOTOR1_STEPMOTOR_IGLOBALSCALER; - cfg.zm_default_velocity = MOTOR1_MOTOR_DEFAULT_VELOCITY; - cfg.zm_min_d = MOTOR1_MIN_D; - cfg.zm_max_d = MOTOR1_MAX_D; - cfg.zm_run_to_zero_speed = MOTOR1_MOTOR_RUN_TO_ZERO_SPEED; - cfg.zm_look_zero_edge_speed = MOTOR1_MOTOR_LOOK_ZERO_EDGE_SPEED; - cfg.zm_vstart = MOTOR1_MOTOR_VSTART; - cfg.zm_a1 = MOTOR1_MOTOR_A1; - cfg.zm_amax = MOTOR1_MOTOR_AMAX; - cfg.zm_v1 = MOTOR1_MOTOR_V1; - cfg.zm_dmax = MOTOR1_MOTOR_DMAX; - cfg.zm_d1 = MOTOR1_MOTOR_D1; - cfg.zm_vstop = MOTOR1_MOTOR_VSTOP; - cfg.zm_tzerowait = MOTOR1_MOTOR_TZEROWAIT; - cfg.zm_enc_resolution = MOTOR1_ENC_RESOLUTION; - cfg.zm_enable_enc = MOTOR1_ENABLE_ENC_RESOLUTION; // - PipetteModuleV2::hardward_config_t hardwarecfg = { + PipetteModule::hardward_config_t hardwarecfg = { .uart = &huart2, .hdma_rx = hdma_usart2_rx, .hdma_tx = hdma_usart2_tx, + .uart232 = &huart3, + + .IO1 = PB1, + .IO1Mirror = true, + .zmotor = &motor, .zmotor_0point = &input[0], }; - module.initialize(getmoduleId(subid), &cfg, &hardwarecfg); + module.initialize(getmoduleId(subid), &hardwarecfg); GService::inst()->getZCanProtocolParser()->registerModule(&module); ZLOGI(TAG, "subboard80_cliptip pipette module initialized"); } diff --git a/usrc/subboards/subboard80_cliptip/subboard80_cliptip_board.c b/usrc/subboards/subboard80_cliptip/subboard80_cliptip_board.c index 51c2705..fa31444 100644 --- a/usrc/subboards/subboard80_cliptip/subboard80_cliptip_board.c +++ b/usrc/subboards/subboard80_cliptip/subboard80_cliptip_board.c @@ -174,9 +174,80 @@ static void UART4_Init() { huart4_enable = true; } +static void UART3_Init() { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + __HAL_RCC_USART3_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); + __HAL_RCC_DMA1_CLK_ENABLE(); + + huart3.Instance = USART3; + huart3.Init.BaudRate = 38400; + huart3.Init.WordLength = UART_WORDLENGTH_8B; + huart3.Init.StopBits = UART_STOPBITS_1; + huart3.Init.Parity = UART_PARITY_NONE; + huart3.Init.Mode = UART_MODE_TX_RX; + huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart3.Init.OverSampling = UART_OVERSAMPLING_16; + if (HAL_UART_Init(&huart3) != HAL_OK) { + Error_Handler(); + } + + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF7_USART3; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + hdma1_stream1.Instance = DMA1_Stream1; + hdma1_stream1.Init.Channel = DMA_CHANNEL_4; + hdma1_stream1.Init.Direction = DMA_PERIPH_TO_MEMORY; + hdma1_stream1.Init.PeriphInc = DMA_PINC_DISABLE; + hdma1_stream1.Init.MemInc = DMA_MINC_ENABLE; + hdma1_stream1.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + hdma1_stream1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + hdma1_stream1.Init.Mode = DMA_NORMAL; + hdma1_stream1.Init.Priority = DMA_PRIORITY_LOW; + hdma1_stream1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; + if (HAL_DMA_Init(&hdma1_stream1) != HAL_OK) { + Error_Handler(); + } + + __HAL_LINKDMA(&huart3, hdmarx, hdma1_stream1); + + hdma1_stream3.Instance = DMA1_Stream3; + hdma1_stream3.Init.Channel = DMA_CHANNEL_4; + hdma1_stream3.Init.Direction = DMA_MEMORY_TO_PERIPH; + hdma1_stream3.Init.PeriphInc = DMA_PINC_DISABLE; + hdma1_stream3.Init.MemInc = DMA_MINC_ENABLE; + hdma1_stream3.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + hdma1_stream3.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + hdma1_stream3.Init.Mode = DMA_NORMAL; + hdma1_stream3.Init.Priority = DMA_PRIORITY_LOW; + hdma1_stream3.Init.FIFOMode = DMA_FIFOMODE_DISABLE; + if (HAL_DMA_Init(&hdma1_stream3) != HAL_OK) { + Error_Handler(); + } + + __HAL_LINKDMA(&huart3, hdmatx, hdma1_stream3); + + hdma_usart3_rx = &hdma1_stream1; + hdma_usart3_tx = &hdma1_stream3; + hdma1_stream1_enable = true; + hdma1_stream3_enable = true; + + HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn); + + HAL_NVIC_SetPriority(DMA1_Stream3_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(DMA1_Stream3_IRQn); +} + void subboard80_cliptip_board_init() { common_hardware_init(); MX_SPI1_Init(); UART2_Init(); + UART3_Init(); UART4_Init(); }