diff --git a/sdk b/sdk index 9de9f89..e2554e9 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit 9de9f8940b0013d7a97db35e0acad9a4e072015a +Subproject commit e2554e9bad20de9474f430bf46571d6082ae50c1 diff --git a/usrc/main.cpp b/usrc/main.cpp index b6efddc..366ff27 100644 --- a/usrc/main.cpp +++ b/usrc/main.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include "board.h" #include "sdk\components\subcanmodule\zcancmder_subboard_initer.hpp" @@ -9,9 +11,9 @@ #include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.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\step_motor_ctrl_module\tmc51x0_motor.hpp" #include "sdk\components\tmc\ic\ztmc4361A.hpp" #include "sdk\components\tmc\ic\ztmc5130.hpp" -#include "sdk\components\step_motor_ctrl_module\tmc51x0_motor.hpp" #define TAG "main" using namespace iflytop; @@ -54,18 +56,50 @@ void nvs_init_cb() {} static void initsubmodule() { osDelay(1000); { - static TMC5130 g_motor; + static TMC5130 g_motor; static TMC51X0Motor g_stepMotorCtrlModule; - TMC5130::cfg_t cfg = { - .spi = &TMC_MOTOR_SPI, // - .csgpio = MOTOR0_CSN, // - .ennPin = MOTOR0_ENN, // - .spi_mode_select = MOTOR0_SPI_MODE_SELECT, // + TMC5130::cfg_t cfg = { + .spi = &TMC_MOTOR_SPI, // + .csgpio = MOTOR0_CSN, // + .ennPin = MOTOR0_ENN, // + .spi_mode_select = MOTOR0_SPI_MODE_SELECT, // }; g_motor.initialize(&cfg); ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion()); - g_motor.enable(true); + g_motor.enable(false); g_motor.setMotorShaft(false); + +#if 0 + // g_motor.setMotorShaft(true); + + // void writeInt(uint8_t address, int32_t value); + // int32_t readInt(uint8_t address); + + int32_t enc_const_integral = 12; + float enc_const_fractional = 0.8; + + int32_t setval = (enc_const_integral << 16) + enc_const_fractional * 10000; + setval = -setval; + ZLOGI(TAG, "setval:%d", setval); + g_motor.writeInt(TMC5130_ENC_CONST, setval); + g_motor.writeInt(TMC5130_ENCMODE, 0x1 << 10); + + g_motor.setIHOLD_IRUN(2, 6, 1000); + g_motor.setENCVAL(0); + g_motor.enable(true); + osDelay(100); + g_motor.setENCVAL(0); + // g_motor.moveBy(51200, 100000); + g_motor.moveBy(51200, 100000); + + while (true) { + int32_t enc = g_motor.readInt(TMC5130_XENC); + int32_t xactual = g_motor.readInt(TMC5130_XACTUAL); + ZLOGI(TAG, "enc:%d %d %d", enc, xactual, enc - xactual); + osDelay(1000); + } +#endif + static ZGPIO input[10]; input[0].initAsInput(MOTOR0_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); input[1].initAsInput(MOTOR0_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);