/// <summary>
        /// Method parses the parameters
        /// </summary>
        /// <param name="instruction"></param>
        /// <returns></returns>
        private MBoolResponse ParseParameters(MInstruction instruction)
        {
            MBoolResponse response = new MBoolResponse(true);

            //Get the target hand
            if (instruction.Properties.ContainsKey("Hand"))
            {
                if (instruction.Properties["Hand"] == "Left")
                {
                    this.handJoint = MJointType.LeftWrist;
                }

                if (instruction.Properties["Hand"] == "Right")
                {
                    this.handJoint = MJointType.RightWrist;
                }
            }
            //Error target hand not specified
            else
            {
                return(new MBoolResponse(false)
                {
                    LogData = new List <string>()
                    {
                        "Required parameter hand not defined"
                    }
                });
            }


            if (instruction.Properties.ContainsKey("Velocity"))
            {
                this.velocity = float.Parse(instruction.Properties["Velocity"], System.Globalization.CultureInfo.InvariantCulture);
            }

            if (instruction.Properties.ContainsKey("AngularVelocity"))
            {
                this.angularVelocity = float.Parse(instruction.Properties["AngularVelocity"], System.Globalization.CultureInfo.InvariantCulture);
            }

            if (instruction.Properties.ContainsKey("UseBlending"))
            {
                bool.TryParse("UseBlending", out bool useBlending);
                this.useIK = !useBlending;
            }

            if (instruction.Properties.ContainsKey("EndBlendDuration"))
            {
                this.endBlendDuration = float.Parse(instruction.Properties["EndBlendDuration"], System.Globalization.CultureInfo.InvariantCulture);
            }

            //First extract all parameters
            if (instruction.Properties.ContainsKey("Trajectory"))
            {
                string pathConstraintID = instruction.Properties["Trajectory"];


                if (instruction.Constraints != null || instruction.Constraints.Where(s => s.PathConstraint != null && s.ID == pathConstraintID).Count() == 0)
                {
                    //Get the path constraint
                    MPathConstraint pathConstraint = instruction.Constraints.Find(s => s.PathConstraint != null && s.ID == pathConstraintID).PathConstraint;

                    //Extract the trajectory
                    this.trajectory = pathConstraint.GetMTransformList();

                    //Add the target transform
                    this.trajectory.Add(new MTransform("targetTransform", new MVector3(0, 0, 0), new MQuaternion(0, 0, 0, 1)));

                    MMICSharp.Adapter.Logger.Log(MMICSharp.Adapter.Log_level.L_INFO, $"Assigned hand trajectory. Number elements: {trajectory.Count}, hand: {this.handJoint}");
                }
                else
                {
                    MMICSharp.Adapter.Logger.Log(MMICSharp.Adapter.Log_level.L_ERROR, $"Cannot assign trajectory of hand: {this.handJoint}. No suitable MPathConstraint available.");
                }
            }

            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// Methods parses the parameters defined in the MInstruction
        /// </summary>
        /// <param name="instruction"></param>
        /// <returns></returns>
        private MBoolResponse ParseParameters(MInstruction instruction)
        {
            //Extract the single shot ik parameter if defined
            if (instruction.Properties.ContainsKey("SingleShotIK"))
            {
                bool.TryParse(instruction.Properties["SingleShotIK"], out singleShotIK);
            }

            //Extract the velocity if defined
            if (instruction.Properties.ContainsKey("Velocity"))
            {
                this.velocity = float.Parse(instruction.Properties["Velocity"], System.Globalization.CultureInfo.InvariantCulture);
            }

            //Extract the angular velocity
            if (instruction.Properties.ContainsKey("AngularVelocity"))
            {
                this.angularVelocity = float.Parse(instruction.Properties["AngularVelocity"], System.Globalization.CultureInfo.InvariantCulture);
            }


            //Extract the information with regard to the target
            if (instruction.Properties.ContainsKey("TargetID"))
            {
                //Use the constraint (if defined)
                if (instruction.Constraints != null && instruction.Constraints.Exists(s => s.ID == instruction.Properties["TargetID"]))
                {
                    MConstraint match = instruction.Constraints.Find(s => s.ID == instruction.Properties["TargetID"]);
                    this.targetTransform = new MTransform()
                    {
                        ID       = "target",
                        Position = match.GeometryConstraint.GetGlobalPosition(this.SceneAccess),
                        Rotation = match.GeometryConstraint.GetGlobalRotation(this.SceneAccess)
                    };

                    MMICSharp.Adapter.Logger.Log(MMICSharp.Adapter.Log_level.L_DEBUG, "Using MGeometryConstraint for target definition");
                }

                //Gather from the scene
                else
                {
                    this.targetTransform = this.SceneAccess.GetTransformByID(instruction.Properties["TargetID"]);
                }
            }
            //Error id not available
            else
            {
                return(new MBoolResponse(false)
                {
                    LogData = new List <string>()
                    {
                        "Required parameter Target ID not defined"
                    }
                });
            }

            //Get the target hand
            if (instruction.Properties.ContainsKey("Hand"))
            {
                if (instruction.Properties["Hand"] == "Left")
                {
                    this.handJoint = MJointType.LeftWrist;
                }

                if (instruction.Properties["Hand"] == "Right")
                {
                    this.handJoint = MJointType.RightWrist;
                }
            }
            //Error target hand not specified
            else
            {
                return(new MBoolResponse(false)
                {
                    LogData = new List <string>()
                    {
                        "Required parameter hand not defined"
                    }
                });
            }


            //First extract all parameters
            if (instruction.Properties.ContainsKey("Trajectory"))
            {
                string pathConstraintID = instruction.Properties["Trajectory"];


                if (instruction.Constraints != null || instruction.Constraints.Where(s => s.PathConstraint != null && s.ID == pathConstraintID).Count() == 0)
                {
                    //Get the path constraint
                    MPathConstraint pathConstraint = instruction.Constraints.Find(s => s.PathConstraint != null && s.ID == pathConstraintID).PathConstraint;

                    //Extract the trajectory
                    this.trajectory = pathConstraint.GetMTransformList();

                    MMICSharp.Adapter.Logger.Log(MMICSharp.Adapter.Log_level.L_INFO, $"Assigned hand trajectory. Number elements: {trajectory.Count}, hand: {this.handJoint}");
                }
                else
                {
                    MMICSharp.Adapter.Logger.Log(MMICSharp.Adapter.Log_level.L_ERROR, $"Cannot assign trajectory of hand: {this.handJoint}. No suitable MPathConstraint available.");
                }
            }

            return(new MBoolResponse(true));
        }
Beispiel #3
0
        /// <summary>
        /// Method is used to setup the parameters of one individual hand
        /// </summary>
        /// <param name="type"></param>
        /// <param name="instruction"></param>
        private void SetupHand(MJointType type, MInstruction instruction)
        {
            HandContainer hand = this.activeHands.Find(s => s.Type == type);

            if (hand != null)
            {
                this.activeHands.Remove(hand);
            }


            //Create a new hand
            hand = new HandContainer(type, instruction, true);

            if (instruction.Properties.ContainsKey("Velocity"))
            {
                hand.Velocity = float.Parse(instruction.Properties["Velocity"], System.Globalization.CultureInfo.InvariantCulture);
            }

            if (instruction.Properties.ContainsKey("AngularVelocity"))
            {
                hand.AngularVelocity = float.Parse(instruction.Properties["AngularVelocity"], System.Globalization.CultureInfo.InvariantCulture);
            }

            if (instruction.Properties.ContainsKey("Acceleration"))
            {
                hand.Acceleration = float.Parse(instruction.Properties["Acceleration"], System.Globalization.CultureInfo.InvariantCulture);
            }

            if (instruction.Properties.ContainsKey("HoldDuration"))
            {
                hand.HoldTime = float.Parse(instruction.Properties["HoldDuration"], System.Globalization.CultureInfo.InvariantCulture);
            }

            if (instruction.Properties.ContainsKey("CollisionAvoidance"))
            {
                hand.CollisionAvoidance = bool.Parse(instruction.Properties["CollisionAvoidance"]);

                if (hand.CollisionAvoidance)
                {
                    MMICSharp.Adapter.Logger.Log(MMICSharp.Adapter.Log_level.L_INFO, $"Using local collision avoidance, hand: {hand.Type}");
                }
            }


            //First extract all parameters
            if (instruction.Properties.ContainsKey("Trajectory"))
            {
                string pathConstraintID = instruction.Properties["Trajectory"];

                if (instruction.Constraints != null || instruction.Constraints.Where(s => s.PathConstraint != null && s.ID == pathConstraintID).Count() == 0)
                {
                    //Get the path constraint
                    MPathConstraint pathConstraint = instruction.Constraints.Find(s => s.PathConstraint != null && s.ID == pathConstraintID).PathConstraint;

                    //Extract the trajectory
                    hand.Trajectory = pathConstraint.GetMTransformList();

                    MMICSharp.Adapter.Logger.Log(MMICSharp.Adapter.Log_level.L_INFO, $"Assigned hand trajectory. Number elements: {hand.Trajectory.Count}, hand: {hand.Type}");
                }
                else
                {
                    MMICSharp.Adapter.Logger.Log(MMICSharp.Adapter.Log_level.L_ERROR, $"Cannot assign trajectory of hand: {hand.Type}. No suitable MPathConstraint available.");
                }
            }


            this.activeHands.Add(hand);
        }