-
Notifications
You must be signed in to change notification settings - Fork 1
/
rb-cobot.h
280 lines (211 loc) · 6.42 KB
/
rb-cobot.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
277
278
279
280
#ifndef COBOT_H
#define COBOT_H
#ifdef RB_EXPORTS
#define COBOT_DECLSPEC __declspec(dllexport)
#else
#define COBOT_DECLSPEC __declspec(dllimport)
#endif
#include "rb-common-header.h"
#include "rb-point.h"
#include "rb-joint.h"
using namespace std;
#include <thread>
#include <WinSock2.h>
#pragma comment(lib, "ws2_32")
namespace rb {
//프로그램 모드
enum class PG_MODE {
SIMULATION,
REAL
};
//원동작 타입
enum class CIRCLE_TYPE {
INTENDED,
CONSTANT,
RADIAL,
SMOOTH
};
//원동작 타입
enum class CIRCLE_AXIS {
X,
Y,
Z
};
enum class BLEND_OPTION {
RATIO,
DISTANCE
};
enum class BLEND_RTYPE {
INTENDED,
CONSTANT
};
enum class ITPL_RTYPE {
INTENDED,
CONSTANT,
RESERVED1,
SMOOTH,
RESERVED2,
CA_INTENDED,
CA_CONSTANT,
RESERVED3,
CA_SMOOTH
};
enum class DOUT_SET {
LOW,
HIGH,
BYPASS
};
//디지털 출력 전압
enum class DOUT_VOLT {
VOLT_0,
VOLT_12,
VOLT_24
};
//협동로봇 상태
enum class COBOT_STATUS {
IDLE,
PAUSED,
RUNNING,
UNKNOWN
};
//제어박스 디지털 출력 신호
const int SIGNAL_BYPASS = -1;
const int SIGNAL_LOW = 0;
const int SIGNAL_HIGH = 1;
//제어박스 디지털 출력 포트
using DOUT_PORT = struct dout_port{
int d0 = SIGNAL_BYPASS; int d1 = SIGNAL_BYPASS; int d2 = SIGNAL_BYPASS; int d3 = SIGNAL_BYPASS;
int d4 = SIGNAL_BYPASS; int d5 = SIGNAL_BYPASS; int d6 = SIGNAL_BYPASS; int d7 = SIGNAL_BYPASS;
int d8 = SIGNAL_BYPASS; int d9 = SIGNAL_BYPASS; int d10 = SIGNAL_BYPASS; int d11 = SIGNAL_BYPASS;
int d12 = SIGNAL_BYPASS; int d13 = SIGNAL_BYPASS; int d14 = SIGNAL_BYPASS; int d15 = SIGNAL_BYPASS;
};
class COBOT_DECLSPEC Cobot
{
public:
Cobot();
virtual ~Cobot();
//제어박스와 통신 연결
bool ConnectToCB(string ip="10.0.2.7");
bool ConnectToCMD(string ip = "10.0.2.7");
bool ConnectToData(string ip = "10.0.2.7");
string __Version();
//협동로봇 초기화
bool CobotInit();
//협동로봇 프로그램 모드 설정
bool SetProgramMode(PG_MODE mode);
//현재 로봇의 관절 각도값 획득
Joint GetCurrentJoint();
tuple<float, float, float, float, float, float> GetCurrentSplitedJoint();
//현재 로봇의 TCP 위치 획득
Point GetCurrentTCP();
tuple<float, float, float, float, float, float> GetCurrentSplitedTCP();
//현재 로봇의 관절 각도 값, TCP 위치 획득
tuple<Joint, Point> GetCurrentJP();
//협동로봇 속도 설정
bool SetBaseSpeed(float spd);
//협동로봇 일시정지
bool MotionPause();
//협동로봇 정지
bool MotionHalt();
//협동로봇 일시정지 재개
bool MotionResume();
//협동로봇 충돌정지 재개
bool CollisionResume();
//Move Linear
bool MoveL(Point p, float spd, float acc);
bool MoveL(float x, float y, float z, float rx, float ry, float rz, float spd, float acc);
//Move Joint
bool MoveJ(Joint j, float spd, float acc);
bool MoveJ(float j0, float j1, float j2, float j3, float j4, float j5, float spd, float acc);
//Move JL
bool MoveJL(float x, float y, float z, float rx, float ry, float rz, float spd, float acc);
bool MoveJL(Point p, float spd, float acc);
//Move Joint Blend
bool MoveJB_Clear();
bool MoveJB_Add(Joint j);
bool MoveJB_Add(float j0, float j1, float j2, float j3, float j4, float j5);
bool MoveJB_Run(float spd, float acc);
//Move Linear Blend
bool MovePB_Clear();
bool MovePB_Add(Point p, float spd, BLEND_OPTION option, float quantity);
bool MovePB_Add(float x, float y, float z, float rx, float ry, float rz, float spd, BLEND_OPTION option, float quantity);
bool MovePB_Run(float acc, BLEND_RTYPE type);
//Move Interpolation
bool MoveITPL_Clear();
bool MoveITPL_Add(Point p, float spd);
bool MoveITPL_Add(float x, float y, float z, float rx, float ry, float rz, float spd);
bool MoveITPL_Run(float acc, ITPL_RTYPE type);
//원 동작
bool MoveCircle_ThreePoint(float x1, float y1, float z1, float rx1, float ry1, float rz1, float x2, float y2, float z2, float rx2, float ry2, float rz2, float spd, float acc, CIRCLE_TYPE type);
bool MoveCircle_ThreePoint(Point p1, Point p2, float spd, float acc, CIRCLE_TYPE type);
bool MoveCircle_Axis(float x1, float y1, float z1, float rx1, float ry1, float rz1, CIRCLE_AXIS axis, float angle, float spd, float acc, CIRCLE_TYPE type);
bool MoveCircle_Axis(Point p1, CIRCLE_AXIS axis, float angle, float spd, float acc, CIRCLE_TYPE type);
//제어박스 디지털 출력
//bool ControlBoxDigitalOut(DOUT_PORT port);
//bool ControlBoxDigitalOut(int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7, int d8, int d9, int d10, int d11, int d12, int d13, int d14, int d15);
bool CBDigitalOut(float port, DOUT_SET type);
bool CBAnalogOut(float port, float volt);
//제어박스 아날로그 출력
//bool ControlBoxAnalogOut(float a0, float a1, float a2, float a3);
//툴플렌지 출력
//bool ToolDigitalOut(int d0, int d1, DOUT_VOLT volt);
//로봇팔 전원 차단
bool RobotPowerDown(void);
//default: 30ms
void SetWaitTime(int millisec);
//협동로봇 idle 유무
bool IsIdle();
//협동로봇 일시정지 유무
bool IsPause();
//협동로봇 활성화 유무
bool IsInitialized();
//협동로봇 동작 모드
bool IsRobotReal();
//커맨드 소켓 연결 확인
bool IsCommandSockConnect();
//데이터 소켓 연결 확인
bool IsDataSockConnect();
//스크립트 직접 작성
bool ManualScript(string ex_msg);
//협동로봇 현재 상태
COBOT_STATUS GetCurrentCobotStatus();
private:
void ReadCmd();
void ReadData();
void RunThread();
void RunCMDThread();
void RunDataThread();
void ReqDataStart();
bool isValidIP(string ip);
bool socketCmdCom(string ip);
bool socketCmdClose();
bool cmd_conneted = false;
bool data_conneted = false;
bool socketDataCom(string ip);
bool socketDataClose();
Point current_tcp_;
Joint current_joint_;
string ip_address_;
systemSTAT systemStat;
systemCONFIG systemConfig;
systemPOPUP systemPopup;
bool initFlag = false;
bool cmdConfirmFlag = true;
bool moveCmdFlag = false;
int moveCmdCnt = 0;
int CMD_CLIENT_FD_ = 0;
int DATA_CLIENT_FD_ = 0;
struct sockaddr_in cmd_addr_;
struct sockaddr_in data_addr_;
int wait_time_ = 30;
bool bReadCmd = false;
vector<char> recv_buf_;
thread proc1;
thread proc2;
thread proc3;
thread proc4_cmd;
thread proc5_datareq;
thread proc6_dataread;
};
}
#endif