Ejemplo n.º 1
0
        public void SetTripDO(int index, int errorCode, bool state)
        {
            string sTrip = string.Format(".gv.Daq.DOUT[{0}].trip.", index);

            TcComm.WriteInt(sTrip + "code", (short)errorCode, ETcRunTime.RT1);
            TcComm.WriteBool(sTrip + "state", state, ETcRunTime.RT1);
        }
Ejemplo n.º 2
0
        public void SetServoFriction(ETcServoAxis axis, int dir, float kf, float kv)
        {
            string sPid = string.Format(".gv.Axis[{0}].friction[{1}].", (int)axis, dir);

            TcComm.WriteReal(sPid + "Kf", (float)kf, ETcRunTime.RT1);
            TcComm.WriteReal(sPid + "Kv", (float)kv, ETcRunTime.RT1);
        }
Ejemplo n.º 3
0
        public void SetScaleAO(int index, int type, double scale, double offset)
        {
            string sAO = string.Format(".gv.Daq.AOUT[{0}].", index);

            TcComm.WriteInt(sAO + "mode", (short)type, ETcRunTime.RT1);
            TcComm.WriteReal(sAO + "scale", (float)scale, ETcRunTime.RT1);
            TcComm.WriteReal(sAO + "offset", (float)offset, ETcRunTime.RT1);
        }
Ejemplo n.º 4
0
 public TcDaqStorage()
 {
     // Storage length = 10 minutes DAQ gathering length
     length     = (int)TcComm.ReadInt(tagDaqLength, ETcRunTime.RT1) / 2 * 5 * 60 * 10;
     values     = new float[length];
     fValueList = new List <float>(length / 2 / 30);
     dValueList = new List <double>(length / 2 / 30);
 }
Ejemplo n.º 5
0
        public void SetTripAO(int index, int errorCode, int maxCount, double min, double max)
        {
            string sTrip = string.Format(".gv.Daq.AOUT[{0}].trip.", index);

            TcComm.WriteInt(sTrip + "code", (short)errorCode, ETcRunTime.RT1);
            TcComm.WriteInt(sTrip + "maxCount", (short)maxCount, ETcRunTime.RT1);
            TcComm.WriteReal(sTrip + "minValue", (float)min, ETcRunTime.RT1);
            TcComm.WriteReal(sTrip + "maxValue", (float)max, ETcRunTime.RT1);
        }
Ejemplo n.º 6
0
        // Set servo running profile //
        public void SetServoProfile(ETcServoAxis axis, PointF[] point)
        {
            for (int i = 0; i < point.Length; i++)
            {
                string sPointX = string.Format(".gv.Axis[{0}].profile.point[{1}].X", (int)axis, i);
                string sPointY = string.Format(".gv.Axis[{0}].profile.point[{1}].Y", (int)axis, i);

                TcComm.WriteReal(sPointX, point[i].X, ETcRunTime.RT1);
                TcComm.WriteReal(sPointY, point[i].Y, ETcRunTime.RT1);
            }

            string sLength = string.Format(".gv.Axis[{0}].profile.length", (int)axis);

            TcComm.WriteInt(sLength, (short)point.Length, ETcRunTime.RT1);
        }
Ejemplo n.º 7
0
        // Set PID parameter
        // axis : Servo axis number
        // mode  : Servo PID control mode 0-Torque 1-Speed 2-Position
        // kp    : Propotional factor(%)
        // ki    : Integral factor(msec)
        // kd    : Differencial factor(msec)
        // tv    : Velocity compensation
        // tf    : Friction
        // ti    : Rotor inertia
        // min   : Minimum output value
        // max   : Maximum output value
        public void SetParamServoPID(ETcServoAxis axis, ETcServoMode mode, bool closeLoop, double kp, double ki,
                                     double kd, double ka, double tv, double tf, double ti, double min, double max)
        {
            string sPid = string.Format(".gv.Axis[{0}].pidParam[{1}].", (int)axis, (int)mode);

            TcComm.WriteBool(sPid + "closeLoop", closeLoop, ETcRunTime.RT1);
            TcComm.WriteReal(sPid + "Kp", (float)kp, ETcRunTime.RT1);
            TcComm.WriteReal(sPid + "Ki", (float)ki, ETcRunTime.RT1);
            TcComm.WriteReal(sPid + "Kd", (float)kd, ETcRunTime.RT1);
            TcComm.WriteReal(sPid + "Ka", (float)ka, ETcRunTime.RT1);
            TcComm.WriteReal(sPid + "Tv", (float)tv, ETcRunTime.RT1);
            TcComm.WriteReal(sPid + "Tf", (float)tf, ETcRunTime.RT1);
            TcComm.WriteReal(sPid + "Ti", (float)ti, ETcRunTime.RT1);
            TcComm.WriteReal(sPid + "value.minValue", (float)min, ETcRunTime.RT1);
            TcComm.WriteReal(sPid + "value.maxValue", (float)max, ETcRunTime.RT1);
        }
Ejemplo n.º 8
0
        private void DoThreadWork()
        {
            float[] tcValues    = null;
            float[] tcNewValues = null;
            int     tcLength    = TcComm.ReadInt(tagDaqLength, ETcRunTime.RT1) / 2;

            while (threadTerminated == false)
            {
                // Is a half of DAQ storage full?
                if (TcComm.ReadBool(tagDaqActive, ETcRunTime.RT1) == true)
                {
                    int tcIndex = TcComm.ReadInt(tagDaqIndex, ETcRunTime.RT1);
                    int tcStart = (tcIndex < tcLength) ? tcLength : 0;

                    // Read DAQ storage values from TwinCAT
                    tcValues = TcComm.ReadRealArray(tagDaqValues, tcLength * 2, ETcRunTime.RT1);

                    //Copy into newValues array
                    tcNewValues = new float[tcLength];
                    Array.Copy(tcValues, tcStart, tcNewValues, 0, tcLength);

                    // Reset DAQ half full flag
                    TcComm.WriteBool(tagDaqActive, false, ETcRunTime.RT1);

                    lock (dataLock)
                    {
                        Array.Copy(tcValues, tcStart, values, index, tcLength);
                        index = (index + tcLength) % length;
                    }

                    diState   = (UInt16)GetFloatValue(ETcRealTags.DI_24_None);
                    doState   = (UInt16)GetFloatValue(ETcRealTags.DO_25_None);
                    errorCode = (int)GetFloatValue(ETcRealTags.ID_27_ErrorCode);

                    try
                    {
                        OnDaqAvailable(new DaqEventArgs(tcNewValues));
                    }
                    catch (Exception ex)
                    {
                        Debug.Print(ex.ToString());
                    }
                }

                Thread.Sleep(1);
            }
        }