GrooveComputerTool.cs
27.9 KB
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
using HHECS.BllModel;
using HHECS.RobotTool.Dto;
using System.Numerics;
namespace HHECS.RobotTool.Utils
{
/// <summary>
/// 坡口计算工具
/// </summary>
internal static class GrooveComputerTool
{
/// <summary>
/// 获取计算结果
/// </summary>
/// <param name="parameter">输入参数</param>
/// <returns>[2024/11/29]</returns>
public static BllResult<RobotOutputParameter> GetComputedData(RobotInputParameter parameter)
{
try
{
var output = new RobotOutputParameter();
double WeldAttitudeAngle = 0;
var layermod = (parameter.GrooveDepth + parameter.WeldHeight) % parameter.OneWeldHeight;//计算层数的余数
//总层数
var layerValue = (parameter.GrooveDepth + parameter.WeldHeight) / parameter.OneWeldHeight;
//如果剩余高度大于四,则向上取整,否则向下
output.Layers = (int)(layermod >= 4 ? Math.Ceiling(layerValue) : Math.Floor(layerValue));
//多层多道算法
if (parameter.GrooveWidth > 30)
{
//遍历每层进行计算
for (int i = 1; i <= output.Layers; i++)
{
var layerModel = new LayerModel
{
CurrentLayer = i, //当前层
};
var weldTotal = GetWeldTotal(i, parameter, layermod);
var iLayerWeldUpTotal = GetWeldUpTotal(i, output.Layers, parameter, layermod);
layerModel.WeldTotal = weldTotal;
layerModel.WeldUpTotal = iLayerWeldUpTotal;
var zCompensation = 0f;
if (layermod < 4)
{
zCompensation = layermod;
}
//第一层
if (i == 1)
{
//一层一道
var channelModel = new ChannelModel
{
CurrentChannel = 1,
StartingPoint = new Vector3(0, 0, 0),
EndingPoint = new Vector3(parameter.WeldLength, 0, 0),
WeldAttitudeAngle = 0,
WeldWidth = layerModel.WeldTotal / i,
};
layerModel.LayerHeight = parameter.OneWeldHeight + zCompensation;
//焊接截面积
channelModel.WeldArea = parameter.GrooveWidth * Math.Pow(parameter.OneWeldHeight + zCompensation, 2) / (2 * parameter.GrooveDepth);
//焊接速度
channelModel.WeldSpeed = Math.PI * Math.Pow(parameter.WeldingWire, 2) * (parameter.OneLayerWireFeedingSpeed / (channelModel.WeldArea * 4));
//振幅为三角形焊缝的上底
var weldAmplitude = layerModel.WeldUpTotal / 2 - 2;
channelModel.WeldAmplitude = weldAmplitude;
//频率、左右停留时间
layerModel.LeftAndRightDwellTime = GetLeftAndRightDwellTime(weldAmplitude);
layerModel.WeldSwingFrequency = GetWeldSwingFrequency(weldAmplitude);
layerModel.ChannelModels.Add(channelModel);
output.LayerModels.Add(layerModel);
continue;
}
//其他层
if (i >= 2 && i < output.Layers)
{
layerModel.LayerHeight = parameter.OneWeldHeight;
//遍历每层每个焊缝进行计算
for (int j = 1; j <= i; j++)
{
var oneWeldWidth = weldTotal / i; //第i层有i条焊缝,且每条焊缝宽度相同 di
var channelModel = new ChannelModel
{
CurrentChannel = j,
WeldWidth = oneWeldWidth,
};
if (j == 1)//梯形焊缝
{
//起点和终点
var startingPoint = new Vector3(0, -weldTotal / 2, (i - 1) * parameter.OneWeldHeight + zCompensation);
var endingPoint = new Vector3(parameter.WeldLength, -weldTotal / 2, (i - 1) * parameter.OneWeldHeight + zCompensation);
channelModel.StartingPoint = startingPoint;
channelModel.EndingPoint = endingPoint;
//姿态角计算
double k1 = -2 * parameter.GrooveDepth / parameter.GrooveWidth; //AB所在直线的斜率k1
double k2 = 2 * parameter.GrooveDepth / parameter.GrooveWidth; //AC所在直线的斜率k2
double kijB = (i * parameter.OneWeldHeight - parameter.GrooveDepth) / (parameter.GrooveWidth / (2 - weldTotal / 2 + (j - 1) * oneWeldWidth)); //起点与点B连线所在直线的斜率kijB
double kijC = (parameter.GrooveDepth - i * parameter.OneWeldHeight) / (parameter.GrooveWidth / (2 + weldTotal / 2 - (j - 1) * oneWeldWidth)); //起点与点C连线所在直线的斜率kijC
double tanValue1 = (kijB - kijC) / (1 + kijB * kijC); //起点与点B和C连线的夹角正切值;
double tanValue2 = (k1 - k2) / (1 + k1 * k2); //AB和AC夹角正切值;
double tanRadianValue1 = Math.Atan(Math.Abs(tanValue1)); //弧度值
double tanRadianValue2 = Math.Atan(Math.Abs(tanValue2)); //弧度值
double tanAngleValue1 = tanRadianValue1 / Math.PI * 180; //角度值
double tanAngleValue2 = tanRadianValue2 / Math.PI * 180; //角度值
WeldAttitudeAngle = tanAngleValue1 / 2 - tanAngleValue2 / 2;//取反中间值
channelModel.WeldAttitudeAngle = tanAngleValue1 / 2 - tanAngleValue2 / 2;
var iLayerjthWeldArea = parameter.OneWeldHeight / 2 * (2 * iLayerWeldUpTotal / i + weldTotal / 2 - iLayerWeldUpTotal / 2);
channelModel.WeldArea = iLayerjthWeldArea;
//焊接速度
channelModel.WeldSpeed = Math.PI * Math.Pow(parameter.WeldingWire, 2) * (parameter.WireFeedingSpeed / (iLayerjthWeldArea * 4));
layerModel.ChannelModels.Add(channelModel);
continue;
}
if (j > 1 & j < i)
{
//起点和终点
var startingPoint = new Vector3(0, -iLayerWeldUpTotal / 2 + (j - 0.5f) * iLayerWeldUpTotal / i, (i - 1) * parameter.OneWeldHeight + zCompensation);
var endingPoint = new Vector3(parameter.WeldLength, -iLayerWeldUpTotal / 2 + (j - 0.5f) * iLayerWeldUpTotal / i, (i - 1) * parameter.OneWeldHeight + zCompensation);
channelModel.StartingPoint = startingPoint;
channelModel.EndingPoint = endingPoint;
//姿态角计算
channelModel.WeldAttitudeAngle = 0;
var iLayerjthWeldArea = parameter.OneWeldHeight * iLayerWeldUpTotal / i;
channelModel.WeldArea = iLayerjthWeldArea;
//焊接速度
channelModel.WeldSpeed = Math.PI * Math.Pow(parameter.WeldingWire, 2) * (parameter.WireFeedingSpeed / (iLayerjthWeldArea * 4));
}
///最后一条梯形焊缝
else
{
//起点、终点、姿态角
var startingPoint = new Vector3(0, weldTotal / 2, (i - 1) * parameter.OneWeldHeight + zCompensation);
var endingPoint = new Vector3(parameter.WeldLength, weldTotal / 2, (i - 1) * parameter.OneWeldHeight + zCompensation);
channelModel.StartingPoint = startingPoint;
channelModel.EndingPoint = endingPoint;
///姿态角计算
channelModel.WeldAttitudeAngle = WeldAttitudeAngle * -1;
//焊接速度
var iLayerjthWeldArea = parameter.OneWeldHeight / 2 * (2 * iLayerWeldUpTotal / i + weldTotal / 2 - iLayerWeldUpTotal / 2);
channelModel.WeldArea = iLayerjthWeldArea;
channelModel.WeldSpeed = Math.PI * Math.Pow(parameter.WeldingWire, 2) * (parameter.WireFeedingSpeed / (iLayerjthWeldArea * 4));
}
layerModel.ChannelModels.Add(channelModel);
}
output.LayerModels.Add(layerModel);
continue;
}
//最后一层(盖面层)
else
{
//总焊接截面积(mm²)
var totalWeldArea = parameter.GrooveWidth * parameter.GrooveDepth / 2 + (parameter.GrooveWidth * 2 + parameter.WeldWidth * 2) * parameter.WeldHeight / 2;
// 总熔敷量(mm³)
var totalDepositionAmount = totalWeldArea * parameter.WeldLength; //熔敷量与焊接横截面积成正比
//最后一层实际高度
layerModel.LayerHeight = parameter.GrooveDepth + parameter.WeldHeight - ((output.Layers - 1) * parameter.OneWeldHeight + zCompensation);
//遍历每层每个焊缝进行计算
for (int j = 1; j <= i; j++)
{
var oneWeldWidth = weldTotal / i; //第i层有i条焊缝,且每条焊缝宽度相同 di
var channelModel = new ChannelModel
{
CurrentChannel = j,
WeldWidth = oneWeldWidth,
};
if (j == 1)//梯形焊缝
{
//起点和终点
var startingPoint = new Vector3(0, -weldTotal / 2, (i - 1) * parameter.OneWeldHeight + zCompensation);
var endingPoint = new Vector3(parameter.WeldLength, -weldTotal / 2, (i - 1) * parameter.OneWeldHeight + zCompensation);
channelModel.StartingPoint = startingPoint;
channelModel.EndingPoint = endingPoint;
///姿态角计算
double k1 = -2 * parameter.GrooveDepth / parameter.GrooveWidth; //AB所在直线的斜率k1
double k2 = 2 * parameter.GrooveDepth / parameter.GrooveWidth; //AC所在直线的斜率k2
double kijB = (i * parameter.OneWeldHeight - parameter.GrooveDepth) / (parameter.GrooveWidth / (2 - weldTotal / 2 + (j - 1) * oneWeldWidth)); //起点与点B连线所在直线的斜率kijB
double kijC = ((float)parameter.GrooveDepth - i * (float)parameter.OneWeldHeight) / ((float)parameter.GrooveWidth / (2 + weldTotal / 2 - (j - 1) * oneWeldWidth)); //起点与点C连线所在直线的斜率kijC
double tanValue1 = (kijB - kijC) / (1 + kijB * kijC); //起点与点B和C连线的夹角正切值;
double tanValue2 = (k1 - k2) / (1 + k1 * k2); //AB和AC夹角正切值;
double tanRadianValue1 = Math.Atan(Math.Abs(tanValue1)); //弧度值
double tanRadianValue2 = Math.Atan(Math.Abs(tanValue2)); //弧度值
double tanAngleValue1 = tanRadianValue1 / Math.PI * 180; //角度值
double tanAngleValue2 = tanRadianValue2 / Math.PI * 180; //角度值
WeldAttitudeAngle = tanAngleValue1 / 2 - tanAngleValue2 / 2;
channelModel.WeldAttitudeAngle = tanAngleValue1 / 2 - tanAngleValue2 / 2;
var iLayerjthWeldArea = 0f;
//焊接速度
if (layermod >= 4)
{
iLayerjthWeldArea = layermod / 2 * (2 * iLayerWeldUpTotal / i + weldTotal / 2 - iLayerWeldUpTotal / 2);
}
else
{
iLayerjthWeldArea = (parameter.OneWeldHeight) / 2 * (2 * iLayerWeldUpTotal / i + weldTotal / 2 - iLayerWeldUpTotal / 2);
}
channelModel.WeldSpeed = Math.PI * Math.Pow(parameter.WeldingWire, 2) * (parameter.WireFeedingSpeed / (iLayerjthWeldArea * 4));
layerModel.ChannelModels.Add(channelModel);
continue;
}
if (j > 1 & j < i)
{
//起点和终点
var startingPoint = new Vector3(0, -iLayerWeldUpTotal / 2 + (j - 0.5f) * iLayerWeldUpTotal / i, (i - 1) * parameter.OneWeldHeight + zCompensation);
var endingPoint = new Vector3((float)parameter.WeldLength, Convert.ToSingle(-iLayerWeldUpTotal / 2 + (j - 0.5) * iLayerWeldUpTotal / i), (i - 1) * (float)parameter.OneWeldHeight + zCompensation);
channelModel.StartingPoint = startingPoint;
channelModel.EndingPoint = endingPoint;
///姿态角计算
channelModel.WeldAttitudeAngle = 0;
var iLayerjthWeldArea = 0f;
if (layermod >= 4)
{
iLayerjthWeldArea = layermod * iLayerWeldUpTotal / i;
}
else
{
iLayerjthWeldArea = parameter.OneWeldHeight * iLayerWeldUpTotal / i;
}
//焊接速度
channelModel.WeldSpeed = Math.PI * Math.Pow(parameter.WeldingWire, 2) * (parameter.WireFeedingSpeed / (iLayerjthWeldArea * 4));
layerModel.ChannelModels.Add(channelModel);
}
///最后一条梯形焊缝
else
{
//起点、终点、姿态角
var startingPoint = new Vector3(0, weldTotal / 2, (i - 1) * parameter.OneWeldHeight + zCompensation);
var endingPoint = new Vector3(parameter.WeldLength, weldTotal / 2, (i - 1) * parameter.OneWeldHeight + zCompensation);
channelModel.StartingPoint = startingPoint;
channelModel.EndingPoint = endingPoint;
///姿态角计算
channelModel.WeldAttitudeAngle = WeldAttitudeAngle * -1;
var iLayerjthWeldArea = 0d;
//焊接速度
if (layermod >= 4)
{
iLayerjthWeldArea = (layermod) / 2 * (2 * iLayerWeldUpTotal / i + weldTotal / 2 - iLayerWeldUpTotal / 2);
}
else
{
iLayerjthWeldArea = (parameter.OneWeldHeight) / 2 * (2 * iLayerWeldUpTotal / i + weldTotal / 2 - iLayerWeldUpTotal / 2);
}
channelModel.WeldSpeed = Math.PI * Math.Pow(parameter.WeldingWire, 2) * (parameter.WireFeedingSpeed / (iLayerjthWeldArea * 4));
layerModel.ChannelModels.Add(channelModel);
}
}
output.LayerModels.Add(layerModel);
}
}
return BllResultFactory.Success(output);
}
//多层单道算法
//遍历每层进行计算
for (int i = 1; i <= output.Layers; i++)
{
var weldTotal = GetWeldTotal(i, parameter, layermod);
var iLayerWeldUpTotal = GetWeldUpTotal(i, output.Layers, parameter, layermod);
var zCompensation = 0f;
if (layermod < 4)
{
zCompensation = layermod;
}
var layerModel = new LayerModel
{
CurrentLayer = i,
WeldTotal = weldTotal,
WeldUpTotal = iLayerWeldUpTotal,
};
///第一层
if (i == 1)
{
layerModel.LayerHeight = parameter.OneWeldHeight + zCompensation;
var channelModel = new ChannelModel
{
CurrentChannel = 1,
StartingPoint = new Vector3(0, 0, 0),
EndingPoint = new Vector3(parameter.WeldLength, 0, 0),
WeldAttitudeAngle = 0,
};
// 第一层(打底)焊接截面积(mm²)
var oneLayerWeldArea = parameter.GrooveWidth * Math.Pow(parameter.OneWeldHeight + zCompensation, 2) / (2 * parameter.GrooveDepth);
channelModel.WeldArea = oneLayerWeldArea;
//焊接速度
channelModel.WeldSpeed = Math.PI * Math.Pow(parameter.WeldingWire, 2) * (parameter.OneLayerWireFeedingSpeed / (oneLayerWeldArea * 4));
//振幅为上底
var weldAmplitude = iLayerWeldUpTotal / 2 - 2;
channelModel.WeldAmplitude = weldAmplitude;
//频率、左右停留时间
layerModel.LeftAndRightDwellTime = GetLeftAndRightDwellTime(weldAmplitude);
layerModel.WeldSwingFrequency = GetWeldSwingFrequency(weldAmplitude);
layerModel.ChannelModels.Add(channelModel);
output.LayerModels.Add(layerModel);
continue;
}
//其他层
if (i >= 2 && i < output.Layers)
{
var channelModel = new ChannelModel
{
CurrentChannel = 1,
WeldAttitudeAngle = 0,
StartingPoint = new Vector3(0, 0, (i - 1) * parameter.OneWeldHeight + zCompensation),
EndingPoint = new Vector3(parameter.WeldLength, 0, (i - 1) * parameter.OneWeldHeight + zCompensation)
};
layerModel.LayerHeight = parameter.OneWeldHeight;
var weldArea = (iLayerWeldUpTotal + weldTotal) * parameter.OneWeldHeight / 2;
channelModel.WeldArea = weldArea;
//焊接速度
channelModel.WeldSpeed = Math.PI * Math.Pow(parameter.WeldingWire, 2) * (parameter.OneLayerWireFeedingSpeed / (weldArea * 4));
//振幅为上底
var weldAmplitude = iLayerWeldUpTotal / 2 - 2;
channelModel.WeldAmplitude = weldAmplitude;
//频率、左右停留时间
layerModel.LeftAndRightDwellTime = GetLeftAndRightDwellTime(weldAmplitude);
layerModel.WeldSwingFrequency = GetWeldSwingFrequency(weldAmplitude);
layerModel.ChannelModels.Add(channelModel);
}
//最后一层(盖面层)
else
{
layerModel.LayerHeight = parameter.GrooveDepth + parameter.WeldHeight - ((output.Layers - 1) * parameter.OneWeldHeight + zCompensation);
//总焊接截面积(mm²)
var totalWeldArea = parameter.GrooveWidth * parameter.GrooveDepth / 2 + (parameter.GrooveWidth * 2 + parameter.WeldWidth * 2) * parameter.WeldHeight / 2;
//总熔敷量(mm³)
var totalDepositionAmount = totalWeldArea * parameter.WeldLength; //熔敷量与焊接横截面积成正比
var channelModel = new ChannelModel
{
CurrentChannel = 1,
WeldAttitudeAngle = 0,
WeldAmplitude = 0,
StartingPoint = new Vector3(0, 0, (i - 1) * parameter.OneWeldHeight + zCompensation),
EndingPoint = new Vector3(parameter.WeldLength, 0, (i - 1) * parameter.OneWeldHeight + zCompensation)
};
var weldArea = 0d;
if (layermod >= 4)
{
weldArea = (parameter.GrooveWidth + weldTotal) * layermod / 2;
}
else
{
weldArea = (parameter.GrooveWidth + weldTotal) * parameter.OneWeldHeight / 2;
//振幅为上底
var weldAmplitude = parameter.GrooveWidth / 2 - 2;
channelModel.WeldAmplitude = weldAmplitude;
//频率、左右停留时间
layerModel.LeftAndRightDwellTime = GetLeftAndRightDwellTime(weldAmplitude);
layerModel.WeldSwingFrequency = GetWeldSwingFrequency(weldAmplitude);
}
//焊接速度
channelModel.WeldSpeed = Math.PI * Math.Pow(parameter.WeldingWire, 2) * (parameter.OneLayerWireFeedingSpeed / (weldArea * 4));
layerModel.ChannelModels.Add(channelModel);
}
output.LayerModels.Add(layerModel);
}
return BllResultFactory.Success(output);
}
catch (Exception ex)
{
return BllResultFactory.Error<RobotOutputParameter>(ex.Message);
}
}
/// <summary>
/// 获取总焊宽
/// </summary>
/// <param name="currentLayer">当前层</param>
/// <param name="totalLayer">总层数</param>
/// <param name="parameter">输入参数</param>
/// <param name="layerMod">计算层数的余数</param>
/// <remarks>1-i-1层上下焊宽算法</remarks>
/// <returns></returns>
private static float GetWeldTotal(int currentLayer, RobotInputParameter parameter, float layerMod)
{
if (currentLayer == 0)
{
return 0;
}
if (layerMod >= 4)
{
return (currentLayer - 1) * parameter.OneWeldHeight * parameter.GrooveWidth / parameter.GrooveDepth;
}
return ((currentLayer - 1) * parameter.OneWeldHeight + layerMod) * parameter.GrooveWidth / parameter.GrooveDepth;
}
/// <summary>
/// 获取上底宽
/// </summary>
/// <param name="currentLayer">当前层</param>
/// <param name="totalLayer">总层数</param>
/// <param name="parameter">输入参数</param>
/// <param name="layerMod">计算层数的余数</param>
/// <remarks>1-i-1层上下焊宽算法</remarks>
/// <returns></returns>
private static float GetWeldUpTotal(int currentLayer, int totalLayer, RobotInputParameter parameter, float layerMod)
{
if (currentLayer == 0)
{
return 0;
}
if (currentLayer != totalLayer) //1-i-1层上下焊宽算法
{
if (layerMod >= 4)
{
return currentLayer * parameter.OneWeldHeight * parameter.GrooveWidth / parameter.GrooveDepth;
}
return (currentLayer * parameter.OneWeldHeight + layerMod) * parameter.GrooveWidth / parameter.GrooveDepth;
}
return parameter.GrooveWidth + parameter.WeldWidth * 2;
}
/// <summary>
/// 获取左右停留时间
/// </summary>
/// <param name="weldAmplitude">振幅</param>
/// <returns></returns>
private static float GetWeldSwingFrequency(float weldAmplitude)
{
// 焊接频率
if (weldAmplitude == 0)
{
return 0;
}
if (5.5 / weldAmplitude >= 2.5)
{
return 2.5f;
}
if (5.5 / weldAmplitude < 1)
{
return 0.8f;
}
if (5.5 / weldAmplitude > 1 && 5.5 / weldAmplitude < 2.5)
{
return (float)Math.Round(5.5 / weldAmplitude, 1);
}
return default;
}
/// <summary>
/// 获取左右停留时间
/// </summary>
/// <param name="weldAmplitude">振幅</param>
/// <returns></returns>
private static float GetLeftAndRightDwellTime(float weldAmplitude)
{
if (weldAmplitude <= 1.5)
{
return 0;
}
if (weldAmplitude > 1.5 && weldAmplitude <= 2.5)
{
return 0.01f;
}
if (weldAmplitude > 2.5 && weldAmplitude <= 3.5)
{
return 0.02f;
}
if (weldAmplitude > 3.5 && weldAmplitude <= 4.5)
{
return 0.05f;
}
if (weldAmplitude > 4.5 && weldAmplitude <= 6)
{
return 0.1f;
}
if (weldAmplitude > 6)
{
return 0.15f;
}
return default;
}
}
}