PathModels.cs
14.2 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
492
493
494
495
496
497
498
499
using System;
using System.Collections.Generic;
using Rcs.Application.Services;
using Rcs.Domain.Entities;
using Rcs.Domain.Enums;
namespace Rcs.Application.Services.PathFind.Models
{
/// <summary>
/// 寻路请求
/// @author zzy
/// </summary>
public class PathRequest
{
/// <summary>
/// 请求机器人ID
/// </summary>
public Guid RobotId { get; set; }
/// <summary>
/// 地图ID
/// </summary>
public Guid MapId { get; set; }
/// <summary>
/// 起始节点ID
/// </summary>
public Guid StartNodeId { get; set; }
/// <summary>
/// 目标节点ID
/// </summary>
public Guid EndNodeId { get; set; }
/// <summary>
/// 当前航向角(弧度)
/// </summary>
public double CurrentTheta { get; set; }
/// <summary>
/// 是否载货
/// </summary>
public bool IsLoaded { get; set; }
/// <summary>
/// 任务优先级(数值越大优先级越高)
/// </summary>
public int Priority { get; set; }
/// <summary>
/// 电池电量(0-100)
/// </summary>
public int BatteryLevel { get; set; }
/// <summary>
/// 最大等待时间(秒)
/// </summary>
public int MaxWaitTime { get; set; } = 30;
/// <summary>
/// 车辆支持的行驶方向角度列表(弧度),如[0, π]表示支持正向和倒车
/// @author zzy
/// </summary>
public List<double> VehicleOrientationAngles { get; set; } = new() { 0, Math.PI };
/// <summary>
/// 默认构造函数,设置默认值为弧度
/// @author zzy
/// </summary>
/// <summary>
/// 取货与车头方向的夹角(弧度),0表示货叉在车头方向,π表示货叉在车尾方向,为空则表示任意方向
/// @author zzy
/// </summary>
public List<double>? ForkRadOffsets{ get; set; }
/// <summary>
/// 终点要求的朝向(弧度),用于取货/放货时的车头方向约束
/// 为null时不约束终点朝向
/// @author zzy
/// </summary>
public double? RequiredEndRad { get; set; }
}
/// <summary>
/// 寻路结果
/// @author zzy
/// </summary>
public class PathResult
{
/// <summary>
/// 是否成功
/// </summary>
public bool Success { get; set; }
/// <summary>
/// 错误信息
/// </summary>
public string? ErrorMessage { get; set; }
/// <summary>
/// 路径节点列表
/// </summary>
public List<PathSegment> Segments { get; set; } = new();
/// <summary>
/// 总路径长度
/// </summary>
public double TotalLength { get; set; }
/// <summary>
/// 总代价
/// </summary>
public double TotalCost { get; set; }
/// <summary>
/// 计算耗时(毫秒)
/// </summary>
public long ComputeTimeMs { get; set; }
/// <summary>
/// 是否需要等待
/// </summary>
public bool NeedWait { get; set; }
/// <summary>
/// 等待节点ID
/// </summary>
public Guid? WaitNodeId { get; set; }
/// <summary>
/// 建议等待时间(秒)
/// </summary>
public int SuggestedWaitTime { get; set; }
}
/// <summary>
/// 路径段
/// @author zzy
/// </summary>
public class PathSegment
{
/// <summary>
/// 边ID
/// </summary>
public Guid EdgeId { get; set; }
/// <summary>
/// 起始节点ID
/// </summary>
public Guid FromNodeId { get; set; }
/// <summary>
/// 目标节点ID
/// </summary>
public Guid ToNodeId { get; set; }
/// <summary>
/// 车头和路径方向的夹角(弧度)
/// @author zzy
/// </summary>
public double Angle { get; set; }
/// <summary>
/// 段长度
/// </summary>
public double Length { get; set; }
/// <summary>
/// 最大速度限制
/// </summary>
public double? MaxSpeed { get; set; }
/// <summary>
/// 进入该段需要的航向角
/// </summary>
public double RequiredAngle { get; set; }
}
/// <summary>
/// 带Code的路径段(用于统一锁管理)
/// @author zzy
/// 2026-02-06 更新:添加网络动作类型映射
/// </summary>
public class PathSegmentWithCode : PathSegment
{
/// <summary>
/// 边编码
/// </summary>
public string EdgeCode { get; set; } = string.Empty;
/// <summary>
/// 起始节点编码
/// </summary>
public string FromNodeCode { get; set; } = string.Empty;
/// <summary>
/// 目标节点编码
/// </summary>
public string ToNodeCode { get; set; } = string.Empty;
/// <summary>
/// 起始节点(FromNode)的动作ID列表
/// @author zzy
/// </summary>
public List<StepAction> StartNodeActions { get; set; } = new();
/// <summary>
/// 起始节点(FromNode)的网络动作类型映射(Key: 网络动作ID, Value: 动作类型)
/// @author zzy
/// 2026-02-06 重构:使用字典替代List,Key即为网络动作ID
/// </summary>
public Dictionary<Guid, ActionType> StartNodeNetActionTypes { get; set; } = new();
/// <summary>
/// 终止节点(ToNode)的动作ID列表
/// @author zzy
/// </summary>
public List<StepAction> EndNodeActions { get; set; } = new();
/// <summary>
/// 终止节点(ToNode)的网络动作类型映射(Key: 网络动作ID, Value: 动作类型)
/// @author zzy
/// 2026-02-06 重构:使用字典替代List,Key即为网络动作ID
/// </summary>
public Dictionary<Guid, ActionType> EndNodeNetActionTypes { get; set; } = new();
/// <summary>
/// 从 PathSegment 创建(需要额外提供Code信息)
/// </summary>
public static PathSegmentWithCode FromSegment(PathSegment segment, string edgeCode, string fromNodeCode, string toNodeCode)
{
return new PathSegmentWithCode
{
EdgeId = segment.EdgeId,
FromNodeId = segment.FromNodeId,
ToNodeId = segment.ToNodeId,
Angle = segment.Angle,
Length = segment.Length,
MaxSpeed = segment.MaxSpeed,
RequiredAngle = segment.RequiredAngle,
EdgeCode = edgeCode,
FromNodeCode = fromNodeCode,
ToNodeCode = toNodeCode
};
}
}
/// <summary>
/// 寻路用节点数据
/// @author zzy
/// </summary>
public class PathNode
{
public Guid NodeId { get; set; }
public string NodeCode { get; set; } = string.Empty;
public double X { get; set; }
public double Y { get; set; }
/// <summary>
/// 节点朝向(弧度)
/// @author zzy
/// </summary>
public double? Theta { get; set; }
public bool IsReverseParking { get; set; }
public bool AllowRotate { get; set; }
public bool Active { get; set; }
public double? MaxCoordinateOffset { get; set; }
/// <summary>
/// 出边列表
/// </summary>
public List<PathEdge> OutEdges { get; set; } = new();
/// <summary>
/// 入边列表
/// </summary>
public List<PathEdge> InEdges { get; set; } = new();
}
/// <summary>
/// 寻路用边数据
/// @author zzy
/// </summary>
public class PathEdge
{
public Guid EdgeId { get; set; }
public string EdgeCode { get; set; } = string.Empty;
public Guid FromNodeId { get; set; }
public Guid ToNodeId { get; set; }
/// <summary>
/// 起始节点Code(用于跨地图冲突检测)
/// @author zzy
/// </summary>
public string FromNodeCode { get; set; } = string.Empty;
/// <summary>
/// 目标节点Code(用于跨地图冲突检测)
/// @author zzy
/// </summary>
public string ToNodeCode { get; set; } = string.Empty;
public double Length { get; set; }
public double Cost { get; set; }
public bool Active { get; set; }
/// <summary>
/// 允许的行驶夹角(弧度)
/// @author zzy
/// </summary>
public List<double> OrientationRads { get; set; } = new();
/// <summary>
/// 最大速度
/// </summary>
public double? MaxSpeed { get; set; }
/// <summary>
/// 终点切线方向(弧度,全局坐标系)
/// @author zzy
/// </summary>
public double DirectionRad { get; set; }
/// <summary>
/// 起点切线方向(弧度,全局坐标系)
/// @author zzy
/// </summary>
public double StartTangentRad { get; set; }
/// <summary>
/// 最大角度偏差(弧度),车辆航向角与边方向的允许偏差范围
/// @author zzy
/// </summary>
public double? MaxRadDeviation { get; set; }
}
/// <summary>
/// 寻路用资源区域数据
/// @author zzy
/// </summary>
public class PathResource
{
public Guid ResourceId { get; set; }
public string ResourceCode { get; set; } = string.Empty;
public int Type { get; set; }
public int Capacity { get; set; }
public double MaxSpeed { get; set; }
public bool CanRotate { get; set; }
/// <summary>
/// 区域内节点ID列表
/// </summary>
public List<Guid> NodeIds { get; set; } = new();
/// <summary>
/// 区域几何坐标点集合
/// </summary>
public List<PointCache>? LocationCoordinates { get; set; }
/// <summary>
/// 前置动作类型1(进入资源前)
/// @author zzy
/// </summary>
public ActionType? PreAction1Type { get; set; }
/// <summary>
/// 前置网络动作集合1(进入资源前)
/// @author zzy
/// </summary>
public List<Guid>? PreNetActions1 { get; set; }
/// <summary>
/// 后置动作类型1(进入资源后)
/// @author zzy
/// </summary>
public ActionType? PostAction1Type { get; set; }
/// <summary>
/// 后置网络动作集合1(进入资源后)
/// @author zzy
/// </summary>
public List<Guid>? PostNetActions1 { get; set; }
/// <summary>
/// 前置动作类型2(离开资源前)
/// @author zzy
/// </summary>
public ActionType? PreAction2Type { get; set; }
/// <summary>
/// 前置网络动作集合2(离开资源前)
/// @author zzy
/// </summary>
public List<Guid>? PreNetActions2 { get; set; }
/// <summary>
/// 后置动作类型2(离开资源后)
/// @author zzy
/// </summary>
public ActionType? PostAction2Type { get; set; }
/// <summary>
/// 后置网络动作集合2(离开资源后)
/// @author zzy
/// </summary>
public List<Guid>? PostNetActions2 { get; set; }
}
/// <summary>
/// 机器人运行时状态(用于冲突检测)
/// @author zzy
/// </summary>
public class RobotRuntimeState
{
public Guid RobotId { get; set; }
public string RobotCode { get; set; } = string.Empty;
public Guid? CurrentNodeId { get; set; }
public double? X { get; set; }
public double? Y { get; set; }
/// <summary>
/// 机器人当前航向角(弧度)
/// @author zzy
/// </summary>
public double? Angle { get; set; }
public bool IsLoaded { get; set; }
public int Priority { get; set; }
public int BatteryLevel { get; set; }
public bool IsDriving { get; set; }
/// <summary>
/// 机器人使用的地图编码(用于跨地图冲突检测)
/// @author zzy
/// </summary>
public string MapCode { get; set; } = string.Empty;
/// <summary>
/// 当前规划路径(节点ID列表)
/// </summary>
public List<Guid> PlannedPath { get; set; } = new();
/// <summary>
/// 当前规划路径带节点Code信息(用于跨地图冲突检测)
/// @author zzy
/// </summary>
public List<PlannedPathNode> PlannedPathWithCode { get; set; } = new();
/// <summary>
/// 已锁定的节点
/// </summary>
public HashSet<Guid> LockedNodes { get; set; } = new();
/// <summary>
/// 已锁定的边
/// </summary>
public HashSet<Guid> LockedEdges { get; set; } = new();
/// <summary>
/// 平均行驶速度(米/秒),用于预估到达时间
/// @author zzy
/// </summary>
public double AverageSpeed { get; set; } = 1.0;
/// <summary>
/// 当前行驶速度(米/秒)
/// @author zzy
/// </summary>
public double CurrentSpeed { get; set; }
/// <summary>
/// 是否被阻塞(遇到障碍物等)
/// @author zzy
/// </summary>
public bool IsBlocked { get; set; }
/// <summary>
/// 当前边的行驶进度(米),0表示还未进入边
/// @author zzy
/// </summary>
public double CurrentEdgeTraveledDistance { get; set; }
}
/// <summary>
/// 规划路径节点(带Code)
/// @author zzy
/// </summary>
public class PlannedPathNode
{
public Guid NodeId { get; set; }
public string NodeCode { get; set; } = string.Empty;
/// <summary>
/// 预估到达时间(秒,相对于路径开始时间)
/// </summary>
public double EstimatedArrivalTime { get; set; }
}
}