-
Notifications
You must be signed in to change notification settings - Fork 0
/
mydobot.cpp
242 lines (192 loc) · 7 KB
/
mydobot.cpp
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
#include "mydobot.h"
#include <QDebug>
MyDobot::MyDobot(QObject *parent) : QObject(parent)
{
}
MyDobot::~MyDobot()
{
DisconnectDobot();
}
void MyDobot::initDobot(QByteArray IPaddress)
{
thisDobotIP = IPaddress;
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
while (SetCmdTimeout(3000) != DobotCommunicate_NoError) {}
while (SetQueuedCmdClear() != DobotCommunicate_NoError) {}
while (SetQueuedCmdStartExec() != DobotCommunicate_NoError) {}
while (GetDeviceSN(deviceSN, sizeof (deviceSN)) != DobotCommunicate_NoError) {}
while (GetDeviceName(deviceName, sizeof(deviceName)) != DobotCommunicate_NoError) {}
//qDebug() << IPaddress << "Device SN:" << deviceSN << "Device name" << deviceName;
setMotor(100, 100);
PTPJumpParams ptpJumpParams;
ptpJumpParams.jumpHeight = 20;
ptpJumpParams.zLimit = 150;
while (SetPTPJumpParams(&ptpJumpParams, false, nullptr) != DobotCommunicate_NoError) {}
}
void MyDobot::setAirPump(int status, int direction)
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
IODO out18;
out18.address = 18;
out18.level = static_cast<uint8_t>(status);
IODO out17;
out17.address = 17;
out17.level = static_cast<uint8_t>(direction);
while (SetIODO(&out17, false, nullptr) != DobotCommunicate_NoError) {}
while (SetIODO(&out18, false, nullptr) != DobotCommunicate_NoError) {}
}
void MyDobot::setOutput(uint8_t address, uint8_t level)
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
IODO out;
out.address = address;
out.level = level;
while (SetIODO(&out, false, nullptr) != DobotCommunicate_NoError) {}
}
void MyDobot::setMotor(int velocity, int acceleration)
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
JOGJointParams jogJointParams;
for (int i = 0; i < 4; i++) {
jogJointParams.velocity[i] = velocity;
jogJointParams.acceleration[i] = acceleration;
}
while (SetJOGJointParams(&jogJointParams, true, nullptr) != DobotCommunicate_NoError) {}
JOGCoordinateParams jogCoordinateParams;
for (int i = 0; i < 4; i++) {
jogCoordinateParams.velocity[i] = velocity;
jogCoordinateParams.acceleration[i] = acceleration;
}
while (SetJOGCoordinateParams(&jogCoordinateParams, true, nullptr) != DobotCommunicate_NoError) {}
JOGCommonParams jogCommonParams;
jogCommonParams.velocityRatio = velocity;
jogCommonParams.accelerationRatio = acceleration;
while (SetJOGCommonParams(&jogCommonParams, true, nullptr) != DobotCommunicate_NoError) {}
PTPJointParams ptpJointParams;
for (int i = 0; i < 4; i++) {
ptpJointParams.velocity[i] = velocity;
ptpJointParams.acceleration[i] = acceleration;
}
while (SetPTPJointParams(&ptpJointParams, true, nullptr) != DobotCommunicate_NoError) {}
PTPCoordinateParams ptpCoordinateParams;
ptpCoordinateParams.xyzVelocity = velocity;
ptpCoordinateParams.xyzAcceleration = acceleration;
ptpCoordinateParams.rVelocity = velocity;
ptpCoordinateParams.rAcceleration = acceleration;
while (SetPTPCoordinateParams(&ptpCoordinateParams, true, nullptr) != DobotCommunicate_NoError) {}
PTPCommonParams ptpCommonParams;
ptpCommonParams.velocityRatio = velocity;
ptpCommonParams.accelerationRatio = acceleration;
while (SetPTPCommonParams(&ptpCommonParams, true, nullptr) != DobotCommunicate_NoError) {}
}
void MyDobot::goHomeSafe()
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
while (SetQueuedCmdClear() != DobotCommunicate_NoError) {}
//goSafe();
Pose position;
while (GetPose(&position) != DobotCommunicate_NoError) {}
PTPCmd safePosition;
safePosition.x = position.x;
safePosition.y = position.y;
safePosition.z = 100;
safePosition.r = 0;
safePosition.ptpMode = PTPMOVJXYZMode;
while (SetPTPCmd(&safePosition, true, nullptr) != DobotCommunicate_NoError) {}
safePosition.x = -150;
safePosition.y = 150;
while (SetPTPCmd(&safePosition, true, nullptr) != DobotCommunicate_NoError) {}
while (SetHOMEWithSwitch(0, true, nullptr) != DobotCommunicate_NoError) {}
//PTPCmd safePosition;
safePosition.x = 400;
safePosition.y = 0;
safePosition.z = 100;
safePosition.r = 0;
while (SetPTPCmd(&safePosition, true, nullptr) != DobotCommunicate_NoError) {}
safePosition.x = -150;
safePosition.y = 150;
while (SetPTPCmd(&safePosition, true, nullptr) != DobotConnect_NoError) {}
}
void MyDobot::goHome()
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
SetQueuedCmdClear();
while (SetHOMEWithSwitch(0, true, nullptr) != DobotCommunicate_NoError) {}
}
void MyDobot::goSafe()
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
Pose position;
while (GetPose(&position) != DobotCommunicate_NoError) {}
PTPCmd safePosition;
safePosition.x = position.x;
safePosition.y = position.y;
safePosition.z = 100;
safePosition.r = 0;
safePosition.ptpMode = PTPMOVJXYZMode;
while (SetPTPCmd(&safePosition, true, nullptr) != DobotCommunicate_NoError) {}
safePosition.x = -150;
safePosition.y = 150;
while (SetPTPCmd(&safePosition, true, nullptr) != DobotCommunicate_NoError) {}
}
Pose MyDobot::getCurrentPosition()
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
while (GetPose(¤tPosition) != DobotCommunicate_NoError) {}
return currentPosition;
}
void MyDobot::goPosition(float x, float y, float z, float r)
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
PTPCmd PTPCmd;
PTPCmd.ptpMode = PTPMOVJXYZMode;
PTPCmd.x = x;
PTPCmd.y = y;
PTPCmd.z = z;
PTPCmd.r = r;
while (SetPTPCmd(&PTPCmd, true, nullptr) != DobotCommunicate_NoError) {}
}
void MyDobot::goPositionStraight(float x, float y, float z, float r)
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
PTPCmd PTPCmd;
PTPCmd.ptpMode = PTPMOVLXYZMode;
PTPCmd.x = x;
PTPCmd.y = y;
PTPCmd.z = z;
PTPCmd.r = r;
while (SetPTPCmd(&PTPCmd, true, nullptr) != DobotCommunicate_NoError) {}
}
void MyDobot::goJog(int index)
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
JOGCmd jogCmd;
jogCmd.isJoint = index > 8;
if (index > 8) index -= 8;
jogCmd.cmd = static_cast<uint8_t>(index);
//while (SetJOGCmd(&jogCmd, false, nullptr) != DobotCommunicate_NoError) {}
SetJOGCmd(&jogCmd, false, nullptr);
}
alarmState MyDobot::getAlarms()
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
alarmState result;
uint32_t len, maxLen = 32;
while (GetAlarmsState(result.value, &len, maxLen) != DobotCommunicate_NoError) {}
return result;
}
void MyDobot::clearAlarms()
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
while (ClearAllAlarmsState() != DobotCommunicate_NoError) {}
}
void MyDobot::clearQueue()
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
while (SetQueuedCmdClear() != DobotCommunicate_NoError) {}
}
QString MyDobot::getName()
{
ConnectDobot(thisDobotIP, 115200, nullptr, nullptr);
return QString(deviceName);
}