From a399a38dae81c1a83713b5bf4b371ef005330366 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Tue, 25 Jun 2024 20:21:08 +0800 Subject: [PATCH] update --- sdk | 2 +- usrc/main.cpp | 8 +- usrc/public_service/instance_init.hpp | 50 ------ .../subboard100_idcard_reader/pri_board.h | 31 ---- usrc/subboards/subboard10_hbot_v2/pri_board.h | 93 ++++++++++ .../subboard10_hbot_v2/subboard10_hbot_board_v2.c | 38 ++++ .../subboard10_hbot_v2/subboard10_hbot_board_v2.h | 12 ++ .../subboard10_hbot_v2/subboard10_hbot_v2.cpp | 194 +++++++++++++++++++++ .../subboard10_hbot_v2/subboard10_hbot_v2.hpp | 25 +++ usrc/subboards/subboard200_ext_tmc5160/pri_board.h | 3 - .../subboard200_ext_tmc5160.cpp | 5 +- .../subboard20_plate_clamp_case/pri_board.h | 8 - .../subboard70_incubation_turntable/pri_board.h | 3 - .../subboard70_incubation_turntable.cpp | 2 + usrc/subboards/subboard80_cliptip/pri_board.h | 3 - .../subboard90_optical_module/pri_board.h | 8 - 16 files changed, 375 insertions(+), 110 deletions(-) create mode 100644 usrc/subboards/subboard10_hbot_v2/pri_board.h create mode 100644 usrc/subboards/subboard10_hbot_v2/subboard10_hbot_board_v2.c create mode 100644 usrc/subboards/subboard10_hbot_v2/subboard10_hbot_board_v2.h create mode 100644 usrc/subboards/subboard10_hbot_v2/subboard10_hbot_v2.cpp create mode 100644 usrc/subboards/subboard10_hbot_v2/subboard10_hbot_v2.hpp diff --git a/sdk b/sdk index 7ab0d4a..375cae6 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit 7ab0d4ae00c6053d0a6aa35b1fa8fd26d027cfd1 +Subproject commit 375cae628409bb2773c208d2979b27f8e4b2de1f diff --git a/usrc/main.cpp b/usrc/main.cpp index 345c934..6c9ecc7 100644 --- a/usrc/main.cpp +++ b/usrc/main.cpp @@ -11,6 +11,8 @@ #include "subboards/subboard100_idcard_reader/subboard100_id_card_reader_board.h" #include "subboards/subboard10_hbot/subboard10_hbot.hpp" #include "subboards/subboard10_hbot/subboard10_hbot_board.h" +#include "subboards/subboard10_hbot_v2/subboard10_hbot_board_v2.h" +#include "subboards/subboard10_hbot_v2/subboard10_hbot_v2.hpp" #include "subboards/subboard200_ext_tmc5160/subboard200_ext_tmc5160.hpp" #include "subboards/subboard200_ext_tmc5160/subboard200_ext_tmc5160_board.h" #include "subboards/subboard20_plate_clamp_case/subboard20_plate_clamp_case.hpp" @@ -44,7 +46,8 @@ int32_t deviceId = 0; static void board_init() { switch (deviceId) { case 10: - subboard10_hbot_board_init(); + // subboard10_hbot_board_init(); + subboard10v2_hbot_board_init(); break; case 20: // 板夹仓 subboard20_plate_clamp_case_board_init(); @@ -85,7 +88,8 @@ static void board_post_init() { GService::inst()->initialize(); switch (deviceId) { case 10: - Subboard10Hbot::ins()->initialize(); + // Subboard10Hbot::ins()->initialize(); + Subboard10HbotV2::ins()->initialize(); break; case 20: Subboard20PlateClampCase::ins()->initialize(); diff --git a/usrc/public_service/instance_init.hpp b/usrc/public_service/instance_init.hpp index 39f1dd6..096120a 100644 --- a/usrc/public_service/instance_init.hpp +++ b/usrc/public_service/instance_init.hpp @@ -29,7 +29,6 @@ .spi = &TMC_MOTOR_SPI, \ .csgpio = MOTOR##MOTOR_INDEX##_CSN, \ .ennPin = MOTOR##MOTOR_INDEX##_ENN, \ - .spi_mode_select = MOTOR##MOTOR_INDEX##_SPI_MODE_SELECT, \ }; \ motor.initialize(&tmc5130cfg); \ motor.setMotorShaft(false); \ @@ -67,55 +66,6 @@ ZLOGI(TAG, "motor%d readic version %x", subid, motor.readICVersion()); \ } -#if 0 -#define TMC4361_MOTOR_INITER(MOTOR_INDEX, _id) \ - { \ - static TMC4361A motor; \ - static StepMotorCtrlModule module; \ - int subid = _id; \ - \ - TMC4361A::cfg_t motorcfg = { \ - .spi = &TMC_MOTOR_SPI, \ - .csgpio = MOTOR##MOTOR_INDEX##_CSN, \ - .resetPin = MOTOR##MOTOR_INDEX##_nRESET_IO, \ - .fREEZEPin = MOTOR##MOTOR_INDEX##_nFREEZE_IO, \ - .ennPin = MOTOR##MOTOR_INDEX##_ENN, \ - .driverIC_ennPin = MOTOR##MOTOR_INDEX##_SUB_IC_ENN_IO, \ - .driverIC_resetPin = PinNull, \ - }; \ - \ - motor.initialize(&motorcfg); \ - \ - static ZGPIO input[2]; \ - input[0].initAsInput(MOTOR##MOTOR_INDEX##_REFL, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, MOTOR##MOTOR_INDEX##_REFL_MIRROR); \ - input[1].initAsInput(MOTOR##MOTOR_INDEX##_REFR, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, MOTOR##MOTOR_INDEX##_REFR_MIRROR); \ - \ - StepMotorCtrlModule::config_t module_cfg = {0}; \ - StepMotorCtrlModule::create_default_cfg(module_cfg); \ - \ - module_cfg.motor_shaft = MOTOR##MOTOR_INDEX##_MOTOR_SHAFT; \ - module_cfg.motor_one_circle_pulse = MOTOR##MOTOR_INDEX##_MOTOR_ONE_CIRCLE_PULSE; \ - module_cfg.motor_one_circle_pulse_denominator = MOTOR##MOTOR_INDEX##_MOTOR_ONE_CIRCLE_PULSE_DENOMINATOR; \ - module_cfg.stepmotor_ihold = MOTOR##MOTOR_INDEX##_STEPMOTOR_IHOLD; \ - module_cfg.stepmotor_irun = MOTOR##MOTOR_INDEX##_STEPMOTOR_IRUN; \ - module_cfg.stepmotor_iholddelay = MOTOR##MOTOR_INDEX##_STEPMOTOR_IHOLDDELAY; \ - module_cfg.stepmotor_iglobalscaler = MOTOR##MOTOR_INDEX##_STEPMOTOR_IGLOBALSCALER; \ - module_cfg.motor_default_acc = MOTOR##MOTOR_INDEX##_MOTOR_DEFAULT_ACC; \ - module_cfg.motor_default_dec = MOTOR##MOTOR_INDEX##_MOTOR_DEFAULT_DEC; \ - module_cfg.motor_default_velocity = MOTOR##MOTOR_INDEX##_MOTOR_DEFAULT_VELOCITY; \ - module_cfg.min_d = MOTOR##MOTOR_INDEX##_MIN_D; \ - module_cfg.max_d = MOTOR##MOTOR_INDEX##_MAX_D; \ - module_cfg.motor_run_to_zero_speed = MOTOR##MOTOR_INDEX##_MOTOR_RUN_TO_ZERO_SPEED; \ - module_cfg.motor_run_to_zero_dec = MOTOR##MOTOR_INDEX##_MOTOR_RUN_TO_ZERO_DEC; \ - module_cfg.motor_look_zero_edge_speed = MOTOR##MOTOR_INDEX##_MOTOR_LOOK_ZERO_EDGE_SPEED; \ - module_cfg.motor_look_zero_edge_dec = MOTOR##MOTOR_INDEX##_MOTOR_LOOK_ZERO_EDGE_DEC; \ - \ - module.initialize(getmoduleId(subid), &motor, input, ZARRAY_SIZE(input), &module_cfg); \ - GService::inst()->getZCanProtocolParser()->registerModule(&module); \ - \ - ZLOGI(TAG, "motor%d readic version %x", subid, motor.readICVersion()); \ - } -#endif #define EXT_READ_IO_NUM 10 #define EXT_WRITE_IO_NUM 10 diff --git a/usrc/subboards/subboard100_idcard_reader/pri_board.h b/usrc/subboards/subboard100_idcard_reader/pri_board.h index a64d665..748b65f 100644 --- a/usrc/subboards/subboard100_idcard_reader/pri_board.h +++ b/usrc/subboards/subboard100_idcard_reader/pri_board.h @@ -25,34 +25,3 @@ #define EXT_OUTPUT_IO8 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ #define EXT_OUTPUT_IO9 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ -#define TMC_MOTOR_SPI hspi1 - -/*********************************************************************************************************************** - * 左右移动 * - ***********************************************************************************************************************/ - -// MOTOR1 -#define TMC_MOTOR1_CHANNEL 1 -#define TMC_MOTOR1_SPI_SELECT1_IO PA4 -#define TMC_MOTOR1_nFREEZE_IO PC2 -#define TMC_MOTOR1_nRESET_IO PB3 -#define TMC_MOTOR1_SUB_IC_ENN_IO PC3 -#define TMC_MOTOR1_ENN_IO // unused - -// MOTOR2 -#define TMC_MOTOR2_CHANNEL 2 -#define TMC_MOTOR2_SPI_SELECT1_IO PA8 -#define TMC_MOTOR2_nFREEZE_IO PC6 -#define TMC_MOTOR2_nRESET_IO PB2 -#define TMC_MOTOR2_SUB_IC_ENN_IO PC7 -#define TMC_MOTOR2_ENN_IO // unused - -#define ARM_X_ZERO PD0 -#define ARM_X_LIMIT PD1 -#define ARM_Y_ZERO PD2 -#define ARM_Y_LIMIT PD3 - -#define ARM_SENSOR5_GPIO PD4 -#define ARM_SENSOR6_GPIO PD5 -#define ARM_SENSOR7_GPIO PD6 -#define ARM_SENSOR8_GPIO PD7 \ No newline at end of file diff --git a/usrc/subboards/subboard10_hbot_v2/pri_board.h b/usrc/subboards/subboard10_hbot_v2/pri_board.h new file mode 100644 index 0000000..c5727cd --- /dev/null +++ b/usrc/subboards/subboard10_hbot_v2/pri_board.h @@ -0,0 +1,93 @@ +#pragma once +/*********************************************************************************************************************** + * 板载扩展IO * + ***********************************************************************************************************************/ +#define EXT_INPUT_IO0 PD0, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true +#define EXT_INPUT_IO1 PD1, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true +#define EXT_INPUT_IO2 PD2, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true +#define EXT_INPUT_IO3 PD3, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true +#define EXT_INPUT_IO4 PD10, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true +#define EXT_INPUT_IO5 PD11, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true +#define EXT_INPUT_IO6 PinNull, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true +#define EXT_INPUT_IO7 PinNull, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true +#define EXT_INPUT_IO8 PinNull, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true +#define EXT_INPUT_IO9 PinNull, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true + +#define EXT_OUTPUT_IO0 PD9, ZGPIO::kMode_nopull, true /*mirror*/, false /*init val*/ +#define EXT_OUTPUT_IO1 PD10, ZGPIO::kMode_nopull, true /*mirror*/, false /*init val*/ +#define EXT_OUTPUT_IO2 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ +#define EXT_OUTPUT_IO3 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ +#define EXT_OUTPUT_IO4 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ +#define EXT_OUTPUT_IO5 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ +#define EXT_OUTPUT_IO6 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ +#define EXT_OUTPUT_IO7 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ +#define EXT_OUTPUT_IO8 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ +#define EXT_OUTPUT_IO9 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ + +#define TMC_MOTOR_SPI hspi1 + +/*********************************************************************************************************************** + * 电机1 * + ***********************************************************************************************************************/ + +#define MOTOR1_CSN PA4 +#define MOTOR1_ENN PB7 + +#define MOTOR1_REFL PD0 +#define MOTOR1_REFR PinNull +#define MOTOR1_REFL_MIRROR true +#define MOTOR1_REFR_MIRROR true + +#define MOTOR1_MOTOR_SHAFT true +#define MOTOR1_MOTOR_ONE_CIRCLE_PULSE 60 +#define MOTOR1_MOTOR_ONE_CIRCLE_PULSE_DENOMINATOR 1 +#define MOTOR1_STEPMOTOR_IHOLD 1 +#define MOTOR1_STEPMOTOR_IRUN 5 +#define MOTOR1_STEPMOTOR_IHOLDDELAY 100 +#define MOTOR1_STEPMOTOR_IGLOBALSCALER 0 +#define MOTOR1_MOTOR_DEFAULT_VELOCITY 500 +#define MOTOR1_MIN_D 0 +#define MOTOR1_MAX_D 0 +#define MOTOR1_MOTOR_RUN_TO_ZERO_SPEED 400 +#define MOTOR1_MOTOR_LOOK_ZERO_EDGE_SPEED 50 +#define MOTOR1_MOTOR_VSTART TMC5130_DEFAULT__MOTOR_VSTART +#define MOTOR1_MOTOR_A1 TMC5130_DEFAULT__MOTOR_A1 +#define MOTOR1_MOTOR_AMAX 300 +#define MOTOR1_MOTOR_V1 TMC5130_DEFAULT__MOTOR_V1 +#define MOTOR1_MOTOR_DMAX 300 +#define MOTOR1_MOTOR_D1 TMC5130_DEFAULT__MOTOR_D1 +#define MOTOR1_MOTOR_VSTOP TMC5130_DEFAULT__MOTOR_VSTOP +#define MOTOR1_MOTOR_TZEROWAIT TMC5130_DEFAULT__MOTOR_TZEROWAIT + +/*********************************************************************************************************************** + * 电机2 * + ***********************************************************************************************************************/ + +#define MOTOR2_CSN PC4 +#define MOTOR2_ENN PE13 + +#define MOTOR2_REFL PinNull +#define MOTOR2_REFR PinNull +#define MOTOR2_REFL_MIRROR true +#define MOTOR2_REFR_MIRROR true + +#define MOTOR2_MOTOR_SHAFT true +#define MOTOR2_MOTOR_ONE_CIRCLE_PULSE 80 +#define MOTOR2_MOTOR_ONE_CIRCLE_PULSE_DENOMINATOR 1 +#define MOTOR2_STEPMOTOR_IHOLD 1 +#define MOTOR2_STEPMOTOR_IRUN 5 +#define MOTOR2_STEPMOTOR_IHOLDDELAY 100 +#define MOTOR2_STEPMOTOR_IGLOBALSCALER 0 +#define MOTOR2_MOTOR_DEFAULT_VELOCITY 500 +#define MOTOR2_MIN_D 0 +#define MOTOR2_MAX_D 0 +#define MOTOR2_MOTOR_RUN_TO_ZERO_SPEED 300 +#define MOTOR2_MOTOR_LOOK_ZERO_EDGE_SPEED 50 +#define MOTOR2_MOTOR_VSTART TMC5130_DEFAULT__MOTOR_VSTART +#define MOTOR2_MOTOR_A1 TMC5130_DEFAULT__MOTOR_A1 +#define MOTOR2_MOTOR_AMAX 300 +#define MOTOR2_MOTOR_V1 TMC5130_DEFAULT__MOTOR_V1 +#define MOTOR2_MOTOR_DMAX 300 +#define MOTOR2_MOTOR_D1 TMC5130_DEFAULT__MOTOR_D1 +#define MOTOR2_MOTOR_VSTOP TMC5130_DEFAULT__MOTOR_VSTOP +#define MOTOR2_MOTOR_TZEROWAIT TMC5130_DEFAULT__MOTOR_TZEROWAIT diff --git a/usrc/subboards/subboard10_hbot_v2/subboard10_hbot_board_v2.c b/usrc/subboards/subboard10_hbot_v2/subboard10_hbot_board_v2.c new file mode 100644 index 0000000..6fbc99f --- /dev/null +++ b/usrc/subboards/subboard10_hbot_v2/subboard10_hbot_board_v2.c @@ -0,0 +1,38 @@ +#include "main.h" +#include "public_service/public_service.h" + +/* SPI1 init function */ +static void MX_SPI1_Init(void) { + __HAL_RCC_SPI1_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + + hspi1.Instance = SPI1; + hspi1.Init.Mode = SPI_MODE_MASTER; + hspi1.Init.Direction = SPI_DIRECTION_2LINES; + hspi1.Init.DataSize = SPI_DATASIZE_8BIT; + hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi1.Init.NSS = SPI_NSS_SOFT; + hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; + hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi1.Init.TIMode = SPI_TIMODE_DISABLE; + hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + hspi1.Init.CRCPolynomial = 10; + if (HAL_SPI_Init(&hspi1) != HAL_OK) { + Error_Handler(); + } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + hspi1_enable = true; +} + +void subboard10v2_hbot_board_init() { + common_hardware_init(); + MX_SPI1_Init(); +} diff --git a/usrc/subboards/subboard10_hbot_v2/subboard10_hbot_board_v2.h b/usrc/subboards/subboard10_hbot_v2/subboard10_hbot_board_v2.h new file mode 100644 index 0000000..666a2f6 --- /dev/null +++ b/usrc/subboards/subboard10_hbot_v2/subboard10_hbot_board_v2.h @@ -0,0 +1,12 @@ +#pragma once +#include "main.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void subboard10v2_hbot_board_init(); + +#ifdef __cplusplus +} +#endif diff --git a/usrc/subboards/subboard10_hbot_v2/subboard10_hbot_v2.cpp b/usrc/subboards/subboard10_hbot_v2/subboard10_hbot_v2.cpp new file mode 100644 index 0000000..7cdd1c3 --- /dev/null +++ b/usrc/subboards/subboard10_hbot_v2/subboard10_hbot_v2.cpp @@ -0,0 +1,194 @@ +#include "subboard10_hbot_v2.hpp" +extern "C" { +#include "subboard10_hbot_board_v2.h" +} +#include "pri_board.h" +#include "public_service/instance_init.hpp" +#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/sensors/m3078/m3078_code_scaner.hpp" +#include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp" +#include "sdk/components/tmc/ic/ztmc4361A.hpp" +#include "sdk\components\pipette_module\pipette_ctrl_module_v2.hpp" +#include "sdk\components\xy_robot_ctrl_module\xy_robot_ctrl_module.hpp" + +#define TAG "Subboard10HbotV2" + +using namespace iflytop; + +/*********************************************************************************************************************** + * IMPL * + ***********************************************************************************************************************/ +void Subboard10HbotV2::initialize() { + // IO_INIT(); + GService::inst()->getZCanProtocolParser()->registerModule(this); + + // PB12 + + static ZGPIO motorPowerEnPin; + static ZGPIO motor1ENNPin; + static ZGPIO motor2ENNPin; + + static ZGPIO TMC51X0_1_SPI_MODE; + static ZGPIO TMC51X0_1_SD_MODE; + static ZGPIO TMC51X0_2_SPI_MODE; + static ZGPIO TMC51X0_2_SD_MODE; + + motor1ENNPin.initAsOutput(MOTOR1_ENN, iflytop::ZGPIO::kMode_nopull, false, true); + motor2ENNPin.initAsOutput(MOTOR2_ENN, iflytop::ZGPIO::kMode_nopull, false, true); + motorPowerEnPin.initAsOutput(PB12, iflytop::ZGPIO::kMode_nopull, true, true); + + osDelay(100); + + // #define MOTOR1_CSN PA4 + // #define MOTOR1_ENN PB7 + // #define MOTOR1_SPI_MODE_SELECT PB4 + // #define MOTOR1_nFREEZE_IO PE12 + // #define MOTOR1_nRESET_IO PinNull + + { + { + static TMC51X0 motor; + static StepMotorCtrlModule module; + int subid = 1; + TMC51X0::cfg_t tmc5130cfg = { + .spi = &hspi1, + .csgpio = PA4, + .ennPin = PB7 + }; + motor.initialize(&tmc5130cfg); + motor.setIHOLD_IRUN(1, 3, 100); + motor.enable(true); + motor.rotate(800); + // motor.setMotorShaft(false); + // static ZGPIO input[2]; + // input[0].initAsInput(PD0, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + // input[1].initAsInput(PD1, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + // StepMotorCtrlModule::config_t stepcfg = {0}; + // StepMotorCtrlModule::create_default_cfg(stepcfg); + // stepcfg.motor_shaft = false; + // stepcfg.motor_one_circle_pulse = 10000; + // stepcfg.motor_one_circle_pulse_denominator = 1; + // stepcfg.stepmotor_ihold = 5; + // stepcfg.stepmotor_irun = 20; + // stepcfg.stepmotor_iholddelay = 10; + // stepcfg.stepmotor_iglobalscaler = 0; + // stepcfg.motor_default_velocity = 600; + // stepcfg.min_d = 0; + // stepcfg.max_d = 0; + // stepcfg.motor_run_to_zero_speed = 300; + // stepcfg.motor_look_zero_edge_speed = 200; + // stepcfg.motor_vstart = 100; + // stepcfg.motor_a1 = 50; + // stepcfg.motor_amax = 100; + // stepcfg.motor_v1 = 300; + // stepcfg.motor_dmax = 100; + // stepcfg.motor_d1 = 50; + // stepcfg.motor_vstop = 100; + // stepcfg.motor_tzerowait = 0; + // module.initialize(getmoduleId(subid), &motor, input, ((int32_t)(sizeof(input) / sizeof(input[0]))), &stepcfg); + // GService::inst()->getZCanProtocolParser()->registerModule(&module); + if (g_enable_log) { + zos_log( + "%08lu INFO [%-10s] " + "motor%d readic version %x" + "\n", + zchip_clock_get_ticket(), "Subboard200ExtTmc5160", subid, motor.readICVersion()); + }; + } + } + // { TMC5130_MOTOR_INITER(2, 2); } + +#if 0 + /*********************************************************************************************************************** + * ID1 * + ***********************************************************************************************************************/ + static XYRobotCtrlModule xyRobotCtrlModule; + static TMC4361A motora; // 1 + static TMC4361A motorb; // 2 + { + TMC4361A::cfg_t cfg = { + .spi = &TMC_MOTOR_SPI, // + .csgpio = TMC_MOTOR1_SPI_SELECT1_IO, // + .resetPin = TMC_MOTOR1_nRESET_IO, // + .fREEZEPin = TMC_MOTOR1_nFREEZE_IO, // + .ennPin = PinNull, // + .driverIC_ennPin = TMC_MOTOR1_SUB_IC_ENN_IO, // + .driverIC_resetPin = PinNull, // + }; + motora.initialize(&cfg); + motora.setMotorShaft(false); + motora.setGlobalScale(31); + ZLOGI(TAG, "motora initialize TMC4361A:%x DriverIC:%x", motora.readICVersion(), motora.driverIC_readICVersion()); + } + + { + TMC4361A::cfg_t cfg = { + .spi = &TMC_MOTOR_SPI, // + .csgpio = TMC_MOTOR2_SPI_SELECT1_IO, // + .resetPin = TMC_MOTOR2_nRESET_IO, // + .fREEZEPin = TMC_MOTOR2_nFREEZE_IO, // + .ennPin = PinNull, // + .driverIC_ennPin = TMC_MOTOR2_SUB_IC_ENN_IO, // + .driverIC_resetPin = PinNull, // + }; + motorb.initialize(&cfg); + motorb.setMotorShaft(false); + motorb.setGlobalScale(31); + ZLOGI(TAG, "motorb initialize TMC4361A:%x DriverIC:%x", motorb.readICVersion(), motorb.driverIC_readICVersion()); + } + + motora.setAcceleration(300); + motora.setDeceleration(300); + motora.setIHOLD_IRUN(0, 4, 10); + + motorb.setAcceleration(300); + motorb.setDeceleration(300); + motorb.setIHOLD_IRUN(0, 4, 10); + + motora.rotate(0); + motorb.rotate(0); + + /******************************************************************************* + * zcanXYRobotCtrlModule * + *******************************************************************************/ + static ZGPIO input[4]; + input[0].initAsInput(ARM_X_ZERO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + input[1].initAsInput(ARM_Y_ZERO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + input[2].initAsInput(ARM_X_LIMIT, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + input[3].initAsInput(ARM_Y_LIMIT, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + + static XYRobotCtrlModule::config_t xy_defaultcfg; + XYRobotCtrlModule::create_default_cfg(xy_defaultcfg); + xy_defaultcfg.configInited = true; + xy_defaultcfg.robot_type = 1; + + xy_defaultcfg.robot_type = XYRobotCtrlModule::khbot; + xy_defaultcfg.x_shaft = 0; + xy_defaultcfg.y_shaft = 1; + xy_defaultcfg.ihold = 3; + xy_defaultcfg.irun = 31; + xy_defaultcfg.iholddelay = 100; + xy_defaultcfg.distance_scale = 7344; + xy_defaultcfg.shift_x = 0; + xy_defaultcfg.shift_y = 0; + + // limit + xy_defaultcfg.acc = 400; + xy_defaultcfg.dec = 400; + xy_defaultcfg.min_x = 0; + xy_defaultcfg.max_x = 0; + xy_defaultcfg.min_y = 0; + xy_defaultcfg.max_y = 0; + xy_defaultcfg.default_velocity = 300; + + xy_defaultcfg.run_to_zero_speed = 40; + xy_defaultcfg.look_zero_edge_speed = 10; + + xyRobotCtrlModule.initialize(getmoduleId(1), &motora, &motorb, &input[0], 4, xy_defaultcfg); + + GService::inst()->registerModule(&xyRobotCtrlModule); + +#endif +} diff --git a/usrc/subboards/subboard10_hbot_v2/subboard10_hbot_v2.hpp b/usrc/subboards/subboard10_hbot_v2/subboard10_hbot_v2.hpp new file mode 100644 index 0000000..0976313 --- /dev/null +++ b/usrc/subboards/subboard10_hbot_v2/subboard10_hbot_v2.hpp @@ -0,0 +1,25 @@ +#include +#include + +// +#include "configs/device_id_mgr.hpp" +#include "sdk/chip/chip.hpp" +#include "sdk/os/zos.hpp" +// +#include "sdk\components\step_motor_ctrl_module\step_motor_ctrl_module.hpp" +#include "sdk\components\tmc\ic\ztmc5130.hpp" +#include "public_service/public_service.hpp" + +namespace iflytop { +class Subboard10HbotV2 : public ExtBoardImpl { + public: + static Subboard10HbotV2 *ins() { + static Subboard10HbotV2 instance; + return &instance; + } + + void initialize(); +}; + +} // namespace iflytop + diff --git a/usrc/subboards/subboard200_ext_tmc5160/pri_board.h b/usrc/subboards/subboard200_ext_tmc5160/pri_board.h index d196f02..448a0e2 100644 --- a/usrc/subboards/subboard200_ext_tmc5160/pri_board.h +++ b/usrc/subboards/subboard200_ext_tmc5160/pri_board.h @@ -39,9 +39,6 @@ #define MOTOR1_CSN PA4 #define MOTOR1_ENN PB7 #define MOTOR1_SPI_MODE_SELECT PB4 -#define MOTOR1_nFREEZE_IO PE12 -#define MOTOR1_nRESET_IO PinNull -#define MOTOR1_SUB_IC_ENN_IO PE11 #define MOTOR1_REFL PD0 #define MOTOR1_REFR PD1 diff --git a/usrc/subboards/subboard200_ext_tmc5160/subboard200_ext_tmc5160.cpp b/usrc/subboards/subboard200_ext_tmc5160/subboard200_ext_tmc5160.cpp index afd6825..d2ad977 100644 --- a/usrc/subboards/subboard200_ext_tmc5160/subboard200_ext_tmc5160.cpp +++ b/usrc/subboards/subboard200_ext_tmc5160/subboard200_ext_tmc5160.cpp @@ -28,8 +28,11 @@ void Subboard200ExtTmc5160::initialize() { /*********************************************************************************************************************** * ID1 * ***********************************************************************************************************************/ - { TMC5130_MOTOR_INITER(1, 1); } + static ZGPIO TMC51X0_1_SD_MODE; + TMC51X0_1_SD_MODE.initAsOutput(PB4, iflytop::ZGPIO::kMode_nopull, false, false); + + { TMC5130_MOTOR_INITER(1, 1); } #endif } diff --git a/usrc/subboards/subboard20_plate_clamp_case/pri_board.h b/usrc/subboards/subboard20_plate_clamp_case/pri_board.h index 23b0726..051dfd6 100644 --- a/usrc/subboards/subboard20_plate_clamp_case/pri_board.h +++ b/usrc/subboards/subboard20_plate_clamp_case/pri_board.h @@ -33,10 +33,6 @@ #define MOTOR1_CSN PA4 #define MOTOR1_ENN PD5 -#define MOTOR1_SPI_MODE_SELECT PinNull -#define MOTOR1_nFREEZE_IO PinNull -#define MOTOR1_nRESET_IO PinNull -#define MOTOR1_SUB_IC_ENN_IO PinNull #define MOTOR1_REFL PD0 #define MOTOR1_REFR PD8 @@ -70,10 +66,6 @@ #define MOTOR2_CSN PB1 #define MOTOR2_ENN PD4 -#define MOTOR2_SPI_MODE_SELECT PinNull -#define MOTOR2_nFREEZE_IO PinNull -#define MOTOR2_nRESET_IO PinNull -#define MOTOR2_SUB_IC_ENN_IO PinNull #define MOTOR2_REFL PD2 #define MOTOR2_REFR PD9 diff --git a/usrc/subboards/subboard70_incubation_turntable/pri_board.h b/usrc/subboards/subboard70_incubation_turntable/pri_board.h index 2bf8efe..600590f 100644 --- a/usrc/subboards/subboard70_incubation_turntable/pri_board.h +++ b/usrc/subboards/subboard70_incubation_turntable/pri_board.h @@ -39,9 +39,6 @@ #define MOTOR1_CSN PA4 #define MOTOR1_ENN PB7 #define MOTOR1_SPI_MODE_SELECT PB4 -#define MOTOR1_nFREEZE_IO PE12 -#define MOTOR1_nRESET_IO PinNull -#define MOTOR1_SUB_IC_ENN_IO PE11 #define MOTOR1_REFL PD0 #define MOTOR1_REFR PD1 diff --git a/usrc/subboards/subboard70_incubation_turntable/subboard70_incubation_turntable.cpp b/usrc/subboards/subboard70_incubation_turntable/subboard70_incubation_turntable.cpp index e506375..16a5e2d 100644 --- a/usrc/subboards/subboard70_incubation_turntable/subboard70_incubation_turntable.cpp +++ b/usrc/subboards/subboard70_incubation_turntable/subboard70_incubation_turntable.cpp @@ -17,6 +17,8 @@ void Subboard70IncubationTurntable::initialize() { IO_INIT(); GService::inst()->getZCanProtocolParser()->registerModule(this); + static ZGPIO TMC51X0_1_SD_MODE; + TMC51X0_1_SD_MODE.initAsOutput(PB4, iflytop::ZGPIO::kMode_nopull, false, false); #if 1 TMC5130_MOTOR_INITER(/*motorid*/ 1, /*moduleid*/ 1); #endif diff --git a/usrc/subboards/subboard80_cliptip/pri_board.h b/usrc/subboards/subboard80_cliptip/pri_board.h index b0d0481..e5a73fb 100644 --- a/usrc/subboards/subboard80_cliptip/pri_board.h +++ b/usrc/subboards/subboard80_cliptip/pri_board.h @@ -34,9 +34,6 @@ #define MOTOR1_CSN PA4 #define MOTOR1_ENN PD0 #define MOTOR1_SPI_MODE_SELECT PinNull -#define MOTOR1_nFREEZE_IO PinNull -#define MOTOR1_nRESET_IO PinNull -#define MOTOR1_SUB_IC_ENN_IO PinNull #define MOTOR1_REFL PD2 #define MOTOR1_REFR PD1 diff --git a/usrc/subboards/subboard90_optical_module/pri_board.h b/usrc/subboards/subboard90_optical_module/pri_board.h index 52b312c..aae8771 100644 --- a/usrc/subboards/subboard90_optical_module/pri_board.h +++ b/usrc/subboards/subboard90_optical_module/pri_board.h @@ -34,10 +34,6 @@ #define MOTOR1_CSN PA4 #define MOTOR1_ENN PD5 -#define MOTOR1_SPI_MODE_SELECT PinNull -#define MOTOR1_nFREEZE_IO PinNull -#define MOTOR1_nRESET_IO PinNull -#define MOTOR1_SUB_IC_ENN_IO PinNull #define MOTOR1_REFL PD0 #define MOTOR1_REFR PinNull @@ -94,10 +90,6 @@ #define MOTOR2_CSN PB1 #define MOTOR2_ENN PD4 -#define MOTOR2_SPI_MODE_SELECT PinNull -#define MOTOR2_nFREEZE_IO PinNull -#define MOTOR2_nRESET_IO PinNull -#define MOTOR2_SUB_IC_ENN_IO PinNull #define MOTOR2_REFL PD2 #define MOTOR2_REFR PD8