SDC C-Project CF Review 프로그램
LYW
2021-07-08 e10b8c2a3f6ee6b639dbb49ff6635d0657531d1e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/******************************************************************************
 *    
 *    (C) Copyright WDI 2010
 *    
 ******************************************************************************
 *
 *    FILE:        llc.h
 *
 *    PROJECT:    AFT Sensor
 *
 *    SUBPROJECT:    .
 *
 *    Description: LLC interface
 *    
 ******************************************************************************
 *    
 *    Change Activity
 *    Defect  Date       Developer        Description
 *    Number  DD/MM/YYYY Name
 *    ======= ========== ================ =======================================
 *          28/01/2011 Chris O.         Initial version
 *
 ******************************************************************************/
 
#pragma once
 
#ifdef __cplusplus
 
#include "epp.h"
#include "logger.h"
 
// number of pulses per mm in LLC encoder
#define ENC_PULSE_PER_MM 10000    
// max number of objectives
#define MAX_LLC_OBJ_NUM 8
 
// LLC error codes
enum LlcErrCode
{
    LlcErrOK = 0,                    // 0
// LLC not initilaized error
    LlcErrNotInitialized,            // 1
// LLC bad argument error
    LlcErrArgRange,                    // 2
// communication errors
    LlcErrStatus,                    // 3
    LlcErrSendFailure,                // 4
    LlcErrSensorCom,                // 5
    LlcErrCmndSyntax,                // 6
    LlcErrRecvLen,                    // 7
    LlcErrRecvSyntax,                // 8
    LlcErrWhistleEC,                // 9
//    number of objectives error
    LlcErrObjectiveNum,                // 10
// offset file error
    LlcErrOffsetFile,                // 11
// homing failure error
    LlcErrHoming,                    // 12
// move to target error
    LlcErrTargetPos,                // 13
// movement timeout
    LlcErrTimeout,                    // 14
// hardware error
    LlcErrRecoveryFailed,            // 15
    LlcErrLimitSwitch,                // 16
    LlcErrMotorDisabled,            // 17
// hardware failure
    LlcErrPeakCurrExceeded,            // 18
    LlcErrInhibit,                    // 19
    LlcErrSpeedTracking,            // 20
    LlcErrPositionTracking,            // 21
    LlcErrUnderVoltage,                // 22
    LlcErrOverVoltage,                // 23
    LlcErrShortCircuit,                // 24
    LlcErrOverheating,                // 25
    LlcErrElectricalZero,            // 26
    LlcErrSpeedLimit,                // 27
    LlcErrMotorStuck,                // 28
    LlcErrPositionlimit,            // 29
    LlcErrStartMotor,                // 30
// MFC firmware failure
    LlcErrStackOverflow,            // 31
    LlcErrCpuException                // 32
};
 
// SR - status register flags (received with "SR;" command)
#define LLC_SR_DR_FLAG        0x00000001    // drive error    (the same as in MF register shown below) - is ON when any of four shown below present
#define LLC_SR_DRUV_FLAG    0x00000003    // under voltage  (the same as in MF register shown below)
#define LLC_SR DROV_FLAG    0x00000005    // over voltage   (the same as in MF register shown below)
#define LLC_SR_DRSC_FLAG    0x0000000B    // short circuit  (the same as in MF register shown below)
#define LLC_SR_DROH_FLAG    0x0000000D    // overheating    (the same as in MF register shown below)
#define LLC_SR_MO_FLAG        0x00000010    // motor enable / disable status - can be obtain with "MO;" command too
#define LLC_SR_MF_FLAG        0x00000040    // motor failure - can be obtain with "MF;" command too
#define LLC_SR_MS_FLAG        0x0000C000    // motion status [00 = In Position; 01 = Off Position; 10 = In motion] - can be obtained with "MS;" command too
#define LLC_SR_PR_FLAG        0x00001000    // program running
#define LLC_SR_SL_FLAG        0x10000000    // limit switches
// MF - motor failure register flags (received with "MF;" command)
#define LLC_MF_PC_FLAG        0x00000008    // peak current exceeded
#define LLC_MF_IN_FLAG        0x00000010    // inhibit
#define LLC_MF_ST_FLAG        0x00000080    // speed tracking error
#define LLC_MF_PS_FLAG        0x00000100    // position tracking error
#define LLC_MF_DR_FLAG        0x00001000    // drive error    (the same as in SR register shown above) - is ON when any of four shown below present
#define LLC_MF_DRUV_FLAG    0x00003000    // under voltage  (the same as in SR register shown above)
#define LLC_MF_DROV_FLAG    0x00005000    // over voltage   (the same as in SR register shown above)
#define LLC_MF_DRSC_FLAG    0x0000B000    // short circuit  (the same as in SR register shown above)
#define LLC_MF_DROH_FLAG    0x0000D000    // overheating    (the same as in SR register shown above)
#define LLC_MF_EZ_FLAG        0x00010000    // electrical zero failure
#define LLC_MF_SL_FLAG        0x00020000    // speed limit failure
#define LLC_MF_SO_FLAG        0x00040000    // stack overflow
#define LLC_MF_CE_FLAG        0x00080000    // CPU exception
#define LLC_MF_MS_FLAG        0x00200000    // motor stuck
#define LLC_MF_PL_FLAG        0x00400000    // position limit exceeded
#define LLC_MF_SM_FLAG        0x20000000    // motor start failure
 
 
// LLC class
class CLlc
{
public:
    // constructor & destructor
    CLlc(CLogger *pLogger = NULL)
    {
        // initialize
        m_pLogger = pLogger;
        m_bIsLlcInit = false;
        m_iObjNum = 0;
//        m_iObjPitch = 0;
        m_cOffsetFilePath[0] = '\0';
        m_cForcerSerNum[0] = '\0';
        for (int i = 0; i < MAX_LLC_OBJ_NUM; i++)
        {
            m_fObjPitch[i] = 0.0f;
        }
    }
 
