public void ReserveOkPartMove(MapSection mapSection)
        {
            try
            {
                int sectionIndex = MovingGuide.GuideSectionIds.FindIndex(x => x.Trim() == mapSection.Id.Trim());
                if (sectionIndex < 0)
                {
                    OnLogErrorEvent?.Invoke(this, new MessageHandlerArgs()
                    {
                        ClassMethodName = GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name,
                        Message         = $"ReserveOkPartMove fail.[{mapSection.Id.Trim()}].[{MovingGuide.GuideSectionIds.GetJsonInfo()}]"
                    });

                    return;
                }
                MapAddress address = MapInfo.addressMap[MovingGuide.GuideAddressIds[sectionIndex + 1]];

                PositionArgs positionArgs = new PositionArgs()
                {
                    EnumLocalArrival = sectionIndex == MovingGuide.GuideSectionIds.Count - 1 ? EnumLocalArrival.EndArrival : EnumLocalArrival.Arrival,
                    MapPosition      = address.Position
                };

                FakeMoveArrivalQueue.Enqueue(positionArgs);
            }
            catch (Exception ex)
            {
                OnLogErrorEvent?.Invoke(this, new MessageHandlerArgs()
                {
                    ClassMethodName = GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name,
                    Message         = ex.Message
                });
            }
        }
Example #2
0
 public void SetAutoState(EnumAutoState autoState)
 {
     try
     {
         Agv.EnumAutoState localPackageAutoState = GetLocalPackageAutoStateFrom(autoState);
         string            errorMessage          = "";
         if (LocalPackage.MainFlowHandler.ChangeAutoManual(localPackageAutoState, ref errorMessage))
         {
             OnModeChangeEvent?.Invoke(this, autoState);
         }
         else
         {
             OnLogDebugEvent?.Invoke(this, new MessageHandlerArgs()
             {
                 ClassMethodName = GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name,
                 Message         = $"LocalPackage.ChangeMode fail.[Error={errorMessage}]"
             });
         }
     }
     catch (Exception ex)
     {
         OnLogErrorEvent?.Invoke(this, new MessageHandlerArgs()
         {
             ClassMethodName = GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name,
             Message         = ex.Message
         });
     }
 }
        public void StartCharge(EnumAddressDirection chargeDirection)
        {
            Task.Run(() =>
            {
                try
                {
                    SpinWait.SpinUntil(() => false, 2000);
                    IsCharging = true;
                    OnUpdateChargeStatusEvent?.Invoke(this, IsCharging);

                    while (BatteryStatus.Percentage < 100 && IsCharging)
                    {
                        SpinWait.SpinUntil(() => false, 2000);

                        BatteryStatus.Percentage = Math.Min(BatteryStatus.Percentage + 10, 100);

                        OnUpdateBatteryStatusEvent?.Invoke(this, BatteryStatus);
                    }
                }
                catch (Exception ex)
                {
                    OnLogErrorEvent?.Invoke(this, new MessageHandlerArgs()
                    {
                        ClassMethodName = GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name,
                        Message         = ex.Message
                    });
                }

                SpinWait.SpinUntil(() => false, 2000);

                IsCharging = false;
                OnUpdateChargeStatusEvent?.Invoke(this, IsCharging);
            });
        }
Example #4
0
 private void MoveControl_MoveCompleteEvent(object sender, Agv.EnumMoveComplete e)
 {
     try
     {
         var localData = LocalPackage.MainFlowHandler.localData;
         OnUpdatePositionArgsEvent?.Invoke(sender, new PositionArgs()
         {
             EnumLocalArrival = GetEnumLocalArrival(e),
             MapPosition      = new MapPosition()
             {
                 X = localData.Real.Position.X,
                 Y = localData.Real.Position.Y
             },
             HeadAngle       = (int)localData.Real.Angle,
             MovingDirection = (int)localData.MoveDirectionAngle,
             Speed           = (int)localData.MoveControlData.MotionControlData.LineVelocity
         });
     }
     catch (Exception ex)
     {
         OnLogErrorEvent?.Invoke(this, new MessageHandlerArgs()
         {
             ClassMethodName = GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name,
             Message         = ex.Message
         });
     }
 }
Example #5
0
        private MapAddress GetLastAddress(INX.Model.LocalData localData)
        {
            try
            {
                INX.Model.VehicleLocation nowVehicleLocation = localData.Location;
                var addressId = nowVehicleLocation.LastAddress;
                return(Vehicle.Instance.MapInfo.addressMap[addressId]);
            }
            catch (Exception ex)
            {
                OnLogErrorEvent?.Invoke(this, new MessageHandlerArgs()
                {
                    ClassMethodName = GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name,
                    Message         = ex.Message
                });
            }

            return(null);
        }
Example #6
0
        private MapSection GetLastSection(INX.Model.LocalData localData)
        {
            try
            {
                INX.Model.VehicleLocation nowVehicleLocation = localData.Location;
                var sectionId   = nowVehicleLocation.NowSection;
                var lastSection = Vehicle.Instance.MapInfo.sectionMap[sectionId];
                lastSection.VehicleDistanceSinceHead = localData.Location.DistanceFormSectionHead;
                return(lastSection);
            }
            catch (Exception ex)
            {
                OnLogErrorEvent?.Invoke(this, new MessageHandlerArgs()
                {
                    ClassMethodName = GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name,
                    Message         = ex.Message
                });
            }

            return(null);
        }
        private void FakeMoveEngine()
        {
            while (true)
            {
                if (IsFakeMoveEnginePause)
                {
                    SpinWait.SpinUntil(() => !IsFakeMoveEnginePause, 1000);
                    continue;
                }

                try
                {
                    if (FakeMoveArrivalQueue.Any())
                    {
                        FakeMoveArrivalQueue.TryDequeue(out PositionArgs positionArgs);
                        OnUpdatePositionArgsEvent?.Invoke(this, positionArgs);
                    }
                    else
                    {
                        FakeMoveArrivalQueue.Enqueue(new PositionArgs()
                        {
                            EnumLocalArrival = EnumLocalArrival.Arrival,
                            MapPosition      = MoveStatus.LastMapPosition
                        });
                    }
                }
                catch (Exception ex)
                {
                    OnLogErrorEvent?.Invoke(this, new MessageHandlerArgs()
                    {
                        ClassMethodName = GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name,
                        Message         = ex.Message
                    });
                }

                SpinWait.SpinUntil(() => false, 5000);
            }
        }
Example #8
0
 private void MoveControl_PassAddressEvent(object sender, string addressId)
 {
     try
     {
         var address   = Vehicle.Instance.MapInfo.addressMap[addressId];
         var localData = LocalPackage.MainFlowHandler.localData;
         OnUpdatePositionArgsEvent?.Invoke(sender, new PositionArgs()
         {
             MapPosition      = address.Position,
             EnumLocalArrival = EnumLocalArrival.Arrival,
             HeadAngle        = (int)localData.Real.Angle,
             MovingDirection  = (int)localData.MoveDirectionAngle,
             Speed            = (int)localData.MoveControlData.MotionControlData.LineVelocity
         });
     }
     catch (Exception ex)
     {
         OnLogErrorEvent?.Invoke(this, new MessageHandlerArgs()
         {
             ClassMethodName = GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name,
             Message         = ex.Message
         });
     }
 }
Example #9
0
 public void LogError(object sender, string message, Exception exception) => OnLogErrorEvent?.Invoke(this, new BuildEventArgs(message, exception));