66using System . Diagnostics ;
77using VMSystem . AGV ;
88using VMSystem . AGV . TaskDispatch . Tasks ;
9+ using VMSystem . Dispatch . Regions ;
910using VMSystem . Extensions ;
1011using VMSystem . Services . Navigation ;
1112using VMSystem . TrafficControl ;
@@ -76,10 +77,17 @@ internal async Task<MapPoint> DetermineStopMapPoint()
7677 speficMap = StaMap . Map . Clone ( )
7778 } ) ;
7879 int destineOfHighPVehicle = _HightPriorityVehicle . CurrentRunningTask ( ) . DestineTag ;
79- ( var shorestPathInfoOfHighPVehicle , var secondaryPathInfoOfHighPVehicle ) = await planer . GetPathPlanResult ( _HightPriorityVehicle , _HightPriorityVehicle . currentMapPoint . TagNumber , destineOfHighPVehicle ) ;
80+ ( var shorestPathInfoOfHighPVehicle , var secondaryPathInfoOfHighPVehicle ) = await planer . GetPathPlanResult ( _HightPriorityVehicle , _HightPriorityVehicle . currentMapPoint . TagNumber
81+ , destineOfHighPVehicle , isGetShortPathWithoutConsiderConstrain : true ) ;
8082
8183
82- MapCircleArea lastRotationAreaOfHpv = shorestPathInfoOfHighPVehicle . path . Last ( ) . GetCircleArea ( ref highProrityVehicle ) ;
84+ MapCircleArea lastRotationAreaOfHpv = null ;
85+ if ( shorestPathInfoOfHighPVehicle != null && shorestPathInfoOfHighPVehicle . path . Last ( ) != null )
86+ lastRotationAreaOfHpv = shorestPathInfoOfHighPVehicle . path . Last ( ) . GetCircleArea ( ref highProrityVehicle ) ;
87+ else if ( highProrityVehicle . main_state != clsEnums . MAIN_STATUS . RUN )
88+ {
89+ lastRotationAreaOfHpv = highProrityVehicle . currentMapPoint . GetCircleArea ( ref highProrityVehicle ) ;
90+ }
8391
8492 if ( shorestPathInfoOfHighPVehicle != null )
8593 cannotAvoidPartToPoints . AddRange ( shorestPathInfoOfHighPVehicle . path ) ;
@@ -99,7 +107,9 @@ internal async Task<MapPoint> DetermineStopMapPoint()
99107
100108 cannotAvoidPartToPoints = cannotAvoidPartToPoints . Union ( nearPointsOfHPVCurrentPoint ) . ToList ( ) ;
101109 cannotAvoidPartToPoints = cannotAvoidPartToPoints . Union ( nearPointsExtend ) . ToList ( ) ;
102- }
110+ }
111+
112+
103113 List < int > tagListOfCannotAvoidPortTo = cannotAvoidPartToPoints . GetTagCollection ( ) . ToList ( ) ;
104114
105115 double [ ] distanceThres = TrafficControlCenter . TrafficControlParameters . DeadLockUse . searchRadiiForAvoidPoint ;
@@ -146,8 +156,8 @@ bool _isStopRotationNOTConflicToHighPAGV(MapPoint pt)
146156 . Select ( p => p . path )
147157 . Where ( path => path != null ) ;
148158 var _pathesCandidates = wrappersOrdered . Where ( path => path != null ) . ToList ( )
149- . Where ( path => path . Last ( ) . TagNumber != toAvoidVehicle . currentMapPoint . TagNumber && path . Count > 0 )
150- //.Where(path =>predicPathRegionOfHPV.All(reg => !reg.IsIntersectionTo(path.Last().GetCircleArea(ref toAvoidVehicle))))
159+ . Where ( path => path . Last ( ) . TagNumber != toAvoidVehicle . currentMapPoint . TagNumber && path . Count > 0 )
160+ //.Where(path =>predicPathRegionOfHPV.All(reg => !reg.IsIntersectionTo(path.Last().GetCircleArea(ref toAvoidVehicle))))
151161 . ToList ( ) ;
152162 sw . Stop ( ) ;
153163 logger ? . Info ( $ "計算避讓點花費 Step2:{ sw . Elapsed . TotalSeconds } 秒") ;
@@ -166,7 +176,44 @@ bool _isStopRotationNOTConflicToHighPAGV(MapPoint pt)
166176
167177 if ( ! pathesCandidates . Any ( ) )
168178 return null ;
169- return pathesCandidates . First ( ) . Last ( ) ;
179+
180+ var result = pathesCandidates . First ( ) . LastOrDefault ( ) ;
181+
182+ if ( result != null )
183+ {
184+ //如果 High Level 車輛的終點位於一個區域且該區域在加上lowlevel 車輛進入後將不可進入,則lowlevel車應該不可以到該區域避車
185+ var regionOfDestineForHPV = destineOfHighPVehicle . GetMapPoint ( ) . GetRegion ( ) ;
186+ var regionOfAvoidPtForLPV = result . GetRegion ( ) ;
187+
188+ if ( regionOfDestineForHPV != null && regionOfAvoidPtForLPV != null && regionOfAvoidPtForLPV . Name == regionOfDestineForHPV . Name && regionOfDestineForHPV . InRegionVehicles . Count ( ) + 1 >= regionOfDestineForHPV . MaxVehicleCapacity )
189+ {
190+ int oriMaxVehicleCapacity = regionOfDestineForHPV . MaxVehicleCapacity ;
191+
192+ logger . Info ( $ "因避車點與高優先度車輛的終點為相同區域({ regionOfDestineForHPV . Name } ),且該區域容量將在低優先度車輛進入後達上限,暫時將該區域可容納車輛數暫時 +1") ;
193+
194+ regionOfDestineForHPV . MaxVehicleCapacity += 1 ;
195+
196+ Task . Run ( async ( ) =>
197+ {
198+ while ( _HightPriorityVehicle . currentMapPoint . GetRegion ( ) . Name != regionOfDestineForHPV . Name )
199+ {
200+ bool isAgvDown = _HightPriorityVehicle . main_state == clsEnums . MAIN_STATUS . DOWN ;
201+ bool isAgvOffline = _HightPriorityVehicle . online_state == clsEnums . ONLINE_STATE . OFFLINE ;
202+ bool isTaskCanceled = _HightPriorityVehicle . taskDispatchModule . OrderExecuteState != clsAGVTaskDisaptchModule . AGV_ORDERABLE_STATUS . EXECUTING ;
203+ if ( isAgvDown || isAgvOffline || isTaskCanceled )
204+ break ;
205+
206+ logger . Info ( $ "等待 { _HightPriorityVehicle . Name } 進入 { regionOfDestineForHPV . Name } 後恢復該區域可容納車輛數量({ oriMaxVehicleCapacity } )") ;
207+ await Task . Delay ( 1000 ) ;
208+ }
209+ regionOfDestineForHPV . MaxVehicleCapacity = oriMaxVehicleCapacity ;
210+ logger . Info ( $ "{ regionOfDestineForHPV . Name } 可容納車輛數已恢復為 { oriMaxVehicleCapacity } ") ;
211+ } ) ;
212+ }
213+ }
214+
215+ return result ;
216+
170217 }
171218
172219 }
0 commit comments