Beispiel #1
0
            public object ReadKidValue(int axisNum, string ColumnName, ADSClient Mom, bool trysql = true)
            {
                object currentValue;

                if (ColumnName.ToUpper() == "TARGETPOSITION")
                {
                    currentValue = Mom.Kids[axisNum].TargetPosition;
                }
                else if (ColumnName.ToUpper() == "CURRENTPOSITION")
                {
                    currentValue = Mom.Kids[AxisNum].CurrentPosition;
                }
                else if (ColumnName.ToUpper() == "FAULTED")
                {
                    currentValue = Mom.ReadValue(Mom.GlobalEstop);
                }
                else if (ColumnName.ToUpper() == "ACCELERATION")
                {
                    currentValue = Mom.Kids[AxisNum].ModeAccel;
                }
                else if (ColumnName.ToUpper() == "VELOCITY")
                {
                    currentValue = Mom.Kids[AxisNum].ModeVel;
                }
                else
                {
                    currentValue = ADSQL.SqlReadAxis(axisNum, ColumnName);
                }
                return(currentValue);
            }
Beispiel #2
0
        public static void Main(string[] args)
        {
            bool[] isActive    = new bool[6];
            int[]  DeadCounter = new int[6];

            try
            {
                int InstanceCount = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length;
                if (InstanceCount > 2)
                {
                    return;
                }
                if (InstanceCount > 1)
                {
                    do
                    {
                        InstanceCount = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length; Thread.Sleep(200);
                    } while (InstanceCount > 1);
                }
                if (InstanceCount > 1)
                {
                    Thread.Sleep(5000);
                }
                Console.Write("STARTING CONNECTION TO MOM...");

                ADSClient Mom = new ADSClient(new TwinCAT.Ads.AmsAddress("10.99.1.1.1.1", 851).NetId.ToString(), true, 6);
                Console.Write("DONE");
                Stopwatch j         = Stopwatch.StartNew();
                int       loopCount = 0;


                do
                {
                    loopCount++; Debug.Print(loopCount.ToString());
                    if (loopCount > 0)
                    {
                        Console.WriteLine(loopCount.ToString() + "   " + j.ElapsedMilliseconds.ToString()); j = Stopwatch.StartNew();
                    }
                    Mom.WriteValue(Mom.TimeOutSwitch, false);
                    AxisRows = (DataRowCollection)ADSQL.SqlPullAxis();
                    Thread.Sleep(50);

                    bool GlobalReset = (string)ADSQL.SqlReadAxis(1, "AxisStatus") == "RESET";

                    if ((string)ADSQL.SqlReadAxis(1, "AxisStatus") == "FAULT")
                    {
                        Mom.WriteValue(Mom.GlobalEstop, true);
                    }



                    if (GlobalReset)
                    {
                        Mom.WriteValue(Mom.FaultReset, true);
                    }
                    bool GlobalEstop = (int)Mom.ReadValue(Mom.GlobalEstop) > 0;

                    for (int x = 1; x <= 6; x++)
                    {
                        if (GlobalReset)
                        {
                            ADSQL.SqlWriteAxis(x, "AxisStatus", "OK");
                        }

                        string FaultStatus = (string)ADSQL.SqlReadAxis(x, "AxisStatus");

                        if (loopCount > 200)
                        {
                            loopCount = 0;
                        }


                        bool QueStarted = (bool)ADSQL.SqlReadAxis(x, "QueStarted");
                        if (QueStarted)
                        {
                            Mom.Kids[x - 1].MomControl = 0; ADSQL.SqlWriteAxis(x, "QueStarted", false);
                        }
                        bool thisActive = (bool)ADSQL.SqlReadAxis(x, "IsActive");
                        int  KidCurrent = Mom.Kids[x - 1].CurrentPosition;
                        ADSQL.SqlWriteAxis(x, "CurrentPosition", KidCurrent);
                        int KidTarget;

                        if (thisActive)
                        {
                            ADSQL.SqlWriteAxis(x, "IsActive", 0);
                            Mom.Kids[x - 1].DeadManPressed = 1;
                            KidTarget = Mom.Kids[x - 1].TargetPosition;
                            int KidSqlTarget = (int)ADSQL.SqlReadAxis(x, "TargetPosition");

                            int scaler = Math.Abs(KidCurrent - KidSqlTarget) / 5;
                            Debug.Print(scaler.ToString());
                            Mom.Kids[x - 1].ScalingInt = (int)ADSQL.SqlReadAxis(x, "TrimFactor");;


                            if (KidSqlTarget != KidTarget)
                            {
                                Mom.Kids[x - 1].TargetPosition = KidSqlTarget;
                            }
                        }

                        if (isActive[x - 1] == thisActive && !thisActive)
                        {
                            DeadCounter[x - 1]++;
                            if (DeadCounter[x - 1] > 3 && DeadCounter[x - 1] < 5)
                            {
                                Mom.Kids[x - 1].DeadManPressed = 0;
                            }
                        }
                        else
                        {
                            DeadCounter[x - 1] = 0;
                        }



                        int KidAccel = Mom.Kids[x - 1].ModeAccel;
                        int KidDecel = Mom.Kids[x - 1].ModeDecel;
                        int KidVel   = Mom.Kids[x - 1].ModeVel;

                        int  KidSqlDecel = (int)ADSQL.SqlReadAxis(x, "Deceleration");
                        int  KidSqlAccel = (int)ADSQL.SqlReadAxis(x, "Acceleration");
                        int  KidSqlVel   = (int)ADSQL.SqlReadAxis(x, "Velocity");
                        bool JogMode     = (bool)ADSQL.SqlReadAxis(x, "JogMode");
                        if (JogMode)
                        {
                            int accelRate = (int)((int)ADSQL.SqlReadAxis(x, "JogSpeed") / (double)ADSQL.SqlReadAxis(x, "JogAccel"));

                            KidSqlAccel = accelRate;
                            if (accelRate < 400)
                            {
                                accelRate = 400;
                            }
                            KidSqlDecel = accelRate;
                            KidSqlVel   = (int)ADSQL.SqlReadAxis(x, "JogSpeed");
                        }

                        if (KidSqlAccel != KidAccel)
                        {
                            Mom.Kids[x - 1].ModeAccel = KidSqlAccel;
                        }
                        if (KidSqlDecel != KidDecel)
                        {
                            Mom.Kids[x - 1].ModeDecel = KidSqlDecel;
                        }
                        if (KidSqlVel != KidVel)
                        {
                            Mom.Kids[x - 1].ModeVel = KidSqlVel;
                        }



                        if (isActive[x - 1])
                        {
                        }
                        else
                        {
                            KidTarget = KidCurrent;
                            Mom.Kids[x - 1].TargetPosition = Mom.Kids[x - 1].CurrentPosition;
                        }

                        if (Mom.Kids[x - 1].MomControl == 0)
                        {
                            ADSQL.SqlWriteAxis(x, "AxisStatus", "OFFLINE");
                        }
                        else if (GlobalEstop && !GlobalReset)
                        {
                            ADSQL.SqlWriteAxis(x, "AxisStatus", "FAULT");
                        }



                        if (QueStarted)
                        {
                            Mom.Kids[x - 1].MomControl = 1;
                        }
                        isActive[x - 1] = thisActive;
                    }
                } while (true);
            }
            catch
            {
                Thread.Sleep(20000); Console.WriteLine("Error");
                Environment.Exit(0);
            }
        }