Bläddra i källkod

Property Event 수정

DESKTOP-Kang 6 år sedan
förälder
incheckning
944428eda9

+ 1 - 0
Dev/OHV/OHV.Common/Shareds/ConstString.cs

@@ -16,6 +16,7 @@ namespace OHV.Common.Shareds
         public const string BuzzerStartReadyTime = "BUZZEER_START_READY";
         public const string PIOInterLockTimeout = "PIO_INTERLOCK_TIMEOUT";
         public const string PIOTimeOut = "PIO_TIMEOUT";
+        public const string DriveSpeed = "DRIVE_SPEED";
 
         //Axis Name
         public const string AXIS_CARRIER_LOCK_LEFT = "Axis_CarrierLock_Left";

+ 5 - 0
Dev/OHV/OHV.Module.Interactivity/PopUp/DriveServoViewModel.cs

@@ -179,6 +179,11 @@ namespace OHV.Module.Interactivity.PopUp
                                 this.ChangeSteeringDirection( dir );
                             }
                             break;
+                        case "CurrentPosition":
+                            {
+                                var v = CastTo<double>.From<object>(obj.Args);
+                            }
+                            break;
                         default:
                             break;
                     }

+ 9 - 2
Dev/OHV/OHV.SqliteDAL/OHVDbInitializer.cs

@@ -75,7 +75,15 @@ namespace OHV.SqliteDAL
                     Desc = "PIO Time Out",
                     EditTime = DateTime.Now,
                 },
