/// <summary> /// Loads a new robot and manipulator from given directorys /// </summary> /// <param name="directory">robot directory</param> /// <returns>whether the process was successful</returns> public bool LoadRobotWithManipulator(string baseDirectory, string manipulatorDirectory) { if (SpawnedRobots.Count >= MAX_ROBOTS) { return(false); } robotPath = baseDirectory; GameObject robotObject = new GameObject("Robot"); MaMRobot robot = robotObject.AddComponent <MaMRobot>(); robot.FilePath = robotPath; //Initialiezs the physical robot based off of robot directory. Returns false if not sucessful if (!robot.InitializeRobot(baseDirectory)) { return(false); } //If this is the first robot spawned, then set it to be the active robot and initialize the robot camera on it if (ActiveRobot == null) { ActiveRobot = robot; } robot.ControlIndex = SpawnedRobots.Count; SpawnedRobots.Add(robot); DPMDataHandler.Load(robotPath); return(robot.InitializeManipulator(manipulatorDirectory)); }
/// <summary> /// If there are two robots or more, remove and delete the robot at that index /// </summary> public void RemoveRobot(int index) { if (index < SpawnedRobots.Count) { robotCameraManager.RemoveCamerasFromRobot(SpawnedRobots[index]); sensorManager.RemoveSensorsFromRobot(SpawnedRobots[index]); // TODO: The camera is a bit weird when changing robots. Fix that. Then test other aspects of the simulator and fix anything else that needs fixing. MaMRobot mamRobot = SpawnedRobots[index] as MaMRobot; if (mamRobot != null && mamRobot.RobotHasManipulator) { UnityEngine.Object.Destroy(mamRobot.ManipulatorObject); } UnityEngine.Object.Destroy(SpawnedRobots[index].gameObject); SpawnedRobots.RemoveAt(index); ActiveRobot = null; SwitchActiveRobot(); int i = 0; foreach (SimulatorRobot robot in SpawnedRobots) { robot.ControlIndex = i; i++; } } }
/// <summary> /// Changes the drive base, destroys old manipulator and creates new manipulator, sets wheels /// </summary> public void MaMChangeRobot(string robotDirectory, string manipulatorDirectory) { MaMRobot mamRobot = State.ActiveRobot as MaMRobot; robotCameraManager.DetachCamerasFromRobot(State.ActiveRobot); sensorManager.RemoveSensorsFromRobot(State.ActiveRobot); //If the current robot has a manipulator, destroy the manipulator if (mamRobot != null && mamRobot.RobotHasManipulator) { State.DeleteManipulatorNodes(); } State.ChangeRobot(robotDirectory, true); //If the new robot has a manipulator, load the manipulator if (RobotTypeManager.HasManipulator) { State.LoadManipulator(manipulatorDirectory); } else if (mamRobot != null) { mamRobot.RobotHasManipulator = false; } }
/// <summary> /// Changes the drive base, destroys old manipulator and creates new manipulator, sets wheels /// </summary> public void MaMChangeRobot(string robotDirectory, string manipulatorDirectory) { MaMRobot mamRobot = State.ActiveRobot as MaMRobot; robotCameraManager.DetachCamerasFromRobot(State.ActiveRobot); sensorManager.RemoveSensorsFromRobot(State.ActiveRobot); //If the current robot has a manipulator, destroy the manipulator if (mamRobot != null && mamRobot.RobotHasManipulator) { State.DeleteManipulatorNodes(); } if (!State.ChangeRobot(robotDirectory, true)) { AppModel.ErrorToMenu("ROBOT_SELECT|Failed to load Mix & Match robot"); } //If the new robot has a manipulator, load the manipulator if (RobotTypeManager.HasManipulator) { State.LoadManipulator(manipulatorDirectory); } else if (mamRobot != null) { mamRobot.RobotHasManipulator = false; } }
/// <summary> /// If there are two robots or more, remove and delete the robot at that index /// </summary> public void RemoveRobot(int index) { if (index < SpawnedRobots.Count) { //remove attached sensors/cameras robotCameraManager.RemoveCamerasFromRobot(SpawnedRobots[index]); sensorManager.RemoveSensorsFromRobot(SpawnedRobots[index]); MaMRobot mamRobot = SpawnedRobots[index] as MaMRobot; if (mamRobot != null && mamRobot.RobotHasManipulator) { UnityEngine.Object.Destroy(mamRobot.ManipulatorObject); } UnityEngine.Object.Destroy(SpawnedRobots[index].gameObject); SpawnedRobots.RemoveAt(index); ActiveRobot = null; SwitchActiveRobot(index < SpawnedRobots.Count() ? index : SpawnedRobots.Count() - 1); //switch to either old location or last active robot int i = 0; foreach (SimulatorRobot robot in SpawnedRobots) { robot.ControlIndex = i; i++; } } }
/// <summary> /// Loads a manipulator for Mix and Match mode and maps it to the robot. /// </summary> /// <param name="directory"></param> /// <returns></returns> public bool LoadManipulator(string directory) { MaMRobot mamRobot = ActiveRobot as MaMRobot; if (mamRobot == null) { return(false); } mamRobot.RobotHasManipulator = true; return(mamRobot.InitializeManipulator(directory)); }
/// <summary> /// Loads a new robot from a given directory /// </summary> /// <param name="directory">robot directory</param> /// <returns>whether the process was successful</returns> public bool LoadRobot(string directory, bool isMixAndMatch) { if (SpawnedRobots.Count < MAX_ROBOTS) { GameObject robotObject = new GameObject("Robot"); SimulatorRobot robot; if (isMixAndMatch) { robotPath = RobotTypeManager.RobotPath; MaMRobot mamRobot = robotObject.AddComponent <MaMRobot>(); mamRobot.RobotHasManipulator = false; // Defaults to false robot = mamRobot; } else { robotPath = directory; robot = robotObject.AddComponent <SimulatorRobot>(); } robot.FilePath = robotPath; //Initialiezs the physical robot based off of robot directory. Returns false if not sucessful if (!robot.InitializeRobot(robotPath)) { return(false); } //If this is the first robot spawned, then set it to be the active robot and initialize the robot camera on it if (ActiveRobot == null) { ActiveRobot = robot; } robot.ControlIndex = SpawnedRobots.Count; SpawnedRobots.Add(robot); DPMDataHandler.Load(robotPath); if (!isMixAndMatch && !PlayerPrefs.HasKey(robot.RootNode.GUID.ToString()) && !SampleRobotGUIDs.Contains(robot.RootNode.GUID.ToString())) { if (PlayerPrefs.GetInt("analytics") == 1) { PlayerPrefs.SetString(robot.RootNode.GUID.ToString(), "analyzed"); Analytics.CustomEvent(robot.RootNode.exportedWith.ToString(), new Dictionary <string, object> { }); } } return(true); } return(false); }
/// <summary> /// Changes the active robot to a new robot with a given directory /// </summary> /// <param name="directory"></param> /// <returns>whether the process was successful</returns> public bool ChangeRobot(string directory, bool isMixAndMatch) { sensorManager.RemoveSensorsFromRobot(ActiveRobot); sensorManagerGUI.ShiftOutputPanels(); sensorManagerGUI.EndProcesses(); int index = SpawnedRobots.IndexOf(ActiveRobot); robotCameraManager.RemoveCamerasFromRobot(SpawnedRobots[index]); sensorManager.RemoveSensorsFromRobot(SpawnedRobots[index]); MaMRobot mamRobot = SpawnedRobots[index] as MaMRobot; if (mamRobot != null && mamRobot.RobotHasManipulator) { UnityEngine.Object.Destroy(mamRobot.ManipulatorObject); } UnityEngine.Object.Destroy(SpawnedRobots[index].gameObject); ActiveRobot = null; if (LoadRobot(directory, isMixAndMatch, index)) { DynamicCamera.ControlEnabled = true; int i = 0; foreach (SimulatorRobot robot in SpawnedRobots) { robot.ControlIndex = i; i++; } return(true); } return(false); }
/// <summary> /// Used to delete manipulator nodes in MaM mode /// </summary> public void DeleteManipulatorNodes() { MaMRobot mamRobot = ActiveRobot as MaMRobot; mamRobot?.DeleteManipulatorNodes(); }
/// <summary> /// Loads a new robot from a given directory /// </summary> /// <param name="directory">robot directory</param> /// <returns>whether the process was successful</returns> public bool LoadRobot(string directory, bool isMixAndMatch, int replacementIndex) { bool b = true; if (!Directory.Exists(directory)) { return(false); } else { string[] files = Directory.GetFiles(directory); foreach (string a in files) { string name = Path.GetFileName(a); if (name.ToLower().Contains("skeleton")) { b = false; } } } if (b) { return(false); } if (SpawnedRobots.Count < MAX_ROBOTS) { GameObject robotObject = new GameObject("Robot"); SimulatorRobot robot; if (isMixAndMatch) { robotPath = RobotTypeManager.RobotPath; MaMRobot mamRobot = robotObject.AddComponent <MaMRobot>(); mamRobot.RobotHasManipulator = false; // Defaults to false robot = mamRobot; if (AnalyticsManager.GlobalInstance != null) { AnalyticsManager.GlobalInstance.LogEventAsync(AnalyticsLedger.EventCatagory.LoadRobot, AnalyticsLedger.EventAction.Load, "Robot - Mix and Match", AnalyticsLedger.getMilliseconds().ToString()); } } else { robotPath = directory; robot = robotObject.AddComponent <SimulatorRobot>(); if (AnalyticsManager.GlobalInstance != null) { AnalyticsManager.GlobalInstance.LogEventAsync(AnalyticsLedger.EventCatagory.LoadRobot, AnalyticsLedger.EventAction.Load, "Robot - Exported", AnalyticsLedger.getMilliseconds().ToString()); } } robot.FilePath = robotPath; //Initialiezs the physical robot based off of robot directory. Returns false if not sucessful if (!robot.InitializeRobot(robotPath)) { return(false); } //If this is the first robot spawned, then set it to be the active robot and initialize the robot camera on it if (ActiveRobot == null) { ActiveRobot = robot; } robot.ControlIndex = SpawnedRobots.Count; if (replacementIndex != -1) { SpawnedRobots[replacementIndex] = robot; } else { SpawnedRobots.Add(robot); } DPMDataHandler.Load(robotPath); if (!isMixAndMatch && !PlayerPrefs.HasKey(robot.RootNode.GUID.ToString()) && !SampleRobotGUIDs.Contains(robot.RootNode.GUID.ToString())) { AnalyticsManager.GlobalInstance.LogEventAsync(AnalyticsLedger.EventCatagory.LoadRobot, AnalyticsLedger.EventAction.Load, robot.RootNode.GUID.ToString(), AnalyticsLedger.getMilliseconds().ToString()); } return(true); } return(false); }