-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseMotor.h
276 lines (234 loc) · 5.3 KB
/
BaseMotor.h
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#pragma once
#include "afxmt.h"
//控制卡品牌
enum eMotorBrand
{
eVirtualCard = -1,
eJotCard8,
eJotCard4,
eHYCard,
eLeiSaiCard,
eGTSCard
};
//控制卡类型
enum eMotorType
{
eMotorTypeNone = 0,
eStepType, //步进电机
eServoType, //伺服电机
};
//返回值
#define CARD_OK 1
#define CARD_NG_NOT_HOME -1
#define CARD_NG_OUT_LIMIT -2
#define CARD_NG_NOT_INIT -3
class AFX_CLASS_IMPORT CInBit
{
public:
CInBit(int canno,int cardno,int bitno);
~CInBit();
public:
void SetReverse(int reverse);
int Get();
private:
int m_canno;
int m_cardno;
int m_bitno;
int m_status;
int m_reverse;
};
class AFX_CLASS_IMPORT CAxisInBit
{
public:
CAxisInBit(int canno,int cardno,int bitno);
~CAxisInBit();
public:
void Set(int canno,int cardno,int bitno);
void SetReverse(int reverse);
int Get();
private:
int m_canno;
int m_cardno;
int m_bitno;
int m_status;
int m_reverse;
};
class AFX_CLASS_IMPORT COutBit
{
public:
COutBit(int canno,int cardno,int bitno);
~COutBit();
public:
void Set(int canno,int cardno,int bitno);
void SetReverse(int reverse);
int On();
int Off();
int Get();
private:
int m_canno;
int m_cardno;
int m_bitno;
int m_status;
int m_reverse;
};
class AFX_CLASS_IMPORT COutPWM
{
public:
COutPWM(int canno,int cardno,int bitno);
~COutPWM();
public:
void Set(int canno,int cardno,int bitno);
int Out(int value);
int GetValue();
int OutFreq(int freq);
int GetFreq();
private:
int m_canno;
int m_cardno;
int m_bitno;
int m_value;
int m_cycle;
int m_freq;
};
class AFX_CLASS_IMPORT CBaseMotor
{
public:
CBaseMotor(int canno,int id );
virtual ~CBaseMotor(void);
public:
virtual void SetCardInitOK(BOOL bOK);
virtual int SetMtrID(int id);
virtual int Init();
virtual int Exit();
virtual int LoadConfig();
virtual int SaveConfig();
//运动相关
public:
virtual int ServoOn();
virtual int ServoOff();
virtual int IsAlarm();
virtual int ClearAlarm();
virtual int Home();
virtual int HomeZero();
virtual int GetHomingSts(){return m_bhoming;}
virtual int WaitHome();
virtual int IsHomeOk();
virtual int SetSoftLimit(int limitP,int limitN);
virtual int SetPfPara(int pfno,double stvel,double maxvel,double stopvel,double acc,double dec);
virtual int MoveAbs(int pos);
virtual int MoveAbs(int pos,double dvel);
virtual int MoveRel(int pos);
virtual int MoveRel(int pos,double dvel);
virtual int MmToPulse(double mm);
virtual double PulseToMm(int pulse);
virtual int MoveAbsMm(double pos);
virtual int MoveRelMm(double pos);
virtual int ConstMove(int pos,double dvel);
virtual int ConstMove(int pos);
virtual int ChangePosMove(int pos);
virtual int IsMoving();
virtual int WaitStop();
virtual int StopMove();
//位置相关
public:
virtual int GetPos();
virtual double GetPosMm();
virtual int SetPos(int pos);
virtual int GetEncPos();
virtual int SetEncPos(int pos);
virtual int GetErrorPos();
virtual int SetEncDir(int ifreverse);// 0-不取反, 1-取反
virtual int CheckPosError(int error = 100);
virtual int GetSnr0();
virtual int GetSnr1();
virtual int GetSnr2();
virtual int GetSnrP();
virtual int GetSnrN();
//参数获取设置
public:
int GetMtrID();
int SetMtrName(CString name);
CString GetMtrName();
int SetCanNo(int no);
int GetCanNo();
int SetCardNo(int no);
int GetCardNo();
int SetAxisNo(int no);
int GetAxisNo();
int SetMotor4(int motor4);
int GetIsMotor4();
int SetPerCircleMm(int mm);
int GetPerCircleMm();
int SetPerCirclePulse(int pulse);
int GetPerCirclePulse();
int SetMmPerPulse(double value);
double GetMmPerPulse();
int SetHomeDist(int dist);
int GetHomeDist();
int SetHomeDir(int dir);
int GetHomeDir();
int SetHomeHighStartSpd(double spd);
double GetHomeHighStartSpd();
int SetHomeLowStartSpd(double spd);
double GetHomeLowStartSpd();
int SetLimitP(int pos);
int GetLimitP();
int SetLimitN(int pos);
int GetLimitN();
int SetPf1IniSpd(double spd);
double GetPf1IniSpd();
int SetPf1MaxSpd(double spd);
double GetPf1MaxSpd();
int SetPf1Acc(double acc);
double GetPf1Acc();
int SetPf1Dec(double dec);
double GetPf1Dec();
int SetEncReverse(int reverse);
int GetEncReverse();
int SetStartPos(int pos);
int GetStartPos();
int SetEndPos(int pos);
int GetEndPos();
int SetRelMovePos(int pos);
int GetRelMovePos();
int SetConstMvVel(double vel);
double GetConstMvVel();
int SetConstMvVel_H(double vel);
double GetConstMvVel_H();
public:
BOOL m_bIsHomeOk;
BOOL m_bhoming;
BOOL m_bCardInitOK;
int m_iVirtualPos;
protected:
CCriticalSection m_Lock;
//保存参数
eMotorBrand m_eMotorBrand;
eMotorType m_eMotorType;
int m_iMtrID; //所有马达序号,从0开始
CString strName;
int m_iCanNo;
int m_iCardNo;
int m_iAxisNo;
int m_iIsMotor4;
int m_iPerCircleMm;
int m_iPerCirclePulse;
double m_dMmPerPulse; //每个脉冲mm数
int m_iHomeDist;
int m_iHomeDir;
double m_dHomeHighStartSpd;
double m_dHomeLowStartSpd;
int m_iLimitP;
int m_iLimitN;
double m_dPf1IniSPd;
double m_dPf1MaxSpd;
double m_dPf1StopSpd;
double m_dPf1AccA;
double m_dPf1DecA;
int m_bEncReverse;
int m_iStartPos;
int m_iEndPos;
int m_iRelMovePos;
double m_dConstMvVel;
double m_dConstMvVel_H;
};