Browse Source

update

master
zhaohe 2 years ago
parent
commit
e5bf2e6eb6
  1. 5
      README.md
  2. 50
      app/MDK-ARM/app.uvguix.h_zha
  3. 2
      dep/libtrinamic
  4. 3
      src/board/hardware.hpp
  5. 120
      src/lncubator_rotating_control_service.cpp
  6. 1
      src/lncubator_rotating_control_service.hpp

5
README.md

@ -23,4 +23,9 @@ TMC4361芯片异常
编码器的供电电压和TMC的芯片电压不匹配时会出现TMC4361芯片无法工作的问题。
```
```
TODO:
1. 转盘卡住了异常捕获。
```

50
app/MDK-ARM/app.uvguix.h_zha
File diff suppressed because it is too large
View File

2
dep/libtrinamic

@ -1 +1 @@
Subproject commit b0450ea2b7b4892637b4885c2518d3b8db245588
Subproject commit a06ef2f6d468540c3cb04c5ce5c65e0d476af9f4

3
src/board/hardware.hpp

@ -30,7 +30,6 @@ class Hardware : public IflytopCanSlaveListener, //
private:
TMC4361A tmc4361motor1;
TMP117 tmp117[4];
FanStateMonitor m_fanStateMonitor[6];
IflytopCanSlave canSlaveService;
bool m_canOnRxDataFlag;
@ -40,6 +39,8 @@ class Hardware : public IflytopCanSlaveListener, //
int m_listenerNum;
public:
TMP117 tmp117[4];
public:
/*******************************************************************************
* ListenerImpl *

120
src/lncubator_rotating_control_service.cpp

@ -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;
}

1
src/lncubator_rotating_control_service.hpp

@ -121,6 +121,7 @@ class LncubatorRotatingControlService : public HardwareListener, //
void doRotateToHomeJob(interevent_t event);
void doMoveToSubPositionJob(interevent_t event);
void doMoveByJob(interevent_t event);
void changeState(dowhat_t state);
private:
int32_t tmc_getPosition();

Loading…
Cancel
Save