|
|
@ -662,40 +662,56 @@ int32_t TMC51X0Motor::motor_set_enc_resolution(int32_t enc_resolution) { |
|
|
|
*/ |
|
|
|
|
|
|
|
int32_t enc_resolution_tmp = enc_resolution * 4; |
|
|
|
int32_t enc_const_integral = 0; |
|
|
|
int32_t enc_const_fractional = 0; |
|
|
|
int16_t enc_const_integral = 0; |
|
|
|
int16_t enc_const_fractional = 0; |
|
|
|
|
|
|
|
switch (abs(enc_resolution_tmp)) { |
|
|
|
case 1000: |
|
|
|
enc_const_integral = 51; |
|
|
|
enc_const_fractional = 2; |
|
|
|
enc_const_fractional = 0.2 * 10000; |
|
|
|
break; |
|
|
|
case 1024: |
|
|
|
enc_const_integral = 50; |
|
|
|
enc_const_fractional = 0; |
|
|
|
enc_const_fractional = 0 * 10000; |
|
|
|
break; |
|
|
|
case 4000: |
|
|
|
enc_const_integral = 12; |
|
|
|
enc_const_fractional = 8; |
|
|
|
enc_const_fractional = 0.8 * 10000; |
|
|
|
break; |
|
|
|
case 4096: |
|
|
|
enc_const_integral = 12; |
|
|
|
enc_const_fractional = 5; |
|
|
|
enc_const_fractional = 0.5 * 10000; |
|
|
|
break; |
|
|
|
case 16384: |
|
|
|
enc_const_integral = 3; |
|
|
|
enc_const_fractional = 125; |
|
|
|
enc_const_fractional = 0.125 * 10000; |
|
|
|
break; |
|
|
|
default: |
|
|
|
return err::kparam_out_of_range; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (enc_resolution_tmp < 0) { |
|
|
|
enc_const_integral = -enc_const_integral; |
|
|
|
} |
|
|
|
// 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; |
|
|
|
uint32_t setval = 0; |
|
|
|
uint8_t* psetval = (uint8_t*)&setval; |
|
|
|
|
|
|
|
// if (enc_resolution_tmp < 0) {
|
|
|
|
// enc_const_integral = -enc_const_integral;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (enc_resolution_tmp < 0) {
|
|
|
|
// enc_const_fractional = enc_const_fractional;
|
|
|
|
// }
|
|
|
|
|
|
|
|
memcpy(psetval + 2, &enc_const_integral, 2); |
|
|
|
memcpy(psetval, &enc_const_fractional, 2); |
|
|
|
|
|
|
|
// int32_t setval = (enc_const_integral << 16) + enc_const_fractional * 10000;
|
|
|
|
// ZLOGI(TAG, "setval:%d", setval);
|
|
|
|
m_stepM1->writeInt(TMC5130_ENCMODE, 0x1 << 10); |
|
|
|
m_stepM1->writeInt(TMC5130_ENC_CONST, setval); |
|
|
|
return 0; |
|
|
|
} |
|
|
@ -716,7 +732,14 @@ int32_t TMC51X0Motor::motor_read_enc_val(int32_t* enc_val) { |
|
|
|
if (m_motor_enc_resolution == 0) { |
|
|
|
return motor_read_pos(enc_val); |
|
|
|
} |
|
|
|
// ZLOGI(TAG, "%d , %d", m_stepM1->getENCVAL(), m_stepM1->getXACTUAL());
|
|
|
|
// m_stepM1->setENCVAL(0);
|
|
|
|
inverse_kinematics(m_stepM1->getENCVAL(), *enc_val); |
|
|
|
|
|
|
|
if (m_motor_enc_resolution < 0) { |
|
|
|
*enc_val = -*enc_val; |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|