diff --git a/Assets/Editor/ModelsManager.cs b/Assets/Editor/ModelsManager.cs new file mode 100644 index 00000000..4b62a62d --- /dev/null +++ b/Assets/Editor/ModelsManager.cs @@ -0,0 +1,42 @@ +using System.IO; +using System.Net; +using UnityEditor; +using UnityEngine; + +namespace Editor +{ + public static class ModelsManager + { + [MenuItem("Tools/Update Schemas")] + public static void UpdateSchemas() + { + var webClient = new WebClient(); + + webClient.DownloadFile( + "https://raw.githubusercontent.com/VirtualBrainLab/vbl-aquarium/main/models/csharp/EphysLinkModels.cs", + "Assets/Scripts/EphysLink/EphysLinkModels.cs"); + + Debug.Log("Schemas updated successfully!"); + } + + private static void GetSchemas(string srcURL, string outFile) + { + + if (!Directory.Exists(outFile)) + { + Directory.CreateDirectory(outFile); + } + + string[] files = Directory.GetFiles(srcURL, "*.cs"); + + foreach (string file in files) + { + string fileName = Path.GetFileName(file); + string destFilePath = Path.Combine(outFile, fileName); + File.Copy(file, destFilePath, true); + } + + AssetDatabase.Refresh(); + } + } +} \ No newline at end of file diff --git a/Assets/Tests/CommunicationManagerTests.cs.meta b/Assets/Editor/ModelsManager.cs.meta similarity index 83% rename from Assets/Tests/CommunicationManagerTests.cs.meta rename to Assets/Editor/ModelsManager.cs.meta index a105bf5a..50d9373c 100644 --- a/Assets/Tests/CommunicationManagerTests.cs.meta +++ b/Assets/Editor/ModelsManager.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 41f828f7fc4d4b940aca50e298285dcd +guid: b46513fbabf35e34ca320b4cff1cca1c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/EphysLink/CommunicationManager.cs b/Assets/Scripts/EphysLink/CommunicationManager.cs index d6c4ed4d..261514f6 100644 --- a/Assets/Scripts/EphysLink/CommunicationManager.cs +++ b/Assets/Scripts/EphysLink/CommunicationManager.cs @@ -22,7 +22,7 @@ public class CommunicationManager : MonoBehaviour private static readonly int[] EPHYS_LINK_MIN_VERSION = { 1, 2, 8 }; - public static readonly string EPHYS_LINK_MIN_VERSION_STRING = "≥ v" + string.Join(".", EPHYS_LINK_MIN_VERSION); + public static readonly string EPHYS_LINK_MIN_VERSION_STRING = $"≥ v{string.Join(".", EPHYS_LINK_MIN_VERSION)}"; private const string UNKOWN_EVENT = "UNKNOWN_EVENT"; @@ -40,8 +40,15 @@ public class CommunicationManager : MonoBehaviour private void Awake() { - if (Instance != null) Debug.LogError("Make sure there is only one CommunicationManager in the scene!"); - Instance = this; + if (Instance == null) + { + Instance = this; + DontDestroyOnLoad(this); + } + else if (Instance != this) + { + Destroy(this); + } } #endregion @@ -51,7 +58,8 @@ private void Awake() public void ServerSettingsLoaded() { // Automatically connect if the server credentials are possible - if (!IsConnected && Settings.EphysLinkServerIp != "" && Settings.EphysLinkServerPort >= 1025) + if (!IsConnected && !string.IsNullOrEmpty(Settings.EphysLinkServerIp) && + Settings.EphysLinkServerPort >= 1025) ConnectToServer(Settings.EphysLinkServerIp, Settings.EphysLinkServerPort, () => { // Verify Ephys Link version @@ -83,13 +91,13 @@ public void ConnectToServer(string ip, int port, Action onConnected = null, try { // Create a new socket - _connectionManager = new SocketManager(new Uri("http://" + ip + ":" + port), options); + _connectionManager = new SocketManager(new Uri($"http://{ip}:{port}"), options); _socket = _connectionManager.Socket; // On successful connection _socket.Once("connect", () => { - Debug.Log("Connected to WebSocket server at " + ip + ":" + port); + Debug.Log($"Connected to WebSocket server at {ip}:{port}"); IsConnected = true; // Save settings @@ -103,7 +111,7 @@ public void ConnectToServer(string ip, int port, Action onConnected = null, _socket.Once("error", () => { var connectionErrorMessage = - "Error connecting to server at " + ip + ":" + port + ". Check server for details."; + $"Error connecting to server at {ip}:{port}. Check server for details."; Debug.LogWarning(connectionErrorMessage); IsConnected = false; _connectionManager.Close(); @@ -115,7 +123,7 @@ public void ConnectToServer(string ip, int port, Action onConnected = null, // On timeout _socket.Once("connect_timeout", () => { - var connectionTimeoutMessage = "Connection to server at " + ip + ":" + port + " timed out"; + var connectionTimeoutMessage = "Connection to server at {ip}:{port} timed out"; Debug.LogWarning(connectionTimeoutMessage); IsConnected = false; _connectionManager.Close(); @@ -128,7 +136,7 @@ public void ConnectToServer(string ip, int port, Action onConnected = null, { // On socket generation error var connectionErrorMessage = - "Error connecting to server at " + ip + ":" + port + ". Check server for details."; + "Error connecting to server at {ip}:{port}. Check server for details."; Debug.LogWarning(connectionErrorMessage); Debug.LogWarning("Exception: " + e); IsConnected = false; @@ -209,23 +217,23 @@ private void GetVersion(Action onSuccessCallback, Action onErrorCallback /// /// Callback function to handle incoming manipulator ID's /// Callback function to handle errors - public void GetManipulators(Action onSuccessCallback, + public void GetManipulators(Action onSuccessCallback, Action onErrorCallback = null) { _connectionManager.Socket.ExpectAcknowledgement(data => { if (DataKnownAndNotEmpty(data)) { - var parsedData = GetManipulatorsCallbackParameters.FromJson(data); - if (parsedData.error == "") - onSuccessCallback?.Invoke(parsedData.manipulators, parsedData.num_axes, - parsedData.dimensions); + var parsedData = ParseJson(data); + + if (string.IsNullOrEmpty(parsedData.Error)) + onSuccessCallback?.Invoke(parsedData); else - onErrorCallback?.Invoke(parsedData.error); + onErrorCallback?.Invoke(parsedData.Error); } else { - onErrorCallback?.Invoke("get_manipulators invalid response: " + data); + onErrorCallback?.Invoke($"get_manipulators invalid response: {data}"); } }).Emit("get_manipulators"); } @@ -241,10 +249,10 @@ public void RegisterManipulator(string manipulatorId, Action onSuccessCallback = { _connectionManager.Socket.ExpectAcknowledgement(error => { - if (error == "") + if (string.IsNullOrEmpty(error)) onSuccessCallback?.Invoke(); else - onErrorCallback?.Invoke("register_manipulators invalid response: " + error); + onErrorCallback?.Invoke($"register_manipulators invalid response: {error}"); }).Emit("register_manipulator", manipulatorId); } @@ -259,10 +267,10 @@ public void UnregisterManipulator(string manipulatorId, Action onSuccessCallback { _connectionManager.Socket.ExpectAcknowledgement(error => { - if (error == "") + if (string.IsNullOrEmpty(error)) onSuccessCallback?.Invoke(); else - onErrorCallback?.Invoke("unregister_manipulator invalid response: " + error); + onErrorCallback?.Invoke($"unregister_manipulator invalid response: {error}"); }).Emit("unregister_manipulator", manipulatorId); } @@ -279,23 +287,16 @@ public void GetPos(string manipulatorId, Action onSuccessCallback, { if (DataKnownAndNotEmpty(data)) { - var parsedData = PositionalCallbackParameters.FromJson(data); - if (parsedData.error == "") - try - { - onSuccessCallback?.Invoke(new Vector4(parsedData.position[0], parsedData.position[1], - parsedData.position[2], parsedData.position[3])); - } - catch (Exception e) - { - onErrorCallback?.Invoke(e.ToString()); - } + var parsedData = ParseJson(data); + + if (string.IsNullOrEmpty(parsedData.Error)) + onSuccessCallback?.Invoke(parsedData.Position); else - onErrorCallback?.Invoke(parsedData.error); + onErrorCallback?.Invoke(parsedData.Error); } else { - onErrorCallback?.Invoke("get_pos invalid response: " + data); + onErrorCallback?.Invoke($"get_pos invalid response: {data}"); } }).Emit("get_pos", manipulatorId); } @@ -313,23 +314,15 @@ public void GetAngles(string manipulatorId, Action onSuccessCallback, { if (DataKnownAndNotEmpty(data)) { - var parsedData = AngularCallbackParameters.FromJson(data); - if (parsedData.error == "") - try - { - onSuccessCallback?.Invoke(new Vector3(parsedData.angles[0], parsedData.angles[1], - parsedData.angles[2])); - } - catch (Exception e) - { - onErrorCallback?.Invoke(e.ToString()); - } + var parsedData = ParseJson(data); + if (string.IsNullOrEmpty(parsedData.Error)) + onSuccessCallback?.Invoke(parsedData.Angles); else - onErrorCallback?.Invoke(parsedData.error); + onErrorCallback?.Invoke(parsedData.Error); } else { - onErrorCallback?.Invoke("get_angles invalid response: " + data); + onErrorCallback?.Invoke($"get_angles invalid response: {data}"); } }).Emit("get_angles", manipulatorId); } @@ -341,22 +334,15 @@ public void GetShankCount(string manipulatorId, Action onSuccessCallback, { if (DataKnownAndNotEmpty(data)) { - var parsedData = ShankCountCallbackParameters.FromJson(data); - if (parsedData.error == "") - try - { - onSuccessCallback?.Invoke(parsedData.shank_count); - } - catch (Exception e) - { - onErrorCallback?.Invoke(e.ToString()); - } + var parsedData = ParseJson(data); + if (string.IsNullOrEmpty(parsedData.Error)) + onSuccessCallback?.Invoke(parsedData.ShankCount); else - onErrorCallback?.Invoke(parsedData.error); + onErrorCallback?.Invoke(parsedData.Error); } else { - onErrorCallback?.Invoke("get_shank_count invalid response: " + data); + onErrorCallback?.Invoke($"get_shank_count invalid response: {data}"); } }).Emit("get_shank_count", manipulatorId); } @@ -365,99 +351,79 @@ public void GetShankCount(string manipulatorId, Action onSuccessCallback, /// Request a manipulator be moved to a specific position. /// /// Position is defined by a Vector4 - /// ID of the manipulator to be moved - /// Position in mm of the manipulator - /// How fast to move the manipulator (in mm/s) + /// Goto position request object /// Callback function to handle successful manipulator movement /// Callback function to handle errors - public void GotoPos(string manipulatorId, Vector4 pos, float speed, Action onSuccessCallback, + public void GotoPos(GotoPositionRequest request, Action onSuccessCallback, Action onErrorCallback = null) { _connectionManager.Socket.ExpectAcknowledgement(data => { if (DataKnownAndNotEmpty(data)) { - var parsedData = PositionalCallbackParameters.FromJson(data); - if (parsedData.error == "") - try - { - onSuccessCallback?.Invoke(new Vector4(parsedData.position[0], parsedData.position[1], - parsedData.position[2], parsedData.position[3])); - } - catch (Exception e) - { - onErrorCallback?.Invoke(e.ToString()); - } + var parsedData = ParseJson(data); + if (string.IsNullOrEmpty(parsedData.Error)) + onSuccessCallback?.Invoke(parsedData.Position); else - onErrorCallback?.Invoke(parsedData.error); + onErrorCallback?.Invoke(parsedData.Error); } else { - onErrorCallback?.Invoke("goto_pos invalid response: " + data); + onErrorCallback?.Invoke($"goto_pos invalid response: {data}"); } - }).Emit("goto_pos", new GotoPositionInputDataFormat(manipulatorId, pos, speed).ToJson()); + }).Emit("goto_pos", ToJson(request)); } /// /// Request a manipulator drive down to a specific depth. /// - /// ID of the manipulator to move - /// Depth in mm of the manipulator (in needle coordinates) - /// How fast to drive the manipulator (in mm/s) + /// Drive to depth request /// Callback function to handle successful manipulator movement /// Callback function to handle errors - public void DriveToDepth(string manipulatorId, float depth, float speed, Action onSuccessCallback, + public void DriveToDepth(DriveToDepthRequest request, Action onSuccessCallback, Action onErrorCallback) { _connectionManager.Socket.ExpectAcknowledgement(data => { if (DataKnownAndNotEmpty(data)) { - var parsedData = DriveToDepthCallbackParameters.FromJson(data); - if (parsedData.error == "") - try - { - onSuccessCallback?.Invoke(parsedData.depth); - } - catch (Exception e) - { - onErrorCallback?.Invoke(e.ToString()); - } + var parsedData = ParseJson(data); + if (string.IsNullOrEmpty(parsedData.Error)) + onSuccessCallback?.Invoke(parsedData.Depth); else - onErrorCallback?.Invoke(parsedData.error); + onErrorCallback?.Invoke(parsedData.Error); } else { - onErrorCallback?.Invoke("drive_to_depth invalid response: " + data); + onErrorCallback?.Invoke($"drive_to_depth invalid response: {data}"); } - }).Emit("drive_to_depth", new DriveToDepthInputDataFormat(manipulatorId, depth, speed).ToJson()); + }).Emit("drive_to_depth", ToJson(request)); } /// /// Set the inside brain state of a manipulator. /// - /// ID of the manipulator to set the state of - /// State to set to + /// /// Callback function to handle setting inside_brain state successfully /// Callback function to handle errors - public void SetInsideBrain(string manipulatorId, bool inside, Action onSuccessCallback, + public void SetInsideBrain(InsideBrainRequest request, Action onSuccessCallback, Action onErrorCallback = null) { _connectionManager.Socket.ExpectAcknowledgement(data => { if (DataKnownAndNotEmpty(data)) { - var parsedData = StateCallbackParameters.FromJson(data); - if (parsedData.error == "") - onSuccessCallback?.Invoke(parsedData.state); + var parsedData = ParseJson(data); + if (string.IsNullOrEmpty(parsedData.Error)) + onSuccessCallback?.Invoke(parsedData.State); else - onErrorCallback?.Invoke(parsedData.error); + onErrorCallback?.Invoke(parsedData.Error); } else { - onErrorCallback?.Invoke("set_inside_brain invalid response: " + data); + onErrorCallback?.Invoke($"set_inside_brain invalid response: {data}"); } - }).Emit("set_inside_brain", new InsideBrainInputDataFormat(manipulatorId, inside).ToJson()); + }).Emit("set_inside_brain", ToJson(request)); } /// @@ -499,29 +465,27 @@ public void BypassCalibration(string manipulatorId, Action onSuccessCallback, /// /// Request a write lease for a manipulator. /// - /// ID of the manipulator to allow writing - /// Write state to set the manipulator to - /// How many hours a manipulator may have a write lease + /// /// Callback function to handle successfully setting can_write state /// Callback function to handle errors - public void SetCanWrite(string manipulatorId, bool canWrite, float hours, Action onSuccessCallback, + public void SetCanWrite(CanWriteRequest request, Action onSuccessCallback, Action onErrorCallback = null) { _connectionManager.Socket.ExpectAcknowledgement(data => { if (DataKnownAndNotEmpty(data)) { - var parsedData = StateCallbackParameters.FromJson(data); - if (parsedData.error == "") - onSuccessCallback?.Invoke(parsedData.state); + var parsedData = ParseJson(data); + if (string.IsNullOrEmpty(parsedData.Error)) + onSuccessCallback?.Invoke(parsedData.State); else - onErrorCallback?.Invoke(parsedData.error); + onErrorCallback?.Invoke(parsedData.Error); } else { - onErrorCallback?.Invoke("set_can_write invalid response: " + data); + onErrorCallback?.Invoke($"set_can_write invalid response: {data}"); } - }).Emit("set_can_write", new CanWriteInputDataFormat(manipulatorId, canWrite, hours).ToJson()); + }).Emit("set_can_write", ToJson(request)); } /// @@ -539,7 +503,17 @@ public void Stop(Action callback) private static bool DataKnownAndNotEmpty(string data) { - return data is not ("" or UNKOWN_EVENT); + return !string.IsNullOrEmpty(data) && !data.Equals(UNKOWN_EVENT); + } + + private static T ParseJson(string json) + { + return JsonUtility.FromJson(json); + } + + private string ToJson(T data) + { + return JsonUtility.ToJson(data); } #endregion diff --git a/Assets/Scripts/EphysLink/EphysLinkModels.cs b/Assets/Scripts/EphysLink/EphysLinkModels.cs new file mode 100644 index 00000000..fb0e1c79 --- /dev/null +++ b/Assets/Scripts/EphysLink/EphysLinkModels.cs @@ -0,0 +1,135 @@ +using UnityEngine; + +public struct AngularResponse +{ + public Vector3 Angles; + public string Error; + + public AngularResponse(Vector3 angles, string error) + { + Angles = angles; + Error = error; + } +} + +public struct BooleanStateResponse +{ + public bool State; + public string Error; + + public BooleanStateResponse(bool state, string error) + { + State = state; + Error = error; + } +} + +public struct CanWriteRequest +{ + public string ManipulatorId; + public bool CanWrite; + public float Hours; + + public CanWriteRequest(string manipulatorId, bool canWrite, float hours) + { + ManipulatorId = manipulatorId; + CanWrite = canWrite; + Hours = hours; + } +} + +public struct DriveToDepthRequest +{ + public string ManipulatorId; + public float Depth; + public float Speed; + + public DriveToDepthRequest(string manipulatorId, float depth, float speed) + { + ManipulatorId = manipulatorId; + Depth = depth; + Speed = speed; + } +} + +public struct DriveToDepthResponse +{ + public float Depth; + public string Error; + + public DriveToDepthResponse(float depth, string error) + { + Depth = depth; + Error = error; + } +} + + +public struct GetManipulatorsResponse +{ + public string[] Manipulators; + public int NumAxes; + public Vector4 Dimensions; + public string Error; + + public GetManipulatorsResponse(string[] manipulators, int numAxes, Vector4 dimensions, string error) + { + Manipulators = manipulators; + NumAxes = numAxes; + Dimensions = dimensions; + Error = error; + } +} + + +public struct GotoPositionRequest +{ + public string ManipulatorId; + public Vector4 Position; + public float Speed; + + public GotoPositionRequest(string manipulatorId, Vector4 position, float speed) + { + ManipulatorId = manipulatorId; + Position = position; + Speed = speed; + } +} + +public struct InsideBrainRequest +{ + public string ManipulatorId; + public bool Inside; + + public InsideBrainRequest(string manipulatorId, bool inside) + { + ManipulatorId = manipulatorId; + Inside = inside; + } +} + + +public struct PositionalResponse +{ + public Vector4 Position; + public string Error; + + public PositionalResponse(Vector4 position, string error) + { + Position = position; + Error = error; + } +} + +public struct ShankCountResponse +{ + public int ShankCount; + public string Error; + + public ShankCountResponse(int shankCount, string error) + { + ShankCount = shankCount; + Error = error; + } +} + diff --git a/Assets/Scripts/EphysLink/EphysLinkModels.cs.meta b/Assets/Scripts/EphysLink/EphysLinkModels.cs.meta new file mode 100644 index 00000000..b5fde171 --- /dev/null +++ b/Assets/Scripts/EphysLink/EphysLinkModels.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 611420d9ab36933479b7fcc8050ee2e3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Pinpoint/JSON/SceneData.cs b/Assets/Scripts/Pinpoint/JSON/SceneData.cs index 74919782..609f4e22 100644 --- a/Assets/Scripts/Pinpoint/JSON/SceneData.cs +++ b/Assets/Scripts/Pinpoint/JSON/SceneData.cs @@ -12,82 +12,82 @@ public struct SceneData public string Settings; - public static SceneData ToSceneData(string atlasName, string transformName, - RigData[] rigDatas, - ProbeData[] probeDatas, - CraniotomyData[] craniotomyDatas, - string settings) - { - SceneData sceneData = new SceneData(); - sceneData.AtlasName = atlasName; - sceneData.TransformName = transformName; - sceneData.Settings = settings; - - sceneData.Data = new string[rigDatas.Length + probeDatas.Length]; - int di = 0; - - foreach (RigData rigData in rigDatas) - { - SceneDataStorage temp = new SceneDataStorage(); - temp.Type = SceneDataType.Rig; - temp.Data = JsonUtility.ToJson(rigData); - sceneData.Data[di++] = JsonUtility.ToJson(temp); - } - - foreach (ProbeData probeData in probeDatas) - { - SceneDataStorage temp = new SceneDataStorage(); - temp.Type = SceneDataType.Probe; - temp.Data = JsonUtility.ToJson(probeData); - sceneData.Data[di++] = JsonUtility.ToJson(temp); - } - - foreach (CraniotomyData craniotomyData in craniotomyDatas) - { - SceneDataStorage temp = new SceneDataStorage(); - temp.Type = SceneDataType.Craniotomy; - temp.Data = JsonUtility.ToJson(craniotomyData); - sceneData.Data[di++] = JsonUtility.ToJson(temp); - } - - return sceneData; - } - - public static (string atlasName, string transformName, - RigData[] rigDatas, - ProbeData[] probeDatas, - CraniotomyData[] craniotomyDatas) FromSceneData(string sceneDataJSON) - { - SceneData sceneData = JsonUtility.FromJson(sceneDataJSON); - string atlasName = sceneData.AtlasName; - string transformName = sceneData.TransformName; - - List rigDatas = new List(); - List probeDatas = new List(); - List craniotomyDatas = new(); - - foreach (string data in sceneData.Data) - { - SceneDataStorage temp = JsonUtility.FromJson(data); - switch (temp.Type) - { - case SceneDataType.Probe: - probeDatas.Add(JsonUtility.FromJson(temp.Data)); - break; - case SceneDataType.Rig: - rigDatas.Add(JsonUtility.FromJson(temp.Data)); - break; - case SceneDataType.Craniotomy: - craniotomyDatas.Add(JsonUtility.FromJson(temp.Data)); - break; - } - } - - return (atlasName, transformName, - rigDatas.ToArray(), - probeDatas.ToArray(), - craniotomyDatas.ToArray()); - } + // public static SceneData ToSceneData(string atlasName, string transformName, + // RigData[] rigDatas, + // ProbeData[] probeDatas, + // CraniotomyData[] craniotomyDatas, + // string settings) + // { + // SceneData sceneData = new SceneData(); + // sceneData.AtlasName = atlasName; + // sceneData.TransformName = transformName; + // sceneData.Settings = settings; + // + // sceneData.Data = new string[rigDatas.Length + probeDatas.Length]; + // int di = 0; + // + // foreach (RigData rigData in rigDatas) + // { + // SceneDataStorage temp = new SceneDataStorage(); + // temp.Type = SceneDataType.Rig; + // temp.Data = JsonUtility.ToJson(rigData); + // sceneData.Data[di++] = JsonUtility.ToJson(temp); + // } + // + // foreach (ProbeData probeData in probeDatas) + // { + // SceneDataStorage temp = new SceneDataStorage(); + // temp.Type = SceneDataType.Probe; + // temp.Data = JsonUtility.ToJson(probeData); + // sceneData.Data[di++] = JsonUtility.ToJson(temp); + // } + // + // foreach (CraniotomyData craniotomyData in craniotomyDatas) + // { + // SceneDataStorage temp = new SceneDataStorage(); + // temp.Type = SceneDataType.Craniotomy; + // temp.Data = JsonUtility.ToJson(craniotomyData); + // sceneData.Data[di++] = JsonUtility.ToJson(temp); + // } + // + // return sceneData; + // } + + // public static (string atlasName, string transformName, + // RigData[] rigDatas, + // ProbeData[] probeDatas, + // CraniotomyData[] craniotomyDatas) FromSceneData(string sceneDataJSON) + // { + // SceneData sceneData = JsonUtility.FromJson(sceneDataJSON); + // string atlasName = sceneData.AtlasName; + // string transformName = sceneData.TransformName; + // + // List rigDatas = new List(); + // List probeDatas = new List(); + // List craniotomyDatas = new(); + // + // foreach (string data in sceneData.Data) + // { + // SceneDataStorage temp = JsonUtility.FromJson(data); + // switch (temp.Type) + // { + // case SceneDataType.Probe: + // probeDatas.Add(JsonUtility.FromJson(temp.Data)); + // break; + // case SceneDataType.Rig: + // rigDatas.Add(JsonUtility.FromJson(temp.Data)); + // break; + // case SceneDataType.Craniotomy: + // craniotomyDatas.Add(JsonUtility.FromJson(temp.Data)); + // break; + // } + // } + // + // return (atlasName, transformName, + // rigDatas.ToArray(), + // probeDatas.ToArray(), + // craniotomyDatas.ToArray()); + // } public override string ToString() { diff --git a/Assets/Scripts/Pinpoint/Probes/ManipulatorBehaviorController.cs b/Assets/Scripts/Pinpoint/Probes/ManipulatorBehaviorController.cs index 49123910..c720c518 100644 --- a/Assets/Scripts/Pinpoint/Probes/ManipulatorBehaviorController.cs +++ b/Assets/Scripts/Pinpoint/Probes/ManipulatorBehaviorController.cs @@ -149,15 +149,15 @@ private void OnDisable() public void Initialize(string manipulatorID, bool calibrated) { - CommunicationManager.Instance.GetManipulators((ids, numAxes, dimensions) => + CommunicationManager.Instance.GetManipulators(reponse => { // Shortcut exit if we have an invalid manipulator ID - if (!ids.Contains(manipulatorID)) return; + if (!reponse.Manipulators.Contains(manipulatorID)) return; // Set manipulator ID, number of axes, and dimensions ManipulatorID = manipulatorID; - NumAxes = numAxes; - Dimensions = new Vector3(dimensions[0], dimensions[1], dimensions[2]); + NumAxes = reponse.NumAxes; + Dimensions = reponse.Dimensions; // Update transform and space UpdateSpaceAndTransform(); @@ -169,16 +169,24 @@ public void Initialize(string manipulatorID, bool calibrated) // Bypass calibration and start echoing CommunicationManager.Instance.BypassCalibration(manipulatorID, StartEchoing); else - CommunicationManager.Instance.SetCanWrite(manipulatorID, true, 1, - _ => - { - CommunicationManager.Instance.Calibrate(manipulatorID, - () => + CommunicationManager.Instance.SetCanWrite(new CanWriteRequest + { + ManipulatorId = manipulatorID, + CanWrite = true, + Hours = 1 + }, _ => + { + CommunicationManager.Instance.Calibrate(manipulatorID, + () => + { + CommunicationManager.Instance.SetCanWrite(new CanWriteRequest { - CommunicationManager.Instance.SetCanWrite(manipulatorID, false, 0, - _ => StartEchoing()); - }); - }); + ManipulatorId = manipulatorID, + CanWrite = false, + Hours = 0 + }, _ => StartEchoing()); + }); + }); return; void StartEchoing() @@ -302,21 +310,39 @@ public void MoveByWorldSpaceDelta(Vector4 worldSpaceDelta, Action onSucces var targetPosition = pos + new Vector4(manipulatorTransformDelta.x, manipulatorTransformDelta.y, manipulatorTransformDelta.z); // Move manipulator - CommunicationManager.Instance.SetCanWrite(ManipulatorID, true, 1, b => + CommunicationManager.Instance.SetCanWrite(new CanWriteRequest + { + ManipulatorId = ManipulatorID, + CanWrite = true, + Hours = 1 + }, b => { if (!b) return; - CommunicationManager.Instance.GotoPos(ManipulatorID, targetPosition, AUTOMATIC_MOVEMENT_SPEED, + CommunicationManager.Instance.GotoPos( + new GotoPositionRequest + { + ManipulatorId = ManipulatorID, Position = targetPosition, Speed = AUTOMATIC_MOVEMENT_SPEED + }, newPos => { // Process depth movement var targetDepth = newPos.w + manipulatorSpaceDepth; // Move the manipulator CommunicationManager.Instance.DriveToDepth( - ManipulatorID, targetDepth, AUTOMATIC_MOVEMENT_SPEED, + new DriveToDepthRequest + { + ManipulatorId = ManipulatorID, + Depth = targetDepth, + Speed = AUTOMATIC_MOVEMENT_SPEED + }, _ => { - CommunicationManager.Instance.SetCanWrite(ManipulatorID, false, 0, - onSuccessCallback, onErrorCallback); + CommunicationManager.Instance.SetCanWrite(new CanWriteRequest + { + ManipulatorId = ManipulatorID, + CanWrite = false, + Hours = 0 + }, onSuccessCallback, onErrorCallback); }, onErrorCallback); }, onErrorCallback); }, onErrorCallback); @@ -331,14 +357,28 @@ public void MoveByWorldSpaceDelta(Vector4 worldSpaceDelta, Action onSucces public void MoveBackToZeroCoordinate(Action onSuccessCallback, Action onErrorCallBack) { // Send move command - CommunicationManager.Instance.SetCanWrite(ManipulatorID, true, 1, b => + CommunicationManager.Instance.SetCanWrite(new CanWriteRequest + { + ManipulatorId = ManipulatorID, + CanWrite = true, + Hours = 1 + }, b => { if (!b) return; - CommunicationManager.Instance.GotoPos(ManipulatorID, ZeroCoordinateOffset, AUTOMATIC_MOVEMENT_SPEED, + CommunicationManager.Instance.GotoPos(new GotoPositionRequest + { + ManipulatorId = ManipulatorID, + Position = ZeroCoordinateOffset, + Speed = AUTOMATIC_MOVEMENT_SPEED + }, pos => { - CommunicationManager.Instance.SetCanWrite(ManipulatorID, false, 0, _ => onSuccessCallback(pos), - onErrorCallBack); + CommunicationManager.Instance.SetCanWrite(new CanWriteRequest + { + ManipulatorId = ManipulatorID, + CanWrite = false, + Hours = 0 + }, _ => onSuccessCallback(pos), onErrorCallBack); }, onErrorCallBack); }, onErrorCallBack); } @@ -444,7 +484,7 @@ private void EchoPosition(Vector4 pos) // Set probe position (change axes to match probe) var transformedApmldv = BrainAtlasManager.World2T_Vector(zeroCoordinateAdjustedWorldPosition); - + // Split between 3 and 4 axis assignments if (CoordinateTransform.Prefix == "3lhm") _probeController.SetProbePosition(transformedApmldv); diff --git a/Assets/Scripts/Pinpoint/UI/EphysCopilot/DrivePanelHandler.cs b/Assets/Scripts/Pinpoint/UI/EphysCopilot/DrivePanelHandler.cs index e78083e4..7b526865 100644 --- a/Assets/Scripts/Pinpoint/UI/EphysCopilot/DrivePanelHandler.cs +++ b/Assets/Scripts/Pinpoint/UI/EphysCopilot/DrivePanelHandler.cs @@ -406,104 +406,127 @@ public void Drive() // Increment state _driveStateManager.DriveIncrement(); - CommunicationManager.Instance.SetCanWrite(_manipulatorId, true, 1, - canWrite => + CommunicationManager.Instance.SetCanWrite(new CanWriteRequest + { + ManipulatorId = _manipulatorId, + CanWrite = true, + Hours = 1 + }, canWrite => + { + if (!canWrite) return; + + // Do something based on current state + switch (_driveStateManager.State) { - if (!canWrite) return; - - // Do something based on current state - switch (_driveStateManager.State) - { - case DriveState.DrivingToNearTarget: - // Update status text - _statusText.text = "Driving to " + _drivePastTargetDistance * 1000f + - " µm past target..."; - - // Replace drive buttons with stop - _driveGroup.SetActive(false); - _stopButton.SetActive(true); - - // Drive to near target depth - if (position.w < _nearTargetDepth) - CommunicationManager.Instance.DriveToDepth(_manipulatorId, _nearTargetDepth, - _targetDriveSpeed, _ => CompleteAndAdvance(), Debug.LogError); - else - // Already closer than near target depth, so continue - CompleteAndAdvance(); - break; - case DriveState.DrivingToPastTarget: - // Update status text - _statusText.text = "Driving to " + _drivePastTargetDistance * 1000f + - " µm past target..."; - - // Replace drive buttons with stop - _driveGroup.SetActive(false); - _stopButton.SetActive(true); - - // Drive to past target depth - if (position.w < _pastTargetDepth) - CommunicationManager.Instance.DriveToDepth(_manipulatorId, _pastTargetDepth, - _nearTargetDriveSpeed, _ => CompleteAndAdvance(), Debug.LogError); - else - // Already further than past target depth, so continue - CompleteAndAdvance(); - break; - case DriveState.ReturningToTarget: - // Update status text - _statusText.text = "Returning to target..."; - - // Replace drive buttons with stop - _driveGroup.SetActive(false); - _stopButton.SetActive(true); - - // Drive to target and complete movement - CommunicationManager.Instance.DriveToDepth( - _manipulatorId, _targetDepth, - _nearTargetDriveSpeed, _ => + case DriveState.DrivingToNearTarget: + // Update status text + _statusText.text = "Driving to " + _drivePastTargetDistance * 1000f + + " µm past target..."; + + // Replace drive buttons with stop + _driveGroup.SetActive(false); + _stopButton.SetActive(true); + + // Drive to near target depth + if (position.w < _nearTargetDepth) + CommunicationManager.Instance.DriveToDepth(new DriveToDepthRequest + { + ManipulatorId = _manipulatorId, + Depth = _nearTargetDepth, + Speed = _targetDriveSpeed + }, _ => CompleteAndAdvance(), Debug.LogError); + else + // Already closer than near target depth, so continue + CompleteAndAdvance(); + break; + case DriveState.DrivingToPastTarget: + // Update status text + _statusText.text = "Driving to " + _drivePastTargetDistance * 1000f + + " µm past target..."; + + // Replace drive buttons with stop + _driveGroup.SetActive(false); + _stopButton.SetActive(true); + + // Drive to past target depth + if (position.w < _pastTargetDepth) + CommunicationManager.Instance.DriveToDepth(new DriveToDepthRequest + { + ManipulatorId = _manipulatorId, + Depth = _pastTargetDepth, + Speed = _nearTargetDriveSpeed + }, _ => CompleteAndAdvance(), Debug.LogError); + else + // Already further than past target depth, so continue + CompleteAndAdvance(); + break; + case DriveState.ReturningToTarget: + // Update status text + _statusText.text = "Returning to target..."; + + // Replace drive buttons with stop + _driveGroup.SetActive(false); + _stopButton.SetActive(true); + + // Drive to target and complete movement + CommunicationManager.Instance.DriveToDepth( + new DriveToDepthRequest + { + ManipulatorId = _manipulatorId, + Depth = _targetDepth, + Speed = _nearTargetDriveSpeed + }, _ => + { + CommunicationManager.Instance.SetCanWrite(new CanWriteRequest + { + ManipulatorId = _manipulatorId, + CanWrite = false, + Hours = 0 + }, _ => { - CommunicationManager.Instance.SetCanWrite(_manipulatorId, false, 0, - _ => - { - _driveStateManager.CompleteMovement(); - - // Complete driving - _statusText.text = "Drive complete"; - _stopButton.SetActive(false); - - // Enable return to surface button - _driveGroup.SetActive(true); - _driveButton.interactable = false; - _exitButton.SetActive(true); - }); - }, Debug.LogError); - break; - case DriveState.Outside: - case DriveState.ExitingToOutside: - case DriveState.AtExitMargin: - case DriveState.ExitingToMargin: - case DriveState.AtDura: - case DriveState.ExitingToDura: - case DriveState.AtNearTarget: - case DriveState.ExitingToNearTarget: - case DriveState.AtPastTarget: - case DriveState.AtTarget: - default: - Debug.LogError("Invalid Drive state for driving: " + _driveStateManager.State); - return; - } - }, Debug.LogError); + _driveStateManager.CompleteMovement(); + + // Complete driving + _statusText.text = "Drive complete"; + _stopButton.SetActive(false); + + // Enable return to surface button + _driveGroup.SetActive(true); + _driveButton.interactable = false; + _exitButton.SetActive(true); + }); + }, Debug.LogError); + break; + case DriveState.Outside: + case DriveState.ExitingToOutside: + case DriveState.AtExitMargin: + case DriveState.ExitingToMargin: + case DriveState.AtDura: + case DriveState.ExitingToDura: + case DriveState.AtNearTarget: + case DriveState.ExitingToNearTarget: + case DriveState.AtPastTarget: + case DriveState.AtTarget: + default: + Debug.LogError("Invalid Drive state for driving: " + _driveStateManager.State); + return; + } + }, Debug.LogError); }, Debug.LogError); return; void CompleteAndAdvance() { - CommunicationManager.Instance.SetCanWrite(_manipulatorId, - false, 0, - _ => - { - _driveStateManager.CompleteMovement(); - Drive(); - }, Debug.LogError); + CommunicationManager.Instance.SetCanWrite(new CanWriteRequest + { + ManipulatorId = _manipulatorId, + CanWrite = false, + Hours = 0 + }, _ => + { + _driveStateManager.CompleteMovement(); + Drive(); + }, Debug.LogError); } } @@ -515,7 +538,12 @@ public void Exit() // Increment state _driveStateManager.ExitIncrement(); - CommunicationManager.Instance.SetCanWrite(_manipulatorId, true, 1, canWrite => + CommunicationManager.Instance.SetCanWrite(new CanWriteRequest + { + ManipulatorId = _manipulatorId, + CanWrite = true, + Hours = 1 + }, canWrite => { if (!canWrite) return; @@ -532,8 +560,12 @@ public void Exit() // Drive to near target depth if (_nearTargetDepth > _duraDepth && position.w > _nearTargetDepth) - CommunicationManager.Instance.DriveToDepth(_manipulatorId, _nearTargetDepth, - _nearTargetExitSpeed, _ => CompleteAndAdvance(), Debug.LogError); + CommunicationManager.Instance.DriveToDepth(new DriveToDepthRequest + { + ManipulatorId = _manipulatorId, + Depth = _nearTargetDepth, + Speed = _nearTargetExitSpeed + }, _ => CompleteAndAdvance(), Debug.LogError); else // Dura depth is within near target distance, so continue CompleteAndAdvance(); @@ -548,9 +580,12 @@ public void Exit() // Drive to dura depth (set speed based on dura depth and near target depth) if (position.w > _duraDepth) - CommunicationManager.Instance.DriveToDepth(_manipulatorId, _duraDepth, - position.w > _nearTargetDepth ? _nearTargetExitSpeed : _exitDriveSpeed, - _ => CompleteAndAdvance(), Debug.LogError); + CommunicationManager.Instance.DriveToDepth(new DriveToDepthRequest + { + ManipulatorId = _manipulatorId, + Depth = _duraDepth, + Speed = position.w > _nearTargetDepth ? _nearTargetExitSpeed : _exitDriveSpeed + }, _ => CompleteAndAdvance(), Debug.LogError); else // Already at dura depth, so continue CompleteAndAdvance(); @@ -565,9 +600,12 @@ public void Exit() // Drive to dura margin depth if (position.w > _exitMarginDepth) - CommunicationManager.Instance.DriveToDepth(_manipulatorId, _exitMarginDepth, - position.w > _nearTargetDepth ? _nearTargetExitSpeed : _exitDriveSpeed, - _ => CompleteAndAdvance(), Debug.LogError); + CommunicationManager.Instance.DriveToDepth(new DriveToDepthRequest + { + ManipulatorId = _manipulatorId, + Depth = _exitMarginDepth, + Speed = position.w > _nearTargetDepth ? _nearTargetExitSpeed : _exitDriveSpeed + }, _ => CompleteAndAdvance(), Debug.LogError); else // Already at dura margin depth, so continue CompleteAndAdvance(); @@ -585,12 +623,20 @@ public void Exit() // Drive to outside position if (position.y < _outsidePosition.y) - CommunicationManager.Instance.GotoPos(_manipulatorId, _outsidePosition, - _outsideDriveSpeed, _ => CompleteOutside(), Debug.LogError); + CommunicationManager.Instance.GotoPos(new GotoPositionRequest + { + ManipulatorId = _manipulatorId, + Position = _outsidePosition, + Speed = _outsideDriveSpeed + }, _ => CompleteOutside(), Debug.LogError); // Drive to outside depth if DV movement is unavailable else if (position.w > _outsideDepth) - CommunicationManager.Instance.DriveToDepth(_manipulatorId, _outsideDepth, - _outsideDriveSpeed, _ => CompleteOutside(), Debug.LogError); + CommunicationManager.Instance.DriveToDepth(new DriveToDepthRequest + { + ManipulatorId = _manipulatorId, + Depth = _outsideDepth, + Speed = _outsideDriveSpeed + }, _ => CompleteOutside(), Debug.LogError); else // Already outside, so complete CompleteOutside(); @@ -615,7 +661,12 @@ public void Exit() void CompleteAndAdvance() { - CommunicationManager.Instance.SetCanWrite(_manipulatorId, false, 0, _ => + CommunicationManager.Instance.SetCanWrite(new CanWriteRequest + { + ManipulatorId = _manipulatorId, + CanWrite = false, + Hours = 0 + }, _ => { _driveStateManager.CompleteMovement(); Exit(); @@ -624,7 +675,12 @@ void CompleteAndAdvance() void CompleteOutside() { - CommunicationManager.Instance.SetCanWrite(_manipulatorId, false, 0, _ => + CommunicationManager.Instance.SetCanWrite(new CanWriteRequest + { + ManipulatorId = _manipulatorId, + CanWrite = false, + Hours = 0 + }, _ => { _driveStateManager.CompleteMovement(); diff --git a/Assets/Scripts/Pinpoint/UI/EphysCopilot/InsertionSelectionPanelHandler.cs b/Assets/Scripts/Pinpoint/UI/EphysCopilot/InsertionSelectionPanelHandler.cs index 14631bdf..a3d2ebe7 100644 --- a/Assets/Scripts/Pinpoint/UI/EphysCopilot/InsertionSelectionPanelHandler.cs +++ b/Assets/Scripts/Pinpoint/UI/EphysCopilot/InsertionSelectionPanelHandler.cs @@ -390,51 +390,69 @@ private void MoveToTargetInsertion() .dv.APMLDV); // Move - CommunicationManager.Instance.SetCanWrite(ProbeManager.ManipulatorBehaviorController.ManipulatorID, true, 1, - canWrite => - { - if (canWrite) - CommunicationManager.Instance.GotoPos(ProbeManager.ManipulatorBehaviorController.ManipulatorID, - dvPosition, - ManipulatorBehaviorController.AUTOMATIC_MOVEMENT_SPEED, _ => + CommunicationManager.Instance.SetCanWrite(new CanWriteRequest + { + ManipulatorId = ProbeManager.ManipulatorBehaviorController.ManipulatorID, + CanWrite = true, + Hours = 1 + }, canWrite => + { + if (canWrite) + CommunicationManager.Instance.GotoPos(new GotoPositionRequest + { + ManipulatorId = ProbeManager.ManipulatorBehaviorController.ManipulatorID, + Position = dvPosition, + Speed = ManipulatorBehaviorController.AUTOMATIC_MOVEMENT_SPEED + }, _ => + { + CommunicationManager.Instance.GotoPos( + new GotoPositionRequest + { + ManipulatorId = ProbeManager.ManipulatorBehaviorController.ManipulatorID, + Position = apPosition, + Speed = ManipulatorBehaviorController.AUTOMATIC_MOVEMENT_SPEED + }, _ => { - CommunicationManager.Instance.GotoPos( - ProbeManager.ManipulatorBehaviorController.ManipulatorID, apPosition, - ManipulatorBehaviorController.AUTOMATIC_MOVEMENT_SPEED, _ => - { - CommunicationManager.Instance.GotoPos( - ProbeManager.ManipulatorBehaviorController.ManipulatorID, mlPosition, - ManipulatorBehaviorController.AUTOMATIC_MOVEMENT_SPEED, _ => - { - CommunicationManager.Instance.SetCanWrite( - ProbeManager.ManipulatorBehaviorController.ManipulatorID, false, - 1, _ => - { - // Hide lines - _lineGameObjects.ap.SetActive(false); - _lineGameObjects.ml.SetActive(false); - _lineGameObjects.dv.SetActive(false); - - // Complete movement - EndMovement(); - _moveButton.interactable = false; - }, Debug.LogError); - }, error => - { - Debug.LogError(error); - EndMovement(); - }); - }, error => - { - Debug.LogError(error); - EndMovement(); - }); + CommunicationManager.Instance.GotoPos(new GotoPositionRequest + { + ManipulatorId = ProbeManager.ManipulatorBehaviorController.ManipulatorID, + Position = mlPosition, + Speed = ManipulatorBehaviorController.AUTOMATIC_MOVEMENT_SPEED + }, _ => + { + CommunicationManager.Instance.SetCanWrite( + new CanWriteRequest + { + ManipulatorId = ProbeManager.ManipulatorBehaviorController.ManipulatorID, + CanWrite = false, + Hours = 1 + }, _ => + { + // Hide lines + _lineGameObjects.ap.SetActive(false); + _lineGameObjects.ml.SetActive(false); + _lineGameObjects.dv.SetActive(false); + + // Complete movement + EndMovement(); + _moveButton.interactable = false; + }, Debug.LogError); + }, error => + { + Debug.LogError(error); + EndMovement(); + }); }, error => { Debug.LogError(error); EndMovement(); }); - }, Debug.LogError); + }, error => + { + Debug.LogError(error); + EndMovement(); + }); + }, Debug.LogError); return; void EndMovement() diff --git a/Assets/Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs b/Assets/Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs index ad773098..31ac1bf8 100644 --- a/Assets/Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs +++ b/Assets/Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs @@ -106,13 +106,13 @@ private void UpdateManipulatorPanels() if (CommunicationManager.Instance.IsConnected) { - CommunicationManager.Instance.GetManipulators((availableIDs, numAxes, _) => + CommunicationManager.Instance.GetManipulators((response) => { // Keep track of handled manipulator panels var handledManipulatorIds = new HashSet(); // Add any new manipulators in scene to list - foreach (var manipulatorID in availableIDs) + foreach (var manipulatorID in response.Manipulators) { // Create new manipulator connection settings panel if the manipulator is new if (!_manipulatorIdToManipulatorConnectionSettingsPanel.ContainsKey(manipulatorID)) @@ -125,7 +125,7 @@ private void UpdateManipulatorPanels() .GetComponent(); // Set manipulator id - manipulatorConnectionSettingsPanel.Initialize(this, manipulatorID, numAxes); + manipulatorConnectionSettingsPanel.Initialize(this, manipulatorID, response.NumAxes); // Add to dictionary _manipulatorIdToManipulatorConnectionSettingsPanel.Add(manipulatorID, @@ -146,7 +146,7 @@ private void UpdateManipulatorPanels() } // Reorder panels to match order of availableIds - foreach (var manipulatorId in availableIDs) + foreach (var manipulatorId in response.Manipulators) _manipulatorIdToManipulatorConnectionSettingsPanel[manipulatorId].gameObject.transform .SetAsLastSibling(); }); diff --git a/Assets/Tests/CommunicationManagerTests.cs b/Assets/Tests/CommunicationManagerTests.cs deleted file mode 100644 index 51f34eb0..00000000 --- a/Assets/Tests/CommunicationManagerTests.cs +++ /dev/null @@ -1,219 +0,0 @@ -using System.Collections; -using NUnit.Framework; -using EphysLink; -using UnityEngine; -using UnityEngine.SceneManagement; -using UnityEngine.TestTools; - -namespace Tests -{ - public class CommunicationManagerTests - { - #region Variables - - private CommunicationManager _communicationManager; - private string[] _manipulators; - - private enum State - { - None, - Success, - Failed, - Failed2, - Failed3, - Failed4, - Failed5 - } - - #endregion - - - #region Setup and Teardown - - /// - /// Setup each test. - /// Ensures a connection to the server and gets the manipulators. - /// - /// - [UnitySetUp] - public IEnumerator Setup() - { - SceneManager.LoadScene("Scenes/TrajectoryPlanner"); - yield return null; - - // Connect to server - _communicationManager = GameObject.Find("EphysLink").GetComponent(); - yield return new WaitUntil(() => _communicationManager.IsConnected); - - // Get manipulators - var state = State.None; - - _communicationManager.GetManipulators( - (returnedManipulators, _, _) => - { - _manipulators = returnedManipulators; - state = State.Success; - }, - returnedError => state = State.Failed); - - yield return new WaitWhile(() => state == State.None); - - if (state == State.Success) yield break; - TearDown(); - Assert.Fail("Could not get manipulators"); - } - - /// - /// Disconnect from server after each test - /// - [TearDown] - public void TearDown() - { - _communicationManager.DisconnectFromServer(); - } - - #endregion - - #region Tests - - /// - /// Register and then unregister each manipulator - /// - /// - [UnityTest] - public IEnumerator TestRegisterAndUnregister() - { - foreach (var id in _manipulators) - { - var state = State.None; - - _communicationManager.RegisterManipulator(id, - () => _communicationManager.UnregisterManipulator(id, () => state = State.Success, - _ => state = State.Failed2), - _ => state = State.Failed); - - yield return new WaitWhile(() => state == State.None); - Assert.That(state, Is.EqualTo(State.Success)); - } - } - - /// - /// Register -> Bypass calibration -> Get position - /// - /// - [UnityTest] - public IEnumerator TestGetPos() - { - foreach (var id in _manipulators) - { - var state = State.None; - - _communicationManager.RegisterManipulator(id, () => _communicationManager.BypassCalibration(id, () => - _communicationManager.GetPos(id, - _ => state = State.Success, - _ => state = State.Failed3), _ => state = State.Failed2), - _ => state = State.Failed); - - - yield return new WaitWhile(() => state == State.None); - Assert.That(state, Is.EqualTo(State.Success)); - } - } - - /// - /// Register -> Set Can Write -> Calibrate -> Goto position -> Return to home position - /// - /// - [UnityTest] - public IEnumerator TestCalibrateAndMovement() - { - foreach (var id in _manipulators) - { - var state = State.None; - - _communicationManager.RegisterManipulator(id, () => _communicationManager.SetCanWrite(id, true, 1, _ => - _communicationManager.Calibrate(id, () => - _communicationManager.GotoPos((string)id, new Vector4(0, 0, 0, 0), 5000, - _ => _communicationManager.GotoPos((string)id, new Vector4(10000, 10000, 10000, 10000), 5000, - _ => state = State.Success, _ => state = State.Failed5), - _ => state = State.Failed4), _ => state = State.Failed3), - _ => state = State.Failed2), _ => state = State.Failed); - - yield return new WaitWhile(() => state == State.None); - Assert.That(state, Is.EqualTo(State.Success)); - } - } - - /// - /// Register -> Set Can Write -> Bypass Calibration -> Drive to depth -> Return to home position - /// - /// - [UnityTest] - public IEnumerator TestDriveToDepth() - { - foreach (var id in _manipulators) - { - var state = State.None; - - _communicationManager.RegisterManipulator(id, - () => _communicationManager.SetCanWrite(id, true, 1, - _ => _communicationManager.BypassCalibration(id, - () => _communicationManager.DriveToDepth(id, 0, 5000, - _ => _communicationManager.DriveToDepth(id, 10000, 5000, _ => state = State.Success, - _ => state = State.Failed5), _ => state = State.Failed4), - _ => state = State.Failed3), _ => state = State.Failed2), - _ => state = State.Failed); - - yield return new WaitWhile(() => state == State.None); - Assert.That(state, Is.EqualTo(State.Success)); - } - } - - /// - /// Register -> Bypass Calibration -> Set inside brain state - /// - /// - [UnityTest] - public IEnumerator TestSetInsideBrain() - { - foreach (var id in _manipulators) - { - var state = State.None; - - _communicationManager.RegisterManipulator(id, - () => _communicationManager.BypassCalibration(id, () => _communicationManager.SetInsideBrain(id, - true, _ => state = State.Success, - _ => state = State.Failed3), _ => state = State.Failed2), _ => state = State.Failed); - - yield return new WaitWhile(() => state == State.None); - Assert.That(state, Is.EqualTo(State.Success)); - } - } - - /// - /// Register -> Set Can Write -> Bypass Calibration -> Goto position -> Stop - /// - /// - [UnityTest] - public IEnumerator TestStop() - { - foreach (var id in _manipulators) - { - var state = State.None; - - _communicationManager.RegisterManipulator(id, () => _communicationManager.SetCanWrite(id, true, 1, _ => - _communicationManager.BypassCalibration(id, () => - { - _communicationManager.GotoPos((string)id, Vector4.zero, 5000, _ => state = State.Failed4, - _ => state = State.Failed4); - _communicationManager.Stop(_ => state = State.Success); - }, _ => state = State.Failed3), _ => state = State.Failed2), _ => state = State.Failed); - - yield return new WaitWhile(() => state == State.None); - Assert.That(state, Is.EqualTo(State.Success)); - } - } - - #endregion - } -} \ No newline at end of file diff --git a/Packages/manifest.json b/Packages/manifest.json index b39703c8..d9a91b8b 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -3,7 +3,7 @@ "com.unity.addressables": "1.21.19", "com.unity.ai.navigation": "1.1.5", "com.unity.animation.rigging": "1.2.1", - "com.unity.ide.rider": "3.0.27", + "com.unity.ide.rider": "3.0.28", "com.unity.ide.visualstudio": "2.0.22", "com.unity.ide.vscode": "1.2.5", "com.unity.inputsystem": "1.7.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index e7fee04d..3b1e254f 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -58,7 +58,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.rider": { - "version": "3.0.27", + "version": "3.0.28", "depth": 0, "source": "registry", "dependencies": { diff --git a/Pinpoint.sln.DotSettings b/Pinpoint.sln.DotSettings index 4b4b12fb..94874ce6 100644 --- a/Pinpoint.sln.DotSettings +++ b/Pinpoint.sln.DotSettings @@ -74,4 +74,5 @@ True True True + True \ No newline at end of file