-            } ) ;
+                new Config
+                {
+                    ID = ConstString.DriveSpeed,
+                    Name= ConstString.DriveSpeed,
+                    Value = "100",
+                    Desc = "Drive Speed",
+                    EditTime = DateTime.Now,
+                },
+            }) ;
 
             context.Set<AxisPositionData>().AddRange( new List<AxisPositionData>()
             {
@@ -113,7 +121,6 @@ namespace OHV.SqliteDAL
                     JogFast = 10,
                     JogSlow = 2,
                     Tolerance = 1,
-
                 },
                 new AxisVelocityData
                 {

+ 38 - 5
Dev/OHV/VehicleControlSystem/ControlLayer/Motion/GSIMotion.cs

@@ -1,4 +1,6 @@
-using System;
+using GSG.NET.Concurrent;
+using OHV.SqliteDAL;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -9,16 +11,30 @@ namespace VehicleControlSystem.ControlLayer.Motion
     /// <summary>
     /// 나성권 부장이 만든 Dll 을 사용할 클래스
     /// </summary>
-    public class GSIMotion
+    public class GSIMotion : ControlObjectBase
     {
         public bool IsStop { get; set; }
-        public double CurrentPos { get; set; }
+
+        double currentPos = 0;
+        public double CurrentPos { get { return this.currentPos; } set { SetField(ref this.currentPos, value); } }
+
+        private string currentTag;
+        public string CurrentTag { get { return currentTag; } set { SetField(ref this.currentTag, value); } }
+
+        private double currentSpeed;
+        public double CurrentSpeed { get { return currentSpeed; } set { SetField(ref this.currentSpeed, value); } }
+
+        private double currentTorque;
+        public double CurrentTorque { get { return currentTorque; } set { SetField(ref this.currentTorque, value); } }
 
         public bool IsErrorOn { get; set; }
 
-        public GSIMotion()
-        {
+        TaskCancel taskCancel = new TaskCancel();
+        SqliteManager sql = null;
 
+        public GSIMotion(SqliteManager sql)
+        {
+            this.sql = sql;
         }
 
         public void Init()
@@ -27,6 +43,19 @@ namespace VehicleControlSystem.ControlLayer.Motion
 
         public bool MoveToPoint(string point, double velocity)
         {
+            var task = Task.Factory.StartNew(() =>
+            {
+                int index = 0;
+                while (true)
+                {
+                    LockUtils.Wait(500);
+                    this.CurrentPos = index++;
+
+                    if (CurrentPos > 20)
+                        break;
+                }
+            });
+
             return true;
         }
 
@@ -54,5 +83,9 @@ namespace VehicleControlSystem.ControlLayer.Motion
         {
             return true;
         }
+
+        #region Test Method
+
+        #endregion
     }
 }

+ 6 - 16
Dev/OHV/VehicleControlSystem/ControlLayer/Steering.cs

@@ -47,13 +47,10 @@ namespace VehicleControlSystem.ControlLayer
         {
             eSteeringState frontState = eSteeringState.None;
             if (this.IsFrontLeft() && this.IsFrontRight())
-            {
-                //None
-            }
+                frontState = eSteeringState.None;
             if (!this.IsFrontLeft() && !this.IsFrontRight())
-            {
-                //None
-            }
+                frontState = eSteeringState.None;
+
             if (this.IsFrontLeft() && !this.IsFrontRight())
                 frontState = eSteeringState.Left;
             if (!this.IsFrontLeft() && this.IsFrontRight())
@@ -61,21 +58,14 @@ namespace VehicleControlSystem.ControlLayer
 
             eSteeringState rearState = eSteeringState.None;
             if (this.IsRearLeft() && this.IsRearRight())
-            {
-                //None
-            }
+                rearState = eSteeringState.None;
             if (!this.IsRearLeft() && !this.IsRearRight())
-            {
-                //None
-            }
+                rearState = eSteeringState.None;
+
             if (this.IsRearLeft() && !this.IsRearRight())
-            {
                 rearState = eSteeringState.Left;
-            }
             if (!this.IsRearLeft() && this.IsRearRight())
-            {
                 rearState = eSteeringState.Right;
-            }
 
             if (frontState == eSteeringState.Left && rearState == eSteeringState.Left)
                 this.SteeringState = eSteeringState.Left;

+ 92 - 32
Dev/OHV/VehicleControlSystem/ControlLayer/Vehicle.cs

@@ -46,22 +46,24 @@ namespace VehicleControlSystem.ControlLayer
         static Logger loggerPIO = Logger.GetLogger("PIO");
 
         #region Properties
-        private double currentPosition;
-
         /// <summary>
         /// Tag 위치
         /// </summary>
-        private int currentTag;
-
-        public int CurrentTag
+        private string currentTag;
+        public string CurrentTag
         {
             get { return currentTag; }
-            set { SetField(ref this.currentTag, value); }
+            set 
+            { 
+                if ( SetField(ref this.currentTag, value))
+                    this.OnCurrentTagChanged?.Invoke(value);
+            }
         }
 
         /// <summary>
         /// Scale Value
         /// </summary>
+        private double currentPosition;
         public double CurrentPosition
         {
             get { return currentPosition; }
@@ -69,21 +71,38 @@ namespace VehicleControlSystem.ControlLayer
             {
                 if (SetField(ref this.currentPosition, value))
                 {
-                    this.currentPosition = value;
-                    this.OnCurrentPotisionChanged?.Invoke((int)value);
                 }
             }
         }
 
-        private eSteeringState steeringState;
+        private double currentSpeed;
+        public double CurrentSpeed
+        {
+            get { return currentSpeed; }
+            set { SetField(ref this.currentSpeed, value); }
+        }
 
+        private double currentTorque;
+        public double CurrentTorque
+        {
+            get { return currentTorque; }
+            set { SetField(ref this.currentTorque, value); }
+        }
+
+        private bool isContain;
+        public bool IsContain
+        {
+            get { return isContain; }
+            set { SetField(ref this.isContain, value); }
+        }
+
+        private eSteeringState steeringState;
         public eSteeringState SteeringState
         {
             get { return steeringState; }
             set { SetField(ref this.steeringState, value); }
         }
 
-
         //이동
         public bool Busy
         {
@@ -97,12 +116,11 @@ namespace VehicleControlSystem.ControlLayer
         public bool IsMoving { get; set; }
         public double BatteryVolt { get; set; }
         public bool IsError { get; set; }
-        public bool IsContain { get { return this.IsDetectedCenter(); } }
 
         public SubCmd CurrentSubCommand { get; private set; }
         #endregion
 
-        #region Event
+        #region Event 
         public event Action OnMoveReady;
         public event Action OnMoving;
         public event Action OnMoveFinish;
@@ -119,7 +137,7 @@ namespace VehicleControlSystem.ControlLayer
         public event Action OnLoadComplete;
         public event Action OnUnloadComplete;
 
-        public event Action<int> OnCurrentPotisionChanged;
+        public event Action<string> OnCurrentTagChanged;
 
         public event Action OnManualMove;
         public event Action OnManualLoad;
@@ -129,7 +147,7 @@ namespace VehicleControlSystem.ControlLayer
         public event Action<eFailCode> OnFailReport;
         #endregion
 
-        IIO iO = null;
+        EzIO iO = null;
         GSIMotion motion = null;
         SqliteManager sql = null;
         Clamp clamp = null;
@@ -163,8 +181,8 @@ namespace VehicleControlSystem.ControlLayer
 
         public Vehicle(IIO io, SqliteManager sqliteManager, IEventAggregator ea, AutoManager auto)
         {
-            this.iO = io;
-            this.motion = new GSIMotion();
+            this.iO = io as EzIO;
+            this.iO.OnChangedIO += IO_OnChangedIO;
             this.sql = sqliteManager;
             this.autoManager = auto;
 
@@ -267,8 +285,6 @@ namespace VehicleControlSystem.ControlLayer
             }
         }
 
-
-
         //private void DriveControlEventPublish( DriveControlEventArgs args ) { }
 
         private void DriveControlEventPublish(DriveControlEventArgs args)
@@ -766,7 +782,7 @@ namespace VehicleControlSystem.ControlLayer
 
         #endregion
 
-        #region Machanical Method
+        #region Mechanical Method
 
         #region Conveyor
         int OnOffConveyor(bool isOn, bool isCW = false)
@@ -1108,24 +1124,16 @@ namespace VehicleControlSystem.ControlLayer
             this.steering.OnSteeringError += Steering_OnSteeringError;
             this.steering.PropertyChanged += Steering_PropertyChanged;
         }
-
-        private void Steering_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
-        {
-            var property = sender.GetType().GetProperty(e.PropertyName);
-            var newValue = property.GetValue(sender, null);
-
-            if (e.PropertyName.Equals("SteeringState"))
-            {
-                var v = CastTo<eSteeringState>.From<object>(newValue);
-                this.SteeringState = v;
-            }
-        }
-
         void CreateClamp()
         {
             this.clamp = new Clamp(this.sql, this.eventAggregator);
             this.clamp.Init();
         }
+        void CreateDrive()
+        {
+            this.motion = new GSIMotion(this.sql);
+            this.motion.PropertyChanged += Motion_PropertyChanged;
+        }
 
         #endregion
 
@@ -1192,6 +1200,58 @@ namespace VehicleControlSystem.ControlLayer
         #endregion
 
         #region Event Subscribe 
+        private void Motion_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+        {
+            var property = sender.GetType().GetProperty(e.PropertyName);
+            var newValue = property.GetValue(sender, null);
+
+            if (e.PropertyName.Equals("CurrentPos"))
+            {
+                var v = CastTo<double>.From<object>(newValue);
+                this.CurrentPosition = v;
+            }
+
+            if (e.PropertyName.Equals("CurrentTag"))
+            {
+                var v = CastTo<string>.From<object>(newValue);
+                this.CurrentTag = v;
+            }
+
+            if (e.PropertyName.Equals("CurrentSpeed"))
+            {
+                var v = CastTo<double>.From<object>(newValue);
+                this.CurrentSpeed = v;
+            }
+
+            if (e.PropertyName.Equals("CurrentTorque"))
+            {
+                var v = CastTo<double>.From<object>(newValue);
+                this.CurrentTorque = v;
+            }
+        }
+
+        private void Steering_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+        {
+            var property = sender.GetType().GetProperty(e.PropertyName);
+            var newValue = property.GetValue(sender, null);
+
+            //Todo: 나중에 Test 하자
+            //var ownPropperty = this.GetType().GetProperty(e.PropertyName);
+            if (e.PropertyName.Equals("SteeringState"))
+            {
+                var v = CastTo<eSteeringState>.From<object>(newValue);
+                this.SteeringState = v;
+            }
+        }
+
+        private void IO_OnChangedIO(BitBlock bit)
+        {
+            if (bit.Tag.Equals("IN_CV_DETECT_01"))
+            {
+                this.IsContain = bit.IsBitOn;
+            }
+        }
+
         private void Steering_OnSteeringError(object sender, int e)
         {
             if (e != 0)

+ 19 - 19
Dev/OHV/VehicleControlSystem/Managers/HostManager.cs

@@ -61,7 +61,7 @@ namespace VehicleControlSystem.Managers
             vehicle.OnCharging += Vehicle_OnCharging;
             vehicle.OnChargingFull += Vehicle_OnChargingFull;
 
-            vehicle.OnCurrentPotisionChanged += Vehicle_OnCurrentPotisionChanged;
+            vehicle.OnCurrentTagChanged += Vehicle_OnCurrentTagChanged;
 
             vehicle.OnManualLoad += Vehicle_OnManualLoad;
             vehicle.OnManualMove += Vehicle_OnManualMove;
@@ -82,7 +82,7 @@ namespace VehicleControlSystem.Managers
         {
             var msg = new OCSMessage();
             msg.Kind = eKind.F;
-            msg.Tag = this.vehicle.CurrentPosition.ToString();
+            msg.Tag = this.vehicle.CurrentTag;
             msg.SubCode = CastTo<int>.From( obj ).ToString( "000" );
 
             this.manager.Send( msg );
@@ -92,7 +92,7 @@ namespace VehicleControlSystem.Managers
         {
             var msg = new OCSMessage();
             msg.Kind = eKind.H;
-            msg.Tag = this.vehicle.CurrentPosition.ToString();
+            msg.Tag = this.vehicle.CurrentTag;
             msg.IsSubCode1 = false;
             msg.IsSubCode2 = false;
             msg.IsSubCode3 = false;
@@ -104,7 +104,7 @@ namespace VehicleControlSystem.Managers
         {
             var msg = new OCSMessage();
             msg.Kind = eKind.H;
-            msg.Tag = this.vehicle.CurrentPosition.ToString();
+            msg.Tag = this.vehicle.CurrentTag;
             msg.IsSubCode1 = false;
             msg.IsSubCode2 = true;
             msg.IsSubCode3 = false;
@@ -116,7 +116,7 @@ namespace VehicleControlSystem.Managers
         {
             var msg = new OCSMessage();
             msg.Kind = eKind.H;
-            msg.Tag = this.vehicle.CurrentPosition.ToString();
+            msg.Tag = this.vehicle.CurrentTag;
             msg.IsSubCode1 = true;
             msg.IsSubCode2 = false;
             msg.IsSubCode3 = false;
@@ -133,7 +133,7 @@ namespace VehicleControlSystem.Managers
             else
                 msg.Kind = eKind.U;
 
-            msg.Tag = this.vehicle.CurrentPosition.ToString();
+            msg.Tag = this.vehicle.CurrentTag;
             msg.IsSubCode1 = true;
             msg.IsSubCode2 = true;
             msg.IsSubCode3 = false;
@@ -145,7 +145,7 @@ namespace VehicleControlSystem.Managers
         {
             var msg = new OCSMessage();
             msg.Kind = eKind.U;
-            msg.Tag = this.vehicle.CurrentPosition.ToString();
+            msg.Tag = this.vehicle.CurrentTag;
             msg.IsSubCode1 = true;
             msg.IsSubCode2 = true;
             msg.IsSubCode3 = true;
@@ -157,7 +157,7 @@ namespace VehicleControlSystem.Managers
         {
             var msg = new OCSMessage();
             msg.Kind = eKind.L;
-            msg.Tag = this.vehicle.CurrentPosition.ToString();
+            msg.Tag = this.vehicle.CurrentTag;
             msg.IsSubCode1 = true;
             msg.IsSubCode2 = true;
             msg.IsSubCode3 = true;
@@ -174,7 +174,7 @@ namespace VehicleControlSystem.Managers
             else
                 msg.Kind = eKind.U;
 
-            msg.Tag = this.vehicle.CurrentPosition.ToString();
+            msg.Tag = this.vehicle.CurrentTag;
             msg.IsSubCode1 = true;
             msg.IsSubCode2 = false;
             msg.IsSubCode3 = true;
@@ -191,7 +191,7 @@ namespace VehicleControlSystem.Managers
             else
                 msg.Kind = eKind.U;
 
-            msg.Tag = this.vehicle.CurrentPosition.ToString();
+            msg.Tag = this.vehicle.CurrentTag;
             msg.IsSubCode1 = true;
             msg.IsSubCode2 = false;
             msg.IsSubCode3 = false;
@@ -208,7 +208,7 @@ namespace VehicleControlSystem.Managers
             else
                 msg.Kind = eKind.U;
 
-            msg.Tag = this.vehicle.CurrentPosition.ToString();
+            msg.Tag = this.vehicle.CurrentTag;
             msg.IsSubCode1 = false;
             msg.IsSubCode2 = false;
             msg.IsSubCode3 = false;
@@ -236,7 +236,7 @@ namespace VehicleControlSystem.Managers
             this.Send_ManualLoad();
         }
 
-        private void Vehicle_OnCurrentPotisionChanged(int point)
+        private void Vehicle_OnCurrentTagChanged(string point)
         {
             this.Send_Tcmd(point);
         }
@@ -428,7 +428,7 @@ namespace VehicleControlSystem.Managers
         public void Send_Ecmd()
         {
             var msg = new OCSMessage();
-            msg.Tag = vehicle.CurrentPosition.ToString("0000");
+            msg.Tag = vehicle.CurrentTag;
             msg.IsSubCode1 = this.vehicle.IsContain;
             msg.IsSubCode2 = vehicle.IsMoving;
             msg.IsSubCode3 = vehicle.IsError;
@@ -436,11 +436,11 @@ namespace VehicleControlSystem.Managers
             this.manager.Send(msg);
         }
 
-        public void Send_Tcmd(int point)
+        public void Send_Tcmd(string point)
         {
             var msg = new OCSMessage();
             msg.Kind = eKind.T;
-            msg.Tag = point.ToString("0000");
+            msg.Tag = point;
             msg.IsSubCode1 = this.vehicle.IsContain;
             msg.IsSubCode2 = vehicle.IsMoving;
             msg.IsSubCode3 = vehicle.IsError;
@@ -466,7 +466,7 @@ namespace VehicleControlSystem.Managers
             var msg = new OCSMessage()
             {
                 Kind = eKind.P,
-                Tag = this.vehicle.CurrentPosition.ToString(),
+                Tag = this.vehicle.CurrentTag,
                 IsSubCode1 = false,
                 IsSubCode2 = false,
                 IsSubCode3 = true,
@@ -479,7 +479,7 @@ namespace VehicleControlSystem.Managers
             var msg = new OCSMessage()
             {
                 Kind = eKind.P,
-                Tag = this.vehicle.CurrentPosition.ToString(),
+                Tag = this.vehicle.CurrentTag,
                 IsSubCode1 = false,
                 IsSubCode2 = true,
                 IsSubCode3 = false,
@@ -492,7 +492,7 @@ namespace VehicleControlSystem.Managers
             var msg = new OCSMessage()
             {
                 Kind = eKind.P,
-                Tag = this.vehicle.CurrentPosition.ToString(),
+                Tag = this.vehicle.CurrentTag,
                 IsSubCode1 = true,
                 IsSubCode2 = false,
                 IsSubCode3 = false,
@@ -505,7 +505,7 @@ namespace VehicleControlSystem.Managers
             var msg = new OCSMessage()
             {
                 Kind = eKind.P,
-                Tag = this.vehicle.CurrentPosition.ToString(),
+                Tag = this.vehicle.CurrentTag,
                 IsSubCode1 = true,
                 IsSubCode2 = true,
                 IsSubCode3 = true,