208 lines
4.0 KiB
C++
208 lines
4.0 KiB
C++
#pragma once
|
|
//#include "../config/bean/AxisCfg.h"
|
|
#include <windows.h>
|
|
#include <functional>
|
|
#include "AxisState.h"
|
|
#include "AxisConfig.h"
|
|
#include "AxisCtrl.h"
|
|
|
|
template <class T>
|
|
class AxisT
|
|
{
|
|
public:
|
|
AxisT();
|
|
~AxisT();
|
|
bool Init(void);
|
|
void UpdateSpeed(float speed);
|
|
void UpdateAcc(float acc);
|
|
void MovLimitStart(AxisConfig::ActiveDirect dir);
|
|
void MovLimitStop(AxisConfig::ActiveDirect dir);
|
|
void MovPoint(bool isActive);
|
|
void MovPoint(float value, bool isActive);
|
|
void MovPoint(AxisConfig::ActiveDirect dir);
|
|
void StopAxis(void);
|
|
void SetZeroPos(void);
|
|
void SetAxisOn(bool ison);
|
|
AxisConfig* GetConfig(void) { return m_Config; }
|
|
//bool IsReachLimit(AxisCfg::ActiveDirect dir);
|
|
bool IsMoving();
|
|
T* GetState(void) { return m_State; }
|
|
AxisCtrl* GetCtrl(void) { return m_Ctrl; }
|
|
private:
|
|
short m_ID;
|
|
AxisConfig* m_Config;
|
|
CRITICAL_SECTION m_cs;
|
|
T* m_State;
|
|
AxisCtrl* m_Ctrl;
|
|
//AxisCfg* m_AxisCfg;
|
|
};
|
|
|
|
template <class T>
|
|
AxisT<T>::AxisT()
|
|
{
|
|
m_State = new T;
|
|
m_Config = new AxisConfig;
|
|
m_Ctrl = new AxisCtrl;
|
|
}
|
|
|
|
template <class T>
|
|
AxisT<T>::~AxisT()
|
|
{
|
|
delete m_State;
|
|
}
|
|
|
|
template <class T>
|
|
bool AxisT<T>::Init(void)
|
|
{
|
|
bool rel = true;
|
|
return rel;
|
|
}
|
|
|
|
template <class T>
|
|
void AxisT<T>::UpdateSpeed(float speed)
|
|
{
|
|
m_Config->m_Speed->SetValue(speed);
|
|
}
|
|
|
|
template <class T>
|
|
void AxisT<T>::UpdateAcc(float acc)
|
|
{
|
|
m_Config->m_Acc->SetValue(acc);
|
|
}
|
|
|
|
template <class T>
|
|
void AxisT<T>::MovPoint(bool isActive)
|
|
{
|
|
if (IsMoving())
|
|
return;
|
|
|
|
if (isActive) {
|
|
m_Ctrl->m_MoveP->SetValue(true);
|
|
m_Ctrl->m_MoveP->SetValue(false);
|
|
}
|
|
else {
|
|
m_Ctrl->m_MoveN->SetValue(true);
|
|
m_Ctrl->m_MoveN->SetValue(false);
|
|
}
|
|
}
|
|
|
|
template <class T>
|
|
void AxisT<T>::MovPoint(float value, bool isActive)
|
|
{
|
|
if (IsMoving())
|
|
return;
|
|
|
|
m_Config->m_RefDistance->SetValue(value);
|
|
if (isActive) {
|
|
m_Ctrl->m_MoveP->SetValue(true);
|
|
m_Ctrl->m_MoveP->SetValue(false);
|
|
}
|
|
else {
|
|
m_Ctrl->m_MoveN->SetValue(true);
|
|
m_Ctrl->m_MoveN->SetValue(false);
|
|
}
|
|
}
|
|
|
|
|
|
template <class T>
|
|
void AxisT<T>::MovPoint(AxisConfig::ActiveDirect dir)
|
|
{
|
|
|
|
if (IsMoving()) {
|
|
return;
|
|
}
|
|
if (m_State->m_AxisCfg->m_active_direct == dir) {
|
|
m_Ctrl->m_MoveP->SetValue(true);
|
|
Sleep(100);
|
|
m_Ctrl->m_MoveP->SetValue(false);
|
|
}
|
|
else {
|
|
m_Ctrl->m_MoveN->SetValue(true);
|
|
Sleep(100);
|
|
m_Ctrl->m_MoveN->SetValue(false);
|
|
}
|
|
}
|
|
|
|
template <class T>
|
|
void AxisT<T>::StopAxis(void)
|
|
{
|
|
m_Ctrl->m_MotionStop->SetValue(true);
|
|
m_Ctrl->m_MotionStop->SetValue(false);
|
|
}
|
|
|
|
template <class T>
|
|
void AxisT<T>::MovLimitStart(AxisConfig::ActiveDirect dir)
|
|
{
|
|
if (IsMoving())
|
|
return;
|
|
|
|
if (m_State->m_AxisCfg->m_active_direct == dir) {
|
|
m_Ctrl->m_MovePContinue->SetValue(true);
|
|
}
|
|
else {
|
|
m_Ctrl->m_MoveNContinue->SetValue(true);
|
|
}
|
|
}
|
|
|
|
template <class T>
|
|
void AxisT<T>::MovLimitStop(AxisConfig::ActiveDirect dir)
|
|
{
|
|
// if (m_State->m_ServoBusy)
|
|
// return;
|
|
|
|
if (m_State->m_AxisCfg->m_active_direct == dir) {
|
|
m_Ctrl->m_MovePContinue->SetValue(false);
|
|
}
|
|
else {
|
|
m_Ctrl->m_MoveNContinue->SetValue(false);
|
|
}
|
|
}
|
|
|
|
template <class T>
|
|
void AxisT<T>::SetZeroPos(void)
|
|
{
|
|
m_Ctrl->m_ServoHomeIndexOn->SetValue(true);
|
|
m_Ctrl->m_ServoHomeIndexOn->SetValue(false);
|
|
}
|
|
|
|
template <class T>
|
|
void AxisT<T>::SetAxisOn(bool ison)
|
|
{
|
|
m_Ctrl->m_ServoOn->SetValue(ison);
|
|
}
|
|
|
|
#if 0
|
|
bool Axis::IsReachLimit(AxisCfg::ActiveDirect dir)
|
|
{
|
|
long limit = m_Config->m_active_direct == dir ? GTS_STATE_ACTIVE_LIMIT_INDEX : GTS_STATE_REACTIVE_LIMIT_INDEX;
|
|
//UpdateAxisState();
|
|
return m_State->state & limit;
|
|
}
|
|
#endif
|
|
|
|
template <class T>
|
|
bool AxisT<T>::IsMoving()
|
|
{
|
|
//std::unique_lock<std::shared_mutex> lock(mtx);
|
|
return m_State->m_ServoBusy;
|
|
}
|
|
|
|
class SysParamWrapper;
|
|
class StateCtrlWrapper;
|
|
class PLCAxis
|
|
{
|
|
public:
|
|
PLCAxis(SysParamWrapper* params, StateCtrlWrapper* ctrl);
|
|
~PLCAxis(){}
|
|
void StopAll(void);
|
|
public:
|
|
AxisT<MainAxisState>* m_Mold;
|
|
AxisT<SlaveAxisState>* m_MoldSlave;
|
|
AxisT<MainAxisState>* m_Clean;
|
|
AxisT<SlaveAxisState>* m_CleanSlave;
|
|
AxisT<AxisState>* m_Load;
|
|
AxisT<AxisState>* m_Arm;
|
|
AxisT<AxisState>* m_Supply;
|
|
AxisT<MainAxisState>* m_Ele;
|
|
AxisT<SlaveAxisState>* m_EleSlave;
|
|
}; |