public override MBoolResponse AssignInstruction(MInstruction instruction, MSimulationState avatarState) { //Initialize the ik service this.ServiceAccess.IKService.Setup(this.AvatarDescription, new Dictionary <string, string>()); //Create a new constraint manager this.constraintManager = new ConstraintManager(this.SceneAccess); //Assign the instruction this.instruction = instruction; //Set state to ik this.state = ReleaseMotionState.IK; this.trajectoryIndex = 0; //Parse the parameters MBoolResponse response = this.ParseParameters(instruction); if (!response.Successful) { return(response); } return(new MBoolResponse(true)); }
public override MBoolResponse AssignInstruction(MInstruction instruction, MSimulationState simulationState) { this.instruction = instruction; //Get the carry object (if available) this.carryObject = this.SceneAccess.GetSceneObjectByID(instruction.Properties["TargetID"]); //Add the carry object to the virtual scene this.virtualScene.Apply(new MSceneUpdate() { AddedSceneObjects = new List <MSceneObject>() { carryObject } }, true); //Create a new id for the instruction this.currentInstructionID = MInstructionFactory.GenerateID(); //Create a new subinstruction utilizing the moving target MInstruction subInstruction = new MInstruction(currentInstructionID, "NestedMove", "move") { Properties = PropertiesCreator.Create("TargetID", moveTarget.ID, "SubjectID", instruction.Properties["TargetID"], "Hand", instruction.Properties["Hand"]) }; //Assign the instruction at the co-simulation and create a new wrapper instruction return(this.coSimulator.AssignInstruction(subInstruction, simulationState)); }
public InstructionDefinitionWindow(MMIAvatar avatar, ref MInstruction rootInstruction, MInstruction availableInstruction = null) { this.avatar = avatar; this.mmuDescriptions = this.avatar.MMUAccess.GetLoadableMMUs(); this.motionTypeOptions = mmuDescriptions.Select(s => s.MotionType).ToArray(); this.instructionList = rootInstruction.Instructions; if (availableInstruction == null) { this.instruction = new MInstruction(); this.instruction.ID = MInstructionFactory.GenerateID(); this.instruction.Properties = new Dictionary <string, string>(); } else { this.instruction = availableInstruction; //Preselect the motion type if (this.motionTypeOptions.Contains(this.instruction.MotionType)) { this.motionTypeIndex = this.motionTypeOptions.ToList().IndexOf(this.instruction.MotionType); } } }
private void OnGUI() { if (GUI.Button(new Rect(100, 100, 100, 50), "Walk")) { MConstraint walkConstraint = new MConstraint(System.Guid.NewGuid().ToString()) { GeometryConstraint = new MGeometryConstraint("") { ParentToConstraint = new MTransform("", new MVector3(1, 0, 3), new MQuaternion(0, 0, 0, 1)) } }; MInstruction walkInstruction = new MInstruction("walkXY", "walk", "walk") { Properties = new Dictionary <string, string>() { { "TargetID", walkConstraint.ID } }, Constraints = new List <MConstraint>() { walkConstraint } }; this.GetComponent <MMIAvatar>().CoSimulator.AssignInstruction(walkInstruction, null); } }
public HandContainer(HandType type, MInstruction instruction, bool isActive) { this.Type = type; this.Instruction = instruction; this.IsActive = isActive; this.ConstraintID = "Carry:" + type + ":" + System.Guid.NewGuid().ToString(); }
/// <summary> /// Basic constructor /// </summary> /// <param name="type"></param> /// <param name="instruction"></param> /// <param name="isActive"></param> /// <param name="bothHanded"></param> public HandContainer(MJointType type, MInstruction instruction, bool isActive, bool bothHanded = false) : this() { this.Type = type; this.Instruction = instruction; this.IsActive = isActive; this.BothHanded = bothHanded; }
private void OnGUI() { if (GUI.Button(new Rect(270, 100, 200, 25), "Reach (MConstraint)")) { MConstraint reachConstraint = new MConstraint(System.Guid.NewGuid().ToString()) { GeometryConstraint = new MGeometryConstraint("") { ParentToConstraint = new MTransform("", this.ReachTarget.MSceneObject.Transform.Position, this.ReachTarget.MSceneObject.Transform.Rotation) } }; MInstruction reachInstruction = new MInstruction("reachXY", "reach", "Pose/Reach") { Properties = new Dictionary <string, string>() { { "TargetID", reachConstraint.ID }, { "Hand", this.Hand.ToString() } }, Constraints = new List <MConstraint>() { reachConstraint } }; this.GetComponent <MMIAvatar>().CoSimulator.AssignInstruction(reachInstruction, null); } }
void LateUpdate() { if (Execute && !lastState && GazeTarget != null) { MInstruction instruction = new MInstruction(System.Guid.NewGuid().ToString(), "gaze", "Pose/Gaze") { Properties = new Dictionary <string, string>() { { "TargetID", this.GazeTarget.MSceneObject.ID } } }; this.lastInstructionID = instruction.ID; MMIAvatar avatar = this.GetComponent <MMIAvatar>(); //Add the motion type to the cosim avatar.CoSimulator.SetPriority("Pose/Gaze", 10); avatar.CoSimulator.AssignInstruction(instruction, new MSimulationState(avatar.GetPosture(), avatar.GetPosture())); } if (!Execute && lastState) { this.avatar.CoSimulator.Abort(lastInstructionID); } lastState = Execute; }
public override MBoolResponse AssignInstruction(MInstruction instruction, MSimulationState simulationState) { base.AssignInstruction(instruction, simulationState); //Get the gaze target if (instruction.Properties != null && instruction.Properties.ContainsKey("TargetID")) { this.gazeTarget = this.SceneAccess.GetTransformByID(instruction.Properties["TargetID"]); } else { //Return false if no gaze target is defined return(new MBoolResponse(false) { LogData = new List <string>() { "Error, no gaze target defined" } }); } if (instruction.Properties.ContainsKey("LowerLimit")) { this.lowerLimit = float.Parse(instruction.Properties["LowerLimit"], System.Globalization.CultureInfo.InstalledUICulture); } if (instruction.Properties.ContainsKey("UpperLimit")) { this.upperLimit = float.Parse(instruction.Properties["UpperLimit"], System.Globalization.CultureInfo.InstalledUICulture); } return(new MBoolResponse(true)); }
public override MBoolResponse AssignInstruction(MInstruction instruction, MSimulationState simulationState) { //To do -> Check whether the execution is allowed ReachMMUImpl instance = new ReachMMUImpl { SceneAccess = this.SceneAccess, ServiceAccess = this.ServiceAccess, SkeletonAccess = this.SkeletonAccess }; //Get the min distance parameter if (instruction.Properties != null) { instruction.Properties.GetValue(out minReachDistance, "MinDistance"); instruction.Properties.GetValue(out debug, "Debug"); } //Call the instance responsible for the left/right arm instance.Initialize(this.AvatarDescription, new Dictionary <string, string>()); instance.AssignInstruction(instruction, simulationState); //Add the instructions and the mmu instance instructions.Add(instruction); mmuInstances.Add(instruction, instance); return(new MBoolResponse(true)); }
/// <summary> /// Method responsible for the inspector visualization /// </summary> public override void OnInspectorGUI() { //Get the cosimulation debugger instance CoSimulationDebugger debugger = this.target as CoSimulationDebugger; if (debugger.SourceAvatar == null) { GUILayout.Label("Source avatar must be set in order to use the CoSimulationDebugger."); //Call the base inspector base.OnInspectorGUI(); return; } //Check if the present frame is not null if (debugger.currentFrame != null) { GUILayout.Label("Hierachy:"); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); //Draw the initial this.DrawInitial(debugger.currentHierachyIndex == 0); int index = 0; for (int i = 0; i < debugger.currentFrame.Results.Count; i++) { MSimulationResult result = debugger.currentFrame.Results[i]; MInstruction instruction = debugger.GetInstructionByID(debugger.currentFrame.Instructions[i]); DrawHierachyEntry(debugger, result, instruction, index + 1); index++; } GUI.color = Color.blue; for (int i = 0; i < debugger.currentFrame.CoSimulationSolverResults.Count; i++) { MSimulationResult result = debugger.currentFrame.CoSimulationSolverResults[i]; DrawSolverEntry(debugger, result, index + 1); index++; } GUI.color = Color.cyan; //Draw the merged resuls this.DrawMergedResult(debugger, debugger.currentFrame.MergedResult, debugger.currentHierachyIndex == -1); GUI.color = GUI.color = Color.white; } //Call the base inspector base.OnInspectorGUI(); }
public MotionTask(SerializableMotionTask data) { this.Events = data.Events; this.Instruction = data.Instruction; this.IsRunning = data.IsRunning; this.BoundaryConstraints = data.BoundaryConstraints; this.Timing = data.Timing; this.ID = data.ID; }
public static void AddAction(this MInstruction instruction, string topic, string action, string instructionID) { if (instruction.Properties == null) { instruction.Properties = new Dictionary <string, string>(); } instruction.Properties.Add(topic, instructionID + ":" + action); }
/// <summary> /// Checks the prerequisites for the carry motion -> Must be in reach /// </summary> /// <param name="instruction"></param> /// <returns></returns> public override MBoolResponse CheckPrerequisites(MInstruction instruction) { ////Fetch the location of the target object //if (instruction.Properties.ContainsKey("TargetID")) //{ // MTransform targetTransform = this.SceneAccess.GetTransformByID(instruction.Properties["TargetID"]); // MAvatar avatar = this.SceneAccess.GetAvatarByID(this.AvatarDescription.AvatarID); // if (avatar != null && targetTransform != null) // { // MVector3 handPosition = new MVector3(); // //To do -> Use the hand position // if (instruction.Properties.ContainsKey("Hand")) // { // switch (instruction.Properties["Hand"]) // { // case "Left": // handPosition = GetGlobalPosition(avatar.PostureValues, HandType.Left); // break; // case "Right": // handPosition = GetGlobalPosition(avatar.PostureValues, HandType.Right); // break; // case "Both": // //To do // //Check both // break; // } // } // //Estimate the distance between object and hand // double delta = Distance(handPosition, targetTransform.Position); // Logger.Log(Log_level.L_INFO, "Distance: " + delta); // if (delta < 0.1f) // { // Logger.Log(Log_level.L_INFO, "CheckPrerequisites: fulfilled"); // return new MBoolResponse(true); // } // else // { // Logger.Log(Log_level.L_INFO, "CheckPrerequisites not fulfilled"); // return new MBoolResponse(false); // } // } //} return(new MBoolResponse(true)); }
/// <summary> /// Method to assign an instruction to the co-simulation /// </summary> /// <param name="instruction"></param> /// <param name="simulationState"></param> /// <returns></returns> public override MBoolResponse AssignInstruction(MInstruction instruction, MSimulationState simulationState) { this.Instruction = instruction; instruction.Instructions = this.CreateSubInstructions(instruction, simulationState); //Co-simulation internally interprets the instruction and the timing return(this.coSimulator.AssignInstruction(instruction, simulationState)); }
/// <summary> /// Implementation of the check prerequisites method which is used by the co-simulation to determine whether the MMU can be started /// </summary> /// <param name="instruction"></param> /// <returns></returns> public override MBoolResponse CheckPrerequisites(MInstruction instruction) { //Get the min distance parameter if (instruction.Properties != null && instruction.Properties.ContainsKey("MinDistance")) { instruction.Properties.GetValue(out minReachDistance, "MinDistance"); } else { minReachDistance = minDistanceDefault; } if (instruction.Properties.ContainsKey("TargetID")) { MSceneObject sceneObject = this.SceneAccess.GetSceneObjectByID(instruction.Properties["TargetID"]); MAvatar avatar = this.SceneAccess.GetAvatarByID(this.AvatarDescription.AvatarID); if (sceneObject != null && avatar != null) { this.SkeletonAccess.SetChannelData(avatar.PostureValues); //Get the root position MVector3 rootPosition = this.SkeletonAccess.GetGlobalJointPosition(this.AvatarDescription.AvatarID, MJointType.PelvisCentre); rootPosition.Y = 0; //Get the object position MVector3 objectPosition = new MVector3(sceneObject.Transform.Position.X, 0, sceneObject.Transform.Position.Z); //Compute the distance between root and object float distance = rootPosition.Subtract(objectPosition).Magnitude(); //Check if below distance if (distance < this.minReachDistance) { if (this.debug) { Logger.Log(Log_level.L_DEBUG, $"Check prerequisites of reach successfull! Distance: {distance}/{minReachDistance}"); } return(new MBoolResponse(true)); } else { if (this.debug) { Logger.Log(Log_level.L_DEBUG, $"Check prerequisites of reach failed! Distance: {distance}/{minReachDistance}"); } return(new MBoolResponse(false)); } } } return(new MBoolResponse(true)); }
public override MBoolResponse AssignInstruction(MInstruction instruction, MSimulationState simulationState) { //Create a new instance of the skeleton access /intermedaite skeleton this.SkeletonAccess = new IntermediateSkeleton(); //Setup the anthropometry this.SkeletonAccess.InitializeAnthropometry(this.AvatarDescription); base.AssignInstruction(instruction, simulationState); //Parse the duration parameter (if defined) bool durationSet = false; float duration = 1f; if (instruction.Properties.ContainsKey("Duration")) { duration = float.Parse(instruction.Properties["Duration"], System.Globalization.CultureInfo.InvariantCulture); } //Parse the angular velocity parameter (if defined) float angularVelocity = 90f; if (instruction.Properties.ContainsKey("AngularVelocity")) { angularVelocity = float.Parse(instruction.Properties["AngularVelocity"], System.Globalization.CultureInfo.InvariantCulture); } bool release = false; //Parse the release parameter (if defined) if (instruction.Properties.ContainsKey("Release")) { release = bool.Parse(instruction.Properties["Release"]); } //If release is not defined -> the handposture is used if (instruction.Properties.ContainsKey("Hand")) { switch (instruction.Properties["Hand"]) { case "Left": this.SetupHand(MJointType.LeftWrist, instruction, duration, angularVelocity, durationSet, release); break; case "Right": this.SetupHand(MJointType.RightWrist, instruction, duration, angularVelocity, durationSet, release); break; } } return(new MBoolResponse(true)); }
/// <summary> /// Parses the properties attached to the instruction /// </summary> /// <param name="instruction"></param> /// <returns></returns> private bool ParseProperties(MInstruction instruction) { //Flag specifies whether a straigh line path is forced if no path can be obtained if (instruction.Properties.ContainsKey("ForcePath")) { this.useStraightLineIfNoPath = bool.Parse(instruction.Properties["ForcePath"]); } //Flag specifies whether a straigh line path is forced if no path can be obtained if (instruction.Properties.ContainsKey("AngularVelocity")) { this.AngularVelocity = float.Parse(instruction.Properties["AngularVelocity"], System.Globalization.CultureInfo.InvariantCulture); } //The replanning time in ms if (instruction.Properties.ContainsKey("ReplanningTime")) { this.replanningTime = int.Parse(instruction.Properties["ReplanningTime"]); } //The desired velocity if (instruction.Properties != null && instruction.Properties.ContainsKey("Velocity")) { this.Velocity = float.Parse(instruction.Properties["Velocity"]); } //Check if target orientation should be used if (instruction.Properties.ContainsKey("UseTargetOrientation")) { this.useTargetOrientation = bool.Parse(instruction.Properties["UseTargetOrientation"]); } //Check if scene objects should be automatically filtered if (instruction.Properties.ContainsKey("FilterSceneObjects")) { filterSceneObjects = bool.Parse(instruction.Properties["FilterSceneObjects"]); } //Check if scene objects should be automatically filtered if (instruction.Properties.ContainsKey("UseVelocityStoppingThreshold")) { this.useVelocityStoppingThreshold = bool.Parse(instruction.Properties["UseVelocityStoppingThreshold"]); } //Check if mandatory properties are defined -> otherwise skip if (instruction.Properties == null || (!instruction.Properties.ContainsKey("TargetName") && !instruction.Properties.ContainsKey("TargetID"))) { return(false); } //Return true by default return(true); }
/// <summary> /// Add instructions to queue /// </summary> /// <param name="instruction">Instruction to add</param> /// <param name="instructionText">Text to display</param> public void AddItem(MInstruction instruction, string instructionText) { _queueList.Add(new QueueElement(instruction)); //Instantiate game object to display text var text = Instantiate(Resources.Load("UI/ScrollViewInstruction"), scrollViewContent.transform) as GameObject; if (!(text is null)) { text.GetComponent <TextMeshProUGUI>().text = instructionText; } }
/// <summary> /// Basic constructor /// </summary> /// <param name="avatar"></param> public BehaviorDefinitionWindow(MMIAvatar avatar) { this.avatar = avatar; this.rootInstruction = new MInstruction() { Instructions = new List <MInstruction>(), ID = MInstructionFactory.GenerateID(), MotionType = "Composite" }; this.instructionsArray = this.rootInstruction.Instructions.Select(s => s.Name + " , " + s.MotionType + " , " + s.ID).ToArray(); }
public override MBoolResponse AssignInstruction(MInstruction instruction, MSimulationState simulationState) { base.AssignInstruction(instruction, simulationState); this.instruction = instruction; if (instruction.Properties.ContainsKey("BlendDuration")) { this.blendDuration = float.Parse(instruction.Properties["BlendDuration"], System.Globalization.CultureInfo.InvariantCulture); } return(new MBoolResponse(true)); }
/// <summary> /// Basic constructor instantiating a new AddParameterWindow /// </summary> /// <param name="instruction"></param> /// <param name="description"></param> public AddParameterWindow(ref MInstruction instruction, MMUDescription description) { //Assign the variables this.description = description; this.instruction = instruction; //Get all available parameters List <string> parameterList = description.Parameters.Select(s => s.Name).ToList(); //Add custom -> for undefined parameter parameterList.Add("Custom"); //Set the parameter names for the popup list this.availableParameters = parameterList.ToArray(); }
private InstructionWindow GetInstructionWindow(MInstruction instruction) { InstructionWindow window = new InstructionWindow() { StartIndex = -1, EndIndex = -1, Instruction = instruction }; for (int i = 0; i < this.record.Frames.Count; i++) { CoSimulationFrame frame = this.record.Frames[i]; if (frame.Instructions.Contains(instruction.ID)) { if (window.StartIndex == -1) { window.StartIndex = i; } if (window.EndIndex == -1 || window.EndIndex < i) { window.EndIndex = i; } MSimulationResult result = frame.MergedResult; if (result.Events != null && result.Events.Count > 0) { foreach (MSimulationEvent simEvent in result.Events) { if (simEvent.Reference == instruction.ID) { window.Events.Add(i); window.RawEvents.Add(simEvent); break; } } } } } return(window); }
public virtual List <MConstraint> GetBoundaryConstraints(MInstruction instruction, string mmuID, string sessionID) { SessionContent sessionContent = null; AvatarContent avatarContent = null; MBoolResponse sessionResult = SessionData.GetContents(sessionID, out sessionContent, out avatarContent); if (!sessionResult.Successful) { return(new List <MConstraint>()); } sessionContent.UpdateLastAccessTime(); return(avatarContent.MMUs[mmuID].GetBoundaryConstraints(instruction)); }
public SerializableMotionTask(MotionTask motionTask) { this.ID = motionTask.ID; this.IsRunning = motionTask.IsRunning; //Assign the id if a container is already assigned if (motionTask.MMUContainer != null) { this.ContainerID = motionTask.MMUContainer.ID; } this.Events = motionTask.Events; this.Instruction = motionTask.Instruction; this.BoundaryConstraints = motionTask.BoundaryConstraints; this.Timing = motionTask.Timing; }
public override MBoolResponse AssignInstruction(MInstruction instruction, MSimulationState simulationState) { base.AssignInstruction(instruction, simulationState); if (instruction.Properties.ContainsKey("leftTarget")) { this.LeftHandTarget = this.SceneAccess.GetSceneObjectByID(instruction.Properties["leftTarget"]); } if (instruction.Properties.ContainsKey("rightTarget")) { this.RightHandTarget = this.SceneAccess.GetSceneObjectByID(instruction.Properties["rightTarget"]); } return(new MBoolResponse(true)); }
/// <summary> /// Basic update routine /// </summary> void Update() { ///Handle the walk command on mouse click if (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButtonDown(0)) { Vector3 mousePos = Input.mousePosition; Ray mouseRay = Camera.main.ScreenPointToRay(mousePos); RaycastHit hit = new RaycastHit(); if (Physics.Raycast(mouseRay, out hit, 10000)) { //Ray for visual guide from camera to mouse position. Debug.DrawRay(mouseRay.origin, mouseRay.direction * hit.distance, Color.red, 1); GameObject walkTarget = GameObject.Find("WalkTarget"); walkTarget.transform.position = new Vector3(hit.point.x, walkTarget.transform.position.y, hit.point.z); walkTarget.GetComponent <MMISceneObject>().UpdateTransform(); MInstruction walkInstruction = new MInstruction(MInstructionFactory.GenerateID(), "Walk", "Locomotion/Walk") { Properties = PropertiesCreator.Create("TargetName", "WalkTarget", "UseTargetOrientation", false.ToString()) }; MInstruction idleInstruction = new MInstruction(MInstructionFactory.GenerateID(), "Idle", "Pose/Idle") { //Start idle after walk has been finished StartCondition = walkInstruction.ID + ":" + mmiConstants.MSimulationEvent_End //synchronization constraint similar to bml "id:End" (bml original: <bml start="id:End"/> }; //Abort all current tasks this.CoSimulator.Abort(); MSimulationState currentState = new MSimulationState() { Initial = this.avatar.GetPosture(), Current = this.avatar.GetPosture() }; //Assign walk and idle instruction this.CoSimulator.AssignInstruction(walkInstruction, currentState); this.CoSimulator.AssignInstruction(idleInstruction, currentState); } } }
private void StartInstruction() { this.WalkTarget.transform.position = new Vector3(Random.Range(-9, 9), 0, Random.Range(-9, 9)); this.WalkTarget.Synchronize(); this.currentInstruction = new MInstruction(MInstructionFactory.GenerateID(), "Walk", "Locomotion/Walk") { Properties = new Dictionary <string, string>() { { "TargetID", this.WalkTarget.MSceneObject.ID }, { "ForcePath", true.ToString() }, { "UseTargetOrientation", false.ToString() } } }; this.CoSimulator.AssignInstruction(this.currentInstruction, null); }
/// <summary> /// Method to assign an instruction /// </summary> /// <param name="motionCommand"></param> /// <param name="simulationState"></param> /// <returns></returns> public override MBoolResponse AssignInstruction(MInstruction motionInstruction, MSimulationState simulationState) { //Execute instructions on main thread this.ExecuteOnMainThread(() => { //Assign the posture this.AssignPostureValues(simulationState.Current); //this.transform.position = this.SkeletonAccess.GetRootPosition(this.AvatarDescription.AvatarID).ToVector3(); //this.transform.rotation = this.SkeletonAccess.GetRootRotation(this.AvatarDescription.AvatarID).ToQuaternion(); //Update the animator initially this.animator.Update(0.1f); }); return(new MBoolResponse(true)); }
/// <summary> /// Walk to selected object /// </summary> public void WalkTo() { GameObject go; GameObject walkTarget; try { //Get selected object go = selectObject.GetObject(); } catch (NullReferenceException) { SSTools.ShowMessage("No object selected", SSTools.Position.bottom, SSTools.Time.twoSecond); return; } //If walk target is selected, switch to parent if (go.transform.name.Equals("WalkTarget")) { go = go.transform.parent.gameObject; } try { //Get walk target of selected object //walkTarget = go.transform.GetChildRecursiveByName("WalkTarget").gameObject; walkTarget = go.transform.Find("WalkTarget").gameObject; } catch (NullReferenceException) { SSTools.ShowMessage("No walk target found", SSTools.Position.bottom, SSTools.Time.twoSecond); return; } String objectID = walkTarget.GetComponent <MMISceneObject>().MSceneObject.ID; //Create instruction MInstruction walkInstruction = new MInstruction(MInstructionFactory.GenerateID(), "Walk", "Locomotion/Walk") { Properties = PropertiesCreator.Create("TargetID", objectID, "ForcePath", "true") }; //Add instruction to queue queueController.AddItem(walkInstruction, "Walk to " + go.name); }