|
|
@ -647,9 +647,71 @@ int32_t TMC51X0Motor::motor_easy_move_to_zero(int32_t direction) { |
|
|
|
return err::koperation_not_support; |
|
|
|
} |
|
|
|
} |
|
|
|
int32_t TMC51X0Motor::motor_read_enc_val(int32_t* enc_val) {} |
|
|
|
int32_t TMC51X0Motor::motor_set_enc_resolution(int32_t enc_resolution) {} |
|
|
|
int32_t TMC51X0Motor::motor_get_enc_resolution(int32_t* enc_resolution) {} |
|
|
|
int32_t TMC51X0Motor::motor_set_enc_resolution(int32_t enc_resolution) { |
|
|
|
/**
|
|
|
|
* @brief |
|
|
|
* |
|
|
|
* TODO: |
|
|
|
* 1.假设电机是256细分 |
|
|
|
* 2.假设TMC5130_ENC_CONST是十进制模式 |
|
|
|
* 3.只支持指定分辨率的编码器 |
|
|
|
*/ |
|
|
|
|
|
|
|
int32_t enc_resolution_tmp = enc_resolution * 4; |
|
|
|
int32_t enc_const_integral = 0; |
|
|
|
int32_t enc_const_fractional = 0; |
|
|
|
|
|
|
|
switch (abs(enc_resolution_tmp)) { |
|
|
|
case 1000: |
|
|
|
enc_const_integral = 51; |
|
|
|
enc_const_fractional = 2; |
|
|
|
break; |
|
|
|
case 1024: |
|
|
|
enc_const_integral = 50; |
|
|
|
enc_const_fractional = 0; |
|
|
|
break; |
|
|
|
case 4000: |
|
|
|
enc_const_integral = 12; |
|
|
|
enc_const_fractional = 8; |
|
|
|
break; |
|
|
|
case 4096: |
|
|
|
enc_const_integral = 12; |
|
|
|
enc_const_fractional = 5; |
|
|
|
break; |
|
|
|
case 16384: |
|
|
|
enc_const_integral = 3; |
|
|
|
enc_const_fractional = 125; |
|
|
|
break; |
|
|
|
default: |
|
|
|
return err::kparam_out_of_range; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (enc_resolution_tmp < 0) { |
|
|
|
enc_const_integral = -enc_const_integral; |
|
|
|
} |
|
|
|
m_motor_enc_resolution = enc_resolution; |
|
|
|
int32_t setval = enc_const_integral * (2 ^ 16) + enc_const_fractional; |
|
|
|
m_stepM1->writeInt(TMC5130_ENC_CONST, setval); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
int32_t TMC51X0Motor::motor_get_enc_resolution(int32_t* enc_resolution) { |
|
|
|
*enc_resolution = m_motor_enc_resolution; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
int32_t TMC51X0Motor::motor_set_subdevice_reg(int32_t reg_addr, int32_t reg_val) { |
|
|
|
m_stepM1->writeInt((uint8_t)reg_addr, reg_val); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
int32_t TMC51X0Motor::motor_get_subdevice_reg(int32_t reg_addr, int32_t* reg_val) { |
|
|
|
*reg_val = m_stepM1->readInt((uint8_t)reg_addr); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int32_t TMC51X0Motor::motor_read_enc_val(int32_t* enc_val) { |
|
|
|
inverse_kinematics(m_stepM1->getENCVAL(), *enc_val); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int32_t TMC51X0Motor::motor_easy_move_to_io(int32_t ioindex, int32_t direction) { return _exec_move_to_io_task(ioindex, direction); } |
|
|
|
|
|
|
|