|
|
@ -3,11 +3,22 @@ |
|
|
|
using namespace iflytop; |
|
|
|
#define TAG "LRCS"
|
|
|
|
|
|
|
|
#define UPDATE_ZERO_POSITION_ALWAYS 1
|
|
|
|
|
|
|
|
const uint32_t LncubatorRotatingControlService::mc_onecircle_ustep_num = (256 * 200 * 50); |
|
|
|
const uint32_t LncubatorRotatingControlService::mc_default_velocity = 500000; // 500kpps
|
|
|
|
const uint32_t LncubatorRotatingControlService::mc_one_sub_position_width = (256 * 200 * 50) / 20; |
|
|
|
|
|
|
|
LncubatorRotatingControlService::LncubatorRotatingControlService() {} |
|
|
|
LncubatorRotatingControlService::LncubatorRotatingControlService() { |
|
|
|
m_hardware = NULL; |
|
|
|
m_motor = NULL; |
|
|
|
m_os = NULL; |
|
|
|
m_workfinished = false; |
|
|
|
m_dowhat = kidle; |
|
|
|
m_maxVelocity = mc_default_velocity; |
|
|
|
m_inletPosition = 0; |
|
|
|
m_outletPosition = m_inletPosition + mc_one_sub_position_width / 2; |
|
|
|
} |
|
|
|
LncubatorRotatingControlService::~LncubatorRotatingControlService() {} |
|
|
|
void LncubatorRotatingControlService::initialize(Hardware* hardware) { //
|
|
|
|
m_hardware = hardware; |
|
|
@ -31,7 +42,15 @@ void LncubatorRotatingControlService::setVelocity(int32_t velocityMax) { m_maxVe |
|
|
|
void LncubatorRotatingControlService::registerListener(LncubatorRotatingControlServiceListener* listener) { //
|
|
|
|
m_listener = listener; |
|
|
|
} |
|
|
|
|
|
|
|
void LncubatorRotatingControlService::calibrationPosition(refpoint_t refpoint) { |
|
|
|
/**
|
|
|
|
* @brief 此时是孵育船1对其了入口 |
|
|
|
*/ |
|
|
|
if (refpoint == REFPOINT_TYPE_INLET) { |
|
|
|
m_inletPosition = tmc_getPosition(); |
|
|
|
m_outletPosition = normalizePosition(m_inletPosition + mc_onecircle_ustep_num / 2); |
|
|
|
} |
|
|
|
} |
|
|
|
/*******************************************************************************
|
|
|
|
* motorHelp * |
|
|
|
*******************************************************************************/ |
|
|
@ -58,7 +77,7 @@ int32_t LncubatorRotatingControlService::normalizePosition(int32_t position) { |
|
|
|
} |
|
|
|
void LncubatorRotatingControlService::tmc_moveBy(int32_t relativePosition) { m_motor->moveBy(relativePosition, m_maxVelocity); } |
|
|
|
/*******************************************************************************
|
|
|
|
* TriggerEvent * |
|
|
|
* JobBasic * |
|
|
|
*******************************************************************************/ |
|
|
|
void LncubatorRotatingControlService::Hardware_onHomeRefSwitchISR() { |
|
|
|
/**
|
|
|
@ -66,84 +85,67 @@ void LncubatorRotatingControlService::Hardware_onHomeRefSwitchISR() { |
|
|
|
*/ |
|
|
|
m_homeKeyTriggered = true; |
|
|
|
} |
|
|
|
void LncubatorRotatingControlService::triggerEvent(interevent_t event) {} |
|
|
|
|
|
|
|
void LncubatorRotatingControlService::periodicJob() { |
|
|
|
void LncubatorRotatingControlService::triggerEvent(interevent_t event) { |
|
|
|
if (kmoveToHomeJob == m_dowhat) { |
|
|
|
doRotateToHomeJob(kPeriodicJobEvent); |
|
|
|
doRotateToHomeJob(event); |
|
|
|
} else if (kmoveSubPositionJob == m_dowhat) { |
|
|
|
doMoveToSubPositionJob(kPeriodicJobEvent); |
|
|
|
doMoveToSubPositionJob(event); |
|
|
|
} else if (kmoveByJob == m_dowhat) { |
|
|
|
doMoveByJob(kPeriodicJobEvent); |
|
|
|
doMoveByJob(event); |
|
|
|
} |
|
|
|
} |
|
|
|
void LncubatorRotatingControlService::periodicJob() { |
|
|
|
triggerEvent(kPeriodicJobEvent); |
|
|
|
if (m_homeKeyTriggered) { |
|
|
|
m_homeKeyTriggered = false; |
|
|
|
if (kmoveToHomeJob == m_dowhat) { |
|
|
|
doRotateToHomeJob(kPeriodicJobEvent); |
|
|
|
} else if (kmoveSubPositionJob == m_dowhat) { |
|
|
|
doMoveToSubPositionJob(kPeriodicJobEvent); |
|
|
|
} else if (kmoveByJob == m_dowhat) { |
|
|
|
doMoveByJob(kPeriodicJobEvent); |
|
|
|
} |
|
|
|
triggerEvent(kHomeSwitchTriggeredEvent); |
|
|
|
} |
|
|
|
} |
|
|
|
void LncubatorRotatingControlService::TMC4361A_onEvent(uint32_t event) { |
|
|
|
if (event & TMC4361A::event_mask_t::ktarget_reached) { |
|
|
|
if (kmoveToHomeJob == m_dowhat) { |
|
|
|
doRotateToHomeJob(kTMC4361AReachTargetEvent); |
|
|
|
} else if (kmoveSubPositionJob == m_dowhat) { |
|
|
|
doMoveToSubPositionJob(kTMC4361AReachTargetEvent); |
|
|
|
} else if (kmoveByJob == m_dowhat) { |
|
|
|
doMoveByJob(kTMC4361AReachTargetEvent); |
|
|
|
} |
|
|
|
triggerEvent(kTMC4361AReachTargetEvent); |
|
|
|
} |
|
|
|
} |
|
|
|
void LncubatorRotatingControlService::changeState(dowhat_t tostate) { |
|
|
|
m_dowhat = tostate; |
|
|
|
if (tostate == kidle) { |
|
|
|
m_workfinished = true; |
|
|
|
} else { |
|
|
|
m_workfinished = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* RotateToHomeJob * |
|
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
void LncubatorRotatingControlService::moveToHome() { |
|
|
|
if (m_dowhat != kidle) return; |
|
|
|
m_dowhat = kmoveToHomeJob; |
|
|
|
changeState(kmoveToHomeJob); |
|
|
|
moveBy(mc_onecircle_ustep_num * 2); |
|
|
|
} |
|
|
|
void LncubatorRotatingControlService::doRotateToHomeJob(interevent_t event) { |
|
|
|
if (event == kPeriodicJobEvent) { |
|
|
|
if (m_homeKeyTriggered) { |
|
|
|
m_homeKeyTriggered = false; |
|
|
|
/**
|
|
|
|
* @brief 零点光电触发,记录零点位置 |
|
|
|
*/ |
|
|
|
m_motor->stop(); |
|
|
|
m_motor->setZeroPoint(); |
|
|
|
m_dowhat = kidle; |
|
|
|
ZLOGI(TAG, "find Zero Point"); |
|
|
|
if (m_listener) m_listener->LncubatorRotatingControlService_onMoveToHomeJobFinished(); |
|
|
|
} |
|
|
|
} else if (event == kHomeSwitchTriggeredEvent) { |
|
|
|
m_motor->stop(); |
|
|
|
m_motor->setZeroPoint(); |
|
|
|
changeState(kidle); |
|
|
|
ZLOGI(TAG, "find Zero Point"); |
|
|
|
if (m_listener) m_listener->LncubatorRotatingControlService_onMoveToHomeJobFinished(); |
|
|
|
} else if (event == kTMC4361AReachTargetEvent) { |
|
|
|
/**
|
|
|
|
* @brief 电机转了两圈依然没有找到零点 |
|
|
|
*/ |
|
|
|
if (m_listener) m_listener->LncubatorRotatingControlService_onException(kGoHomeFail); |
|
|
|
m_dowhat = kidle; |
|
|
|
} |
|
|
|
} |
|
|
|
void LncubatorRotatingControlService::calibrationPosition(refpoint_t refpoint) { |
|
|
|
/**
|
|
|
|
* @brief 此时是孵育船1对其了入口 |
|
|
|
*/ |
|
|
|
if (refpoint == REFPOINT_TYPE_INLET) { |
|
|
|
m_inletPosition = tmc_getPosition(); |
|
|
|
m_outletPosition = normalizePosition(m_inletPosition + mc_onecircle_ustep_num / 2); |
|
|
|
changeState(kidle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* moveToSubPosition * |
|
|
|
* moveToSubPositionJob * |
|
|
|
*******************************************************************************/ |
|
|
|
void LncubatorRotatingControlService::moveToSubPosition(refpoint_t refpoint, int32_t positionIndex) { |
|
|
|
if (m_dowhat != kidle) return; |
|
|
|
m_dowhat = kmoveSubPositionJob; |
|
|
|
changeState(kmoveSubPositionJob); |
|
|
|
// 出口
|
|
|
|
if (refpoint == REFPOINT_TYPE_OUTLET) { |
|
|
|
int32_t targetPosition = m_outletPosition + positionIndex * mc_one_sub_position_width; |
|
|
@ -157,12 +159,16 @@ void LncubatorRotatingControlService::moveToSubPosition(refpoint_t refpoint, int |
|
|
|
} |
|
|
|
void LncubatorRotatingControlService::doMoveToSubPositionJob(interevent_t event) { |
|
|
|
if (event == kPeriodicJobEvent) { |
|
|
|
} else if (event == kHomeSwitchTriggeredEvent) { |
|
|
|
#if UPDATE_ZERO_POSITION_ALWAYS
|
|
|
|
m_motor->setZeroPoint(); |
|
|
|
#endif
|
|
|
|
} else if (event == kTMC4361AReachTargetEvent) { |
|
|
|
/**
|
|
|
|
* @brief moveToTarget |
|
|
|
*/ |
|
|
|
if (m_listener) m_listener->LncubatorRotatingControlService_onMoveSubPositionJobFinished(); |
|
|
|
m_dowhat = kidle; |
|
|
|
changeState(kidle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -171,18 +177,22 @@ void LncubatorRotatingControlService::doMoveToSubPositionJob(interevent_t event) |
|
|
|
*******************************************************************************/ |
|
|
|
void LncubatorRotatingControlService::moveBy(int32_t pluseCount) { |
|
|
|
if (m_dowhat == kidle || m_dowhat == kmoveByJob) { |
|
|
|
m_dowhat = kmoveByJob; |
|
|
|
changeState(kmoveByJob); |
|
|
|
tmc_moveBy(pluseCount); |
|
|
|
} |
|
|
|
} |
|
|
|
void LncubatorRotatingControlService::doMoveByJob(interevent_t event) { |
|
|
|
if (event == kPeriodicJobEvent) { |
|
|
|
} else if (event == kHomeSwitchTriggeredEvent) { |
|
|
|
#if UPDATE_ZERO_POSITION_ALWAYS
|
|
|
|
m_motor->setZeroPoint(); |
|
|
|
#endif
|
|
|
|
} else if (event == kTMC4361AReachTargetEvent) { |
|
|
|
/**
|
|
|
|
* @brief moveToTarget |
|
|
|
*/ |
|
|
|
if (m_listener) m_listener->LncubatorRotatingControlService_onMoveByJobFinished(); |
|
|
|
m_dowhat = kidle; |
|
|
|
changeState(kidle); |
|
|
|
} |
|
|
|
} |
|
|
|
/*******************************************************************************
|
|
|
@ -190,9 +200,7 @@ void LncubatorRotatingControlService::doMoveByJob(interevent_t event) { |
|
|
|
*******************************************************************************/ |
|
|
|
void LncubatorRotatingControlService::stop() { |
|
|
|
if (m_dowhat == kidle) return; |
|
|
|
if (m_dowhat == kmoveToHomeJob) { |
|
|
|
m_motor->stop(); |
|
|
|
m_dowhat = kidle; |
|
|
|
return; |
|
|
|
} |
|
|
|
m_motor->stop(); |
|
|
|
changeState(kidle); |
|
|
|
return; |
|
|
|
} |