Browse Source

update

master
zhaohe 2 years ago
parent
commit
9f2fd2e2c6
  1. 2
      components/step_motor_ctrl_module/step_motor_ctrl_module.cpp
  2. 2
      components/tmc/basic/tmc_ic_interface.hpp
  3. 4
      components/tmc/ic/ztmc4361A.cpp
  4. 13
      components/tmc/ic/ztmc5130.cpp
  5. 4
      components/tmc/ic/ztmc5130.hpp

2
components/step_motor_ctrl_module/step_motor_ctrl_module.cpp

@ -613,5 +613,5 @@ int32_t StepMotorCtrlModule::factory_reset() {
}
void StepMotorCtrlModule::active_cfg() {
m_stepM1->setIHOLD_IRUN(m_param.ihold, m_param.irun, m_param.iholddelay);
m_stepM1->setScale(m_param.distance_scale / 1000.0);
m_stepM1->setScale(m_param.distance_scale);
}

2
components/tmc/basic/tmc_ic_interface.hpp

@ -58,7 +58,7 @@ class IStepperMotor {
virtual bool isStoped() = 0;
virtual void setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay) = 0;
virtual void setScale(float scale) = 0;
virtual void setScale(int32_t scale) = 0;
virtual void enable(bool enable) = 0;
};

4
components/tmc/ic/ztmc4361A.cpp

@ -406,11 +406,11 @@ int32_t TMC4361A::to_motor_pos(int32_t pos) { //
int32_t TMC4361A::to_user_pos(int32_t pos) { //
int32_t val = pos / 51200.0 * m_scale;
return 0;
return val;
} //
int32_t TMC4361A::to_user_vel(int32_t vel) { //
int32_t val = vel * 60.0 / 51200.0;
return 0;
return val;
}
#endif

13
components/tmc/ic/ztmc5130.cpp

@ -116,7 +116,7 @@ Tmc5130RampStat TMC5130::getTMC5130_RAMPSTAT2() {
void TMC5130::stop() { rotate(0); }
void TMC5130::rotate(int32_t velocity) {
// velocity *= m_scale;
to_motor_vel(velocity);
velocity = to_motor_vel(velocity);
writeInt(TMC5130_VMAX, abs(velocity));
writeInt(TMC5130_RAMPMODE, (velocity >= 0) ? TMC5130_MODE_VELPOS : TMC5130_MODE_VELNEG);
}
@ -125,8 +125,9 @@ void TMC5130::left(int32_t velocity) { rotate(-velocity); }
void TMC5130::moveTo(int32_t position, uint32_t velocityMax) {
// position *= m_scale;
// velocityMax *= m_scale;
to_motor_pos(position);
to_motor_vel(velocityMax);
position = to_motor_pos(position);
velocityMax = to_motor_vel(velocityMax);
// ZLOGI("TMC5130", "moveTo %d %d", position, velocityMax);
writeInt(TMC5130_RAMPMODE, TMC5130_MODE_POSITION);
writeInt(TMC5130_VMAX, velocityMax);
writeInt(TMC5130_XTARGET, position);
@ -159,7 +160,7 @@ bool TMC5130::isReachTarget() {
}
}
void TMC5130::setScale(float scale) { m_scale = scale; }
void TMC5130::setScale(int32_t scale) { m_scale = scale; }
/*******************************************************************************
* basic *
@ -225,9 +226,9 @@ int32_t TMC5130::to_motor_pos(int32_t pos) { //
int32_t TMC5130::to_user_pos(int32_t pos) { //
int32_t val = pos / 51200.0 * m_scale;
return 0;
return val;
} //
int32_t TMC5130::to_user_vel(int32_t vel) { //
int32_t val = vel * 60.0 / 51200.0;
return 0;
return val;
}

4
components/tmc/ic/ztmc5130.hpp

@ -88,7 +88,7 @@ class TMC5130 : public IStepperMotor {
const uint8_t *m_registerAccessTable;
const int32_t *m_defaultRegisterResetState;
float m_scale = 1.0;
int32_t m_scale = 10000;
public:
TMC5130(/* args */);
@ -115,7 +115,7 @@ class TMC5130 : public IStepperMotor {
virtual int32_t getENC_POS() { return 0; } // TODO impl it
virtual void setENC_POS(int32_t value) {} // TODO impl it
virtual void setScale(float scale);
virtual void setScale(int32_t scale);
virtual void setAcceleration(float accelerationpps2);
virtual void setDeceleration(float accelerationpps2);

Loading…
Cancel
Save