    ~CLlc() {}
 
private:
    CLogger *m_pLogger;                    // pointer to logger object
    bool m_bIsLlcInit;                    // is LLC initialized flag
    bool m_bIsHomeDetImpl;                // is ET[5] home detection implemented flag
    char m_cForcerSerNum[16];            // forcer serial number - ET[4]
    char m_cOffsetFilePath[MAX_PATH];    // objective movement offsets file name
    int m_iObjNum;                        // number of available objectives
//    int m_iObjPitch;                    // distance between objectives
    float m_fObjPitch[MAX_LLC_OBJ_NUM];    // distance between objectives
 
public:
    bool initializeLlc(char *pOffsetFileDir, int *piErrCode);
    void setObjectiveNum(int iObjNum);
    int getObjectiveNum();
    void setObjectivePitch(float fObjPitch[MAX_LLC_OBJ_NUM]);
    void getObjectivePitch(float fObjPitch[MAX_LLC_OBJ_NUM]);
    int getLlcForcerSerNum();
    int sendLlc(char *toSend, char *toRecv);
    bool getLlcStatus(int *piErrCode, const char **ppErrMsg, int *piStatReg, int *piMtrFailureReg);
    bool recoverLlc(int *piErrCode);
    bool recoverLlcSensorConnection(int *piErrCode);
    bool recoverLlcHdwr(int *piErrCode);
    bool resetLlcController(int *piErrCode);
    bool homeLlc(bool bWaitForEnd, int *piErrCode);
    bool isLlcInHomePos(int *piErrCode);
    bool saveLlcObjectivePositionOffset(int iObjectiveNumber, int iOffset);
    bool getLlcObjectivePositionOffset(int iObjectiveNumber, int *piPositionOffset);
    bool moveLlcToObjective(int iObjectiveNumber, bool bWaitForEnd, int *piErrCode);
    bool moveLlcToPosition(int iPosition, bool bWaitForEnd, int *piErrCode);
    bool moveLLcRelativeDistance(int iDistance, bool bWaitForEnd, int *piErrCode);
    bool isLlcInTargetPosition(int *piErrCode);
    bool enableLlcMotor(int *piErrCode);
    bool disableLlcMotor(int *piErrCode);
    bool stopLlcMotion(int *piErrCode);
    bool setLlcSpeed(int iLlcSpeed, int *piErrCode);
    bool getLlcSpeed(int *piLlcSpeed, int *piErrCode);
    bool setLlcAcceleration(int iLlcAcceleration, int *piErrCode);
    bool getLlcAcceleration(int *piLlcAcceleration, int *piErrCode);
    bool setLlcDeceleration(int iLlcDeceleration, int *piErrCode);
    bool getLlcDeceleration(int *piLlcDeceleration, int *piErrCode);
    bool setLlcSmoothFactor(int iLlcSmoothFactor, int *piErrCode);
    bool getLlcSmoothFactor(int *piLlcSmoothFactor, int *piErrCode);
    bool getLlcVelocity(float *pfLlcVelocity, int *piErrCode);
    bool getLlcPosition(float *pfLlcPosition, int *piErrCode);
    bool getLlcMotorCurrent(float *pfLlcMotorCurrent, int *piErrCode);
    inline void setLlcLogger(CLogger *pLogger) {m_pLogger = pLogger;}
 
private:
    bool createLlcOffsetFile(char *pOffsetFileDir);
    void saveToLog(const char *pLogMsg, CLogger::LogLevels iLogLevel);
    void saveToLog2(CLogger::LogLevels iLogLevel, char *pFormat, ...);
 
// logging macros
#define LLCENTERFUN(funname) saveToLog2(CLogger::LogLow, "%s%s", funname, " - entered\n");
#define LLCEXITFUN(funname) saveToLog2(CLogger::LogLow, "%s%s", funname, " - exited\n");
#define LLCLOGMSG(pLogMsg, LogLev) saveToLog(pLogMsg, LogLev);
#define LLCLOGMSG2(LogLev, format, ...) saveToLog2(LogLev, format, __VA_ARGS__);
};
 
#endif