|
|
@ -83,14 +83,14 @@ int32_t StepMotor45::stop() { |
|
|
|
} |
|
|
|
int32_t StepMotor45::zero_calibration() { |
|
|
|
CriticalContext cc; |
|
|
|
ZLOGI(TAG, "zero_calibration1 %d", getzeropinstate()); |
|
|
|
// ZLOGI(TAG, "zero_calibration1 %d", getzeropinstate());
|
|
|
|
if (getzeropinstate()) { |
|
|
|
ZLOGI(TAG, "zero_calibration2"); |
|
|
|
m_calibration = true; |
|
|
|
m_pos = 0; |
|
|
|
return (int32_t)0; |
|
|
|
} |
|
|
|
ZLOGI(TAG, "zero_calibration"); |
|
|
|
// ZLOGI(TAG, "zero_calibration");
|
|
|
|
m_exec_zero_calibration_task = true; |
|
|
|
m_state = krollback; |
|
|
|
return (int32_t)0; |
|
|
@ -130,57 +130,48 @@ void StepMotor45::schedule() { |
|
|
|
m_lastzeropinstate = iostate; |
|
|
|
} |
|
|
|
|
|
|
|
if ((detect_rising_edge && m_state == krollback) || (detect_falling_edge && m_state == kforward_rotation)) { |
|
|
|
/**
|
|
|
|
* @brief 触发零点 |
|
|
|
*/ |
|
|
|
m_pos = 0; |
|
|
|
m_calibration = true; |
|
|
|
|
|
|
|
if (m_exec_zero_calibration_task) { |
|
|
|
if (m_exec_zero_calibration_task) { |
|
|
|
if ((detect_rising_edge && m_state == krollback) || (detect_falling_edge && m_state == kforward_rotation)) { |
|
|
|
m_pos = 0; |
|
|
|
m_calibration = true; |
|
|
|
m_exec_zero_calibration_task = 0; |
|
|
|
stop_motor(); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 零点限位触发,电机停止运行 |
|
|
|
*/ |
|
|
|
if (m_cfg.enable_zero_limit && m_state == krollback) { |
|
|
|
if (iostate) { |
|
|
|
stop_motor(); |
|
|
|
return; |
|
|
|
} else { |
|
|
|
// 触发零点
|
|
|
|
if ((detect_rising_edge && m_state == krollback) || (detect_falling_edge && m_state == kforward_rotation)) { |
|
|
|
m_pos = 0; |
|
|
|
m_calibration = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 触发最大位置限位,电机停止运行 |
|
|
|
*/ |
|
|
|
if (m_cfg.enable_max_pos_limit && m_state == kforward_rotation) { |
|
|
|
if (m_pos >= m_cfg.max_pos) { |
|
|
|
stop_motor(); |
|
|
|
return; |
|
|
|
// 零点限位触发,电机停止运行
|
|
|
|
if (m_cfg.enable_zero_limit && m_state == krollback) { |
|
|
|
if (iostate) { |
|
|
|
stop_motor(); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 如果使能了最大位置限位,且电机没有校准过,则电机不允许正转 |
|
|
|
*/ |
|
|
|
if (m_cfg.enable_max_pos_limit && !m_calibration) { |
|
|
|
if (m_state == kforward_rotation) { |
|
|
|
return; |
|
|
|
// 触发最大位置限位,电机停止运行
|
|
|
|
if (m_cfg.enable_max_pos_limit && m_state == kforward_rotation) { |
|
|
|
if (m_pos >= m_cfg.max_pos) { |
|
|
|
stop_motor(); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 如果运行到目标位置则停止 |
|
|
|
*/ |
|
|
|
|
|
|
|
if (posmode) { |
|
|
|
if (m_pos == m_targetPos) { |
|
|
|
stop_motor(); |
|
|
|
return; |
|
|
|
// 如果使能了最大位置限位,且电机没有校准过,则电机不允许正转
|
|
|
|
if (m_cfg.enable_max_pos_limit && !m_calibration) { |
|
|
|
if (m_state == kforward_rotation) { |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// 如果运行到目标位置则停止
|
|
|
|
if (posmode) { |
|
|
|
if (m_pos == m_targetPos) { |
|
|
|
stop_motor(); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|