Пример #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);
        }
Пример #2
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);
        }
Пример #3
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);
            }
        }