#include #include #include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp" #include "sdk/os/zos.hpp" #include "sdk\components\flash\zsimple_flash.hpp" #include "sdk\components\mini_servo_motor\feite_servo_motor.hpp" #include "sdk\components\tmc\ic\ztmc4361A.hpp" #include "sdk\components\xy_robot_ctrl_module\xy_robot_ctrl_module.hpp" #include "sdk\components\zcancmder\zcanreceiver.hpp" #include "sdk\components\zcancmder_module\zcan_basic_order_module.hpp" #include "sdk\components\zprotocols\zcancmder_v2\protocol_parser.hpp" // #include "sdk\components\flash\znvs.hpp" // #define TAG "main" using namespace iflytop; using namespace std; extern void umain(); extern "C" { void StartDefaultTask(void const* argument) { umain(); } } #define TMC_MOTOR_SPI hspi1 static TMC4361A motora; static TMC4361A motorb; static ZCanCmder zcanCmder; static StepMotorCtrlModule stepMotorCtrlModule; static XYRobotCtrlModule xyRobotCtrlModule; static ZIProtocolParser g_ziProtocolParser; #define XYRobotCtrlModule_1_FLASH_MARK "XYRobotCtrlModule_1" void umain() { chip_cfg_t chipcfg; chipcfg.us_dleay_tim = &DELAY_US_TIMER; chipcfg.tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER; chipcfg.huart = &DEBUG_UART; chipcfg.debuglight = DEBUG_LIGHT_GPIO; chip_init(&chipcfg); zos_cfg_t zoscfg; zos_init(&zoscfg); ZLOGI(TAG, "boardid:%d moduleid:%d", BOARD_ID, MODULE_ID); /******************************************************************************* * NVSINIT * *******************************************************************************/ ZNVS::ins().initialize(IFLYTOP_NVS_CONFIG_FLASH_SECTOR); { static I_XYRobotCtrlModule::flash_config_t cfg; XYRobotCtrlModule::create_default_cfg(cfg); ZNVS::ins().alloc_config(XYRobotCtrlModule_1_FLASH_MARK, (uint8_t*)&cfg, sizeof(cfg)); } ZNVS::ins().init_config(); osDelay(1000); { 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); ZLOGI(TAG, "motora initialize TMC4361A:%x DriverIC:%x", motora.readICVersion(), motora.readSubICVersion()); } { 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); ZLOGI(TAG, "motorb initialize TMC4361A:%x DriverIC:%x", motorb.readICVersion(), motorb.readSubICVersion()); } motora.setAcceleration(300); motora.setDeceleration(300); motora.setIHOLD_IRUN(0, 2, 10); motorb.setAcceleration(300); motorb.setDeceleration(300); motorb.setIHOLD_IRUN(0, 2, 10); motora.rotate(0); motorb.rotate(0); auto zcanCmder_cfg = zcanCmder.createCFG(BOARD_ID); zcanCmder.init(zcanCmder_cfg); /******************************************************************************* * zcanBasicOrderModule * *******************************************************************************/ #if 0 zcanBasicOrderModule.reg_set_io(1, [](bool val) { ZLOGI(TAG, "write io 1:%d", val); }); zcanBasicOrderModule.reg_read_io(1, []() { ZLOGI(TAG, "read io 1"); return 1; }); zcanBasicOrderModule.reg_read_adc(1, []() { ZLOGI(TAG, "read adc 1"); return 123; }); #endif /******************************************************************************* * zcanXYRobotCtrlModule * *******************************************************************************/ ZGPIO input[8]; input[0].initAsInput(ARM_SENSOR1_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); input[1].initAsInput(ARM_SENSOR2_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); input[2].initAsInput(ARM_SENSOR3_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); input[3].initAsInput(ARM_SENSOR4_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); input[4].initAsInput(ARM_SENSOR5_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); input[5].initAsInput(ARM_SENSOR6_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); input[6].initAsInput(ARM_SENSOR7_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); input[7].initAsInput(ARM_SENSOR8_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); xyRobotCtrlModule.initialize(BOARD_ID, &motora, &motorb, &input[0], 8, XYRobotCtrlModule_1_FLASH_MARK); xyRobotCtrlModule.dumpcfg(); // zcanXYRobotCtrlModule.initialize(&zcanCmder, MODULE_ID, &xyRobotCtrlModule); g_ziProtocolParser.initialize(&zcanCmder); g_ziProtocolParser.registerModule(&xyRobotCtrlModule); while (true) { OSDefaultSchduler::getInstance()->loop(); zcanCmder.loop(); } }