|
@ -3,7 +3,7 @@ |
|
|
#include "i2c.h"
|
|
|
#include "i2c.h"
|
|
|
using namespace iflytop; |
|
|
using namespace iflytop; |
|
|
#define TAG "hardware"
|
|
|
#define TAG "hardware"
|
|
|
#define ENABLE_CAN 1
|
|
|
|
|
|
|
|
|
#define ENABLE_CAN 0
|
|
|
|
|
|
|
|
|
int32_t Hardware::port_tmc4361_get_version(uint8_t channel) { |
|
|
int32_t Hardware::port_tmc4361_get_version(uint8_t channel) { |
|
|
int value; |
|
|
int value; |
|
@ -56,6 +56,7 @@ void Hardware::hardwareinit() { |
|
|
// 4361初始化
|
|
|
// 4361初始化
|
|
|
TMC4361AImpl::TMC4361AConfig_t *tmc4361aconfig = TMC4361AImpl::createDeafultTMC4361AConfig(); |
|
|
TMC4361AImpl::TMC4361AConfig_t *tmc4361aconfig = TMC4361AImpl::createDeafultTMC4361AConfig(); |
|
|
tmc4361aconfig->encoder_config.diff_enc_in_disable = false; |
|
|
tmc4361aconfig->encoder_config.diff_enc_in_disable = false; |
|
|
|
|
|
tmc4361aconfig->encoder_config.invert_enc_dir = true; // 如果编码器方向和期望方向相反,设置为true
|
|
|
tmc4361aconfig->encoder_config.enc_in_res = 4000; |
|
|
tmc4361aconfig->encoder_config.enc_in_res = 4000; |
|
|
tmc4361aconfig->close_loop_config.enable_closed_loop = false; |
|
|
tmc4361aconfig->close_loop_config.enable_closed_loop = false; |
|
|
|
|
|
|
|
@ -63,27 +64,29 @@ void Hardware::hardwareinit() { |
|
|
tmc4361motor1.setMaximumAcceleration(300000); |
|
|
tmc4361motor1.setMaximumAcceleration(300000); |
|
|
tmc4361motor1.setMaximumDeceleration(300000); |
|
|
tmc4361motor1.setMaximumDeceleration(300000); |
|
|
|
|
|
|
|
|
// 2160初始化
|
|
|
|
|
|
tmc2160motor1.initialize(&m_deviceIoService, &tmc4361motor1, MOTOR_1_TMC2160_CHANNEL); |
|
|
|
|
|
tmc2160motor1.setMaximumCurrent(3); |
|
|
|
|
|
|
|
|
|
|
|
HAL_Delay(100); |
|
|
HAL_Delay(100); |
|
|
// 使能电机
|
|
|
// 使能电机
|
|
|
tmc2160motor1.enableIC(true); |
|
|
|
|
|
tmc4361motor1.enableIC(true); |
|
|
tmc4361motor1.enableIC(true); |
|
|
/**
|
|
|
/**
|
|
|
* @brief 通过读取Version寄存器来判断芯片是否正常 |
|
|
* @brief 通过读取Version寄存器来判断芯片是否正常 |
|
|
*/ |
|
|
*/ |
|
|
int32_t ic4361Version = tmc4361motor1.readICVersion(); |
|
|
int32_t ic4361Version = tmc4361motor1.readICVersion(); |
|
|
int32_t ic2160Version = tmc2160motor1.readICVersion(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32_t ic2160Version = tmc4361motor1.read2160ICVersion(); |
|
|
ZLOGI(TAG, "TMC4361Version:%x TMC2160VERSION:%x", ic4361Version, ic2160Version); |
|
|
ZLOGI(TAG, "TMC4361Version:%x TMC2160VERSION:%x", ic4361Version, ic2160Version); |
|
|
if (ic4361Version != 2 || ic2160Version != 30) { |
|
|
|
|
|
|
|
|
if (ic4361Version != 2) { |
|
|
ZLOGE(TAG, "TMC4361 or TMC2160 is not normal"); |
|
|
ZLOGE(TAG, "TMC4361 or TMC2160 is not normal"); |
|
|
} |
|
|
} |
|
|
// 期望 4361Version:2 ic2160Version:30
|
|
|
// 期望 4361Version:2 ic2160Version:30
|
|
|
|
|
|
// tmc4361motor1.stop();
|
|
|
|
|
|
#if 1
|
|
|
|
|
|
// 测试编码器方向
|
|
|
|
|
|
tmc4361motor1.rotate(-300000); |
|
|
|
|
|
while (true) { |
|
|
|
|
|
HAL_Delay(100); |
|
|
|
|
|
ZLOGI(TAG, "TMC4361A: XACTUAL:%d ENC_POS:%d DIFF:%d", tmc4361motor1.getXACTUAL(), tmc4361motor1.getENC_POS(), tmc4361motor1.getENC_POS_DEV()); |
|
|
|
|
|
} |
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
tmc4361motor1.rotate(300000); |
|
|
|
|
|
#endif
|
|
|
#endif
|
|
|
/*******************************************************************************
|
|
|
/*******************************************************************************
|
|
|
* 风扇初始化 * |
|
|
* 风扇初始化 * |
|
|