Beispiel #1
0
        /// <summary>
        /// Called when the value of a dynamic property value has changed.
        /// </summary>
        /// <param name="component"> Component that owns the changed property. </param>
        /// <param name="changedProperty"> Changed property. </param>
        /// <param name="oldValue"> Previous value of the changed property. </param>
        public override void OnPropertyValueChanged(SmartComponent component, DynamicProperty changedProperty, Object oldValue)
        {
            if (changedProperty.Name == "Status")
            {
                return;
            }

            base.OnPropertyValueChanged(component, changedProperty, oldValue);
            if (bOnLoad)
            {
                UpdateComponentList(component);
                UpdateControllers(component);
                isOnPropertyValueChanged[component.UniqueId] = false;
                return;
            }
            if (!isOnPropertyValueChanged.ContainsKey(component.UniqueId))
            {
                isOnPropertyValueChanged[component.UniqueId] = false;
            }

            bool bIsOnPropertyValueChanged = isOnPropertyValueChanged[component.UniqueId];

            isOnPropertyValueChanged[component.UniqueId] = true;

            if (changedProperty.Name == "Controller")
            {
                if ((string)changedProperty.Value != "Update")
                {
                    if (GetController(component) != null)
                    {
                        Logger.AddMessage("RSMoveMecha: Connecting Component " + component.Name + " to " + (string)changedProperty.Value, LogMessageSeverity.Information);
                        component.Properties["Status"].Value = "Connected";
                    }
                }
            }
            if (changedProperty.Name == "CtrlMechanism")
            {
                GetController(component);
            }
            if (changedProperty.Name == "Mechanism")
            {
                Mechanism mecha = (Mechanism)component.Properties["Mechanism"].Value;
                if (mecha != null)
                {
                    int[] mechaAxes         = mecha.GetActiveJoints();
                    int   iMechNumberOfAxes = mechaAxes.Length;
                    component.Properties["MechSpecAxis"].Attributes["MaxValue"] = iMechNumberOfAxes.ToString();
                }
            }

            if (!bIsOnPropertyValueChanged)
            {
                //Update available controller
                UpdateControllers(component);
                //Save Modified Component for EventHandlers
                UpdateComponentList(component);
            }

            isOnPropertyValueChanged[component.UniqueId] = bIsOnPropertyValueChanged;
        }
Beispiel #2
0
        /// <summary>
        /// Update Mechanism axes values
        /// </summary>
        /// <param name="component">Component that owns signals. </param>
        /// <param name="jtValue">JointTarget Value</param>
        private void UpdateAxis(SmartComponent component, Controller controller)
        {
            int iCtrlMechanismIndex = (int)component.Properties["CtrlMechanism"].Value;

            if ((iCtrlMechanismIndex < 1) || (iCtrlMechanismIndex > controller.MotionSystem.MechanicalUnits.Count))
            {
                component.Properties["CtrlMechanism"].Value = iCtrlMechanismIndex = 1;
            }

            //Get Controller Values
            ABB.Robotics.Controllers.MotionDomain.MechanicalUnit mu = controller.MotionSystem.MechanicalUnits[iCtrlMechanismIndex - 1];
            int         iCtrlNumberOfAxes = mu.NumberOfAxes;
            JointTarget jtValue           = mu.GetPosition();

            component.Properties["CtrlSpecAxis"].Attributes["MaxValue"] = iCtrlNumberOfAxes.ToString();
            int iCtrlSpecAxis = (int)component.Properties["CtrlSpecAxis"].Value;

            if (iCtrlSpecAxis > iCtrlNumberOfAxes)
            {
                component.Properties["CtrlSpecAxis"].Value = iCtrlSpecAxis = iCtrlNumberOfAxes;
            }
            if (iCtrlSpecAxis < 0)
            {
                component.Properties["CtrlSpecAxis"].Value = iCtrlSpecAxis = 0;
            }

            //Get Mechanism Values
            Mechanism mecha = (Mechanism)component.Properties["Mechanism"].Value;

            if (mecha == null)
            {
                return;
            }
            int[] mechaAxes         = mecha.GetActiveJoints();
            int   iMechNumberOfAxes = mechaAxes.Length;

            double[] mechaValues = mecha.GetJointValues();
            component.Properties["MechSpecAxis"].Attributes["MaxValue"] = iMechNumberOfAxes.ToString();
            int iMechSpecAxis = (int)component.Properties["MechSpecAxis"].Value;

            if (iMechSpecAxis > iCtrlNumberOfAxes)
            {
                component.Properties["MechSpecAxis"].Value = iMechSpecAxis = iMechNumberOfAxes;
            }
            if (iMechSpecAxis < 0)
            {
                component.Properties["MechSpecAxis"].Value = iMechSpecAxis = 0;
            }

            //Start Updating
            int iAxesUpdated = 0;

            if (iCtrlSpecAxis == 0)
            {
                if (iMechSpecAxis == 0)
                {                 //Take all Controller axes to update all Mechanism
                    for (int iAxis = 1; (iAxis <= iCtrlNumberOfAxes) && (iAxis <= iMechNumberOfAxes); ++iAxis)
                    {
                        mechaValues[iAxis - 1] = GetJointTargetAxis(jtValue, iAxis, mu.Type);
                    }
                }
                else
                {                 //Only Take Mechanism Specific axis from controller to update it
                    if ((iMechSpecAxis <= iCtrlNumberOfAxes) && (iMechSpecAxis <= iMechNumberOfAxes))
                    {
                        mechaValues[iMechSpecAxis - 1] = GetJointTargetAxis(jtValue, iMechSpecAxis, mu.Type);
                    }
                }
            }
            else
            {
                if (iMechSpecAxis == 0)
                {                 //Only Take Controller Specific axis to update same in Mechanism
                    if ((iCtrlSpecAxis <= iCtrlNumberOfAxes) && (iCtrlSpecAxis <= iMechNumberOfAxes))
                    {
                        mechaValues[iCtrlSpecAxis - 1] = GetJointTargetAxis(jtValue, iCtrlSpecAxis, mu.Type);
                    }
                }
                else
                {                 //Only Take Controller Specific axis to update Mechanism Specific axis
                    if ((iCtrlSpecAxis <= iCtrlNumberOfAxes) && (iMechSpecAxis <= iMechNumberOfAxes))
                    {
                        mechaValues[iMechSpecAxis - 1] = GetJointTargetAxis(jtValue, iCtrlSpecAxis, mu.Type);
                    }
                }
            }


            iAxesUpdated = ((iCtrlSpecAxis == 0) && (iMechSpecAxis == 0)) ? Math.Min(iCtrlNumberOfAxes, iMechNumberOfAxes) : 1;

            //Updating
            if (!mecha.SetJointValues(mechaValues, true))
            {
                component.Properties["Status"].Value = "Error";
                Logger.AddMessage("RSMoveMecha: Component " + component.Name + " can't update " + mecha.Name + ".", LogMessageSeverity.Error);
            }
            else
            {
                string sNumberOfAxesStatus = iAxesUpdated.ToString() + "/" + iMechNumberOfAxes.ToString() + " Mechanism axes updated from " + iCtrlNumberOfAxes.ToString() + " Controller axes.";
                component.Properties["NumberOfAxesStatus"].Value = sNumberOfAxesStatus;
            }
        }