|
|
@ -139,13 +139,17 @@ uint8_t TMC5130::reset() { |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
int32_t TMC5130::getXACTUAL() { return to_user_pos(readInt(TMC5130_XACTUAL)); } |
|
|
|
void TMC5130::setXACTUAL(int32_t value) { writeInt(TMC5130_XACTUAL, to_motor_pos(value)); } |
|
|
|
int32_t TMC5130::getVACTUAL() { return to_user_pos(readInt(TMC5130_VACTUAL)); } |
|
|
|
void TMC5130::setAcceleration(float accelerationpps2) { writeInt(TMC5130_AMAX, (int32_t)(to_motor_acc(accelerationpps2))); } // 设置最大加速度
|
|
|
|
void TMC5130::setDeceleration(float accelerationpps2) { writeInt(TMC5130_DMAX, (int32_t)(to_motor_acc(accelerationpps2))); } // 设置最大减速度
|
|
|
|
void TMC5130::setMotorShaft(bool reverse) { PRV_FIELD_WRITE(TMC5130_GCONF, TMC5130_SHAFT_MASK, TMC5130_SHAFT_SHIFT, reverse); } |
|
|
|
void TMC5130::setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay) { writeInt(TMC5130_IHOLD_IRUN, (iholddelay << TMC5130_IHOLDDELAY_SHIFT) | (irun << TMC5130_IRUN_SHIFT) | (ihold << TMC5130_IHOLD_SHIFT)); } |
|
|
|
int32_t TMC5130::getXACTUAL() { return to_user_pos(readInt(TMC5130_XACTUAL)); } |
|
|
|
void TMC5130::setXACTUAL(int32_t value) { writeInt(TMC5130_XACTUAL, to_motor_pos(value)); } |
|
|
|
int32_t TMC5130::getVACTUAL() { return to_user_pos(readInt(TMC5130_VACTUAL)); } |
|
|
|
void TMC5130::setAcceleration(float accelerationpps2) { writeInt(TMC5130_AMAX, (int32_t)(to_motor_acc(accelerationpps2))); } // 设置最大加速度
|
|
|
|
void TMC5130::setDeceleration(float accelerationpps2) { writeInt(TMC5130_DMAX, (int32_t)(to_motor_acc(accelerationpps2))); } // 设置最大减速度
|
|
|
|
void TMC5130::setMotorShaft(bool reverse) { PRV_FIELD_WRITE(TMC5130_GCONF, TMC5130_SHAFT_MASK, TMC5130_SHAFT_SHIFT, reverse); } |
|
|
|
void TMC5130::setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay) { writeInt(TMC5130_IHOLD_IRUN, (iholddelay << TMC5130_IHOLDDELAY_SHIFT) | (irun << TMC5130_IRUN_SHIFT) | (ihold << TMC5130_IHOLD_SHIFT)); } |
|
|
|
void TMC5130::setGlobalScale(uint8_t globalscale) { |
|
|
|
// writeInt(TMC5130_GCONF, (readInt(TMC5130_GCONF) & ~TMC5130_SCALE_MASK) | (globalscale << TMC5130_SCALE_SHIFT));
|
|
|
|
} |
|
|
|
|
|
|
|
uint32_t TMC5130::readICVersion() { |
|
|
|
uint32_t chipID = PRV_FIELD_READ(TMC5130_IOIN, TMC5130_VERSION_MASK, TMC5130_VERSION_SHIFT); |
|
|
|
return chipID; |
|
|
@ -252,8 +256,8 @@ int32_t TMC5130::readInt(uint8_t address) { |
|
|
|
|
|
|
|
return ((uint32_t)data[1] << 24) | ((uint32_t)data[2] << 16) | (data[3] << 8) | data[4]; |
|
|
|
} |
|
|
|
int32_t TMC5130::to_motor_acc(int32_t acc) { //
|
|
|
|
int32_t val = acc / 60.0 * m_onecirclepulse; // 65535
|
|
|
|
int32_t TMC5130::to_motor_acc(int32_t acc) { //
|
|
|
|
int32_t val = acc / 60.0 * m_onecirclepulse; // 65535
|
|
|
|
if (val > 65535) val = 65535; |
|
|
|
return val; |
|
|
|
} |
|
|
|