Skip to content

Commit

Permalink
Merge pull request #212 from robofit/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
Kapim authored Mar 24, 2021
2 parents b999d66 + af1a911 commit 92a24a7
Show file tree
Hide file tree
Showing 13 changed files with 1,622 additions and 5,627 deletions.
753 changes: 289 additions & 464 deletions arcor2_AREditor/Assets/BASE/Prefabs/Dialogs/NewProject.prefab

Large diffs are not rendered by default.

Large diffs are not rendered by default.

109 changes: 45 additions & 64 deletions arcor2_AREditor/Assets/BASE/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using UnityEngine.XR.ARFoundation;
using UnityEngine.Events;
using System.Collections;
using Newtonsoft.Json;

namespace Base {
/// <summary>
Expand Down Expand Up @@ -849,9 +850,9 @@ private async void OnConnectionStatusChanged(ConnectionStatusEnum newState) {
return;
}

await LoadScenes();
await LoadProjects();
await LoadPackages();
WebsocketManager.Instance.LoadScenes(LoadScenesCb);
WebsocketManager.Instance.LoadProjects(LoadProjectsCb);
WebsocketManager.Instance.LoadPackages(LoadPackagesCb);

connectionStatus = newState;
break;
Expand Down Expand Up @@ -1189,66 +1190,46 @@ public string GetSceneId(string name) {
throw new RequestFailedException("No scene with name: " + name);
}

/// <summary>
/// Loads list of scenes from server
/// </summary>
/// <returns></returns>
public async Task LoadScenes() {
try {
Scenes = await WebsocketManager.Instance.LoadScenes();
Scenes.Sort(delegate (ListScenesResponseData x, ListScenesResponseData y) {
return y.Modified.CompareTo(x.Modified);
});
OnSceneListChanged?.Invoke(this, EventArgs.Empty);
} catch (RequestFailedException ex) {
Debug.LogError(ex);
Notifications.Instance.SaveLogs("Failed to update action objects");
GameManager.Instance.DisconnectFromSever();
}
}

/// <summary>
/// Loads list of projects from server
/// </summary>
/// <returns></returns>
public async Task LoadProjects() {
try {
Projects = await WebsocketManager.Instance.LoadProjects();
Projects.Sort(delegate (ListProjectsResponseData x, ListProjectsResponseData y) {
return y.Modified.CompareTo(x.Modified);
});
OnProjectsListChanged?.Invoke(this, EventArgs.Empty);
} catch (RequestFailedException ex) {
Debug.LogError(ex);
Notifications.Instance.SaveLogs("Failed to update action objects");
GameManager.Instance.DisconnectFromSever();
}
public void LoadScenesCb(string id, string responseData) {
IO.Swagger.Model.ListScenesResponse response = JsonConvert.DeserializeObject<IO.Swagger.Model.ListScenesResponse>(responseData);
if (response == null)
Notifications.Instance.ShowNotification("Failed to load scenes", "Please, try again later.");
Scenes = response.Data;
Scenes.Sort(delegate (ListScenesResponseData x, ListScenesResponseData y) {
return y.Modified.CompareTo(x.Modified);
});
OnSceneListChanged?.Invoke(this, EventArgs.Empty);
}

public void LoadProjectsCb(string id, string responseData) {
IO.Swagger.Model.ListProjectsResponse response = JsonConvert.DeserializeObject<IO.Swagger.Model.ListProjectsResponse>(responseData);
if (response == null)
Notifications.Instance.ShowNotification("Failed to load projects", "Please, try again later.");
Projects = response.Data;
Projects.Sort(delegate (ListProjectsResponseData x, ListProjectsResponseData y) {
return y.Modified.CompareTo(x.Modified);
});
OnProjectsListChanged?.Invoke(this, EventArgs.Empty);
}


public void LoadPackagesCb(string id, string responseData) {
IO.Swagger.Model.ListPackagesResponse response = JsonConvert.DeserializeObject<IO.Swagger.Model.ListPackagesResponse>(responseData);
if (response == null)
Notifications.Instance.ShowNotification("Failed to load packages", "Please, try again later.");
Packages = response.Data;
Packages.Sort(delegate (PackageSummary x, PackageSummary y) {
return y.PackageMeta.Built.CompareTo(x.PackageMeta.Built);
});
OnPackagesListChanged?.Invoke(this, EventArgs.Empty);
}

/// <summary>
/// Loads list of packages from server
/// </summary>
/// <returns></returns>
public async Task LoadPackages() {
try {
Packages = await WebsocketManager.Instance.LoadPackages();
Packages.Sort(delegate(PackageSummary x, PackageSummary y) {
return y.PackageMeta.Built.CompareTo(x.PackageMeta.Built);
});
OnPackagesListChanged?.Invoke(this, EventArgs.Empty);
} catch (RequestFailedException ex) {
Debug.LogError(ex);
Notifications.Instance.SaveLogs("Failed to update action objects");
DisconnectFromSever();
}
}

/// <summary>
/// Gets package by ID
/// </summary>
/// <param name="id">Id of package</param>
/// <returns>Package with corresponding ID</returns>
public PackageSummary GetPackage(string id) {
/// <summary>
/// Gets package by ID
/// </summary>
/// <param name="id">Id of package</param>
/// <returns>Package with corresponding ID</returns>
public PackageSummary GetPackage(string id) {
foreach (PackageSummary package in Packages) {
if (id == package.Id)
return package;
Expand Down Expand Up @@ -1631,9 +1612,9 @@ public async Task OpenMainScreen(ShowMainScreenData.WhatEnum what, string highli
Scene.SetActive(false);
MenuManager.Instance.MainMenu.Close();
if (updateResources) {
await LoadScenes();
await LoadProjects();
await LoadPackages();
WebsocketManager.Instance.LoadScenes(LoadScenesCb);
WebsocketManager.Instance.LoadProjects(LoadProjectsCb);
WebsocketManager.Instance.LoadPackages(LoadPackagesCb);
}
switch (what) {
case ShowMainScreenData.WhatEnum.PackagesList:
Expand Down
2 changes: 1 addition & 1 deletion arcor2_AREditor/Assets/BASE/Scripts/LabeledInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void SetLabel(string label, string description) {
}

public void SetType(string contentType) {
switch (ParameterType) {
switch (contentType) {
case "integer":
Input.contentType = TMPro.TMP_InputField.ContentType.IntegerNumber;
break;
Expand Down
3 changes: 3 additions & 0 deletions arcor2_AREditor/Assets/BASE/Scripts/SceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ public async Task<bool> CreateScene(IO.Swagger.Model.Scene scene, bool loadResou
} catch (RequestFailedException) {
WebsocketManager.Instance.InvokeSceneStateEvent(new SceneStateData(message: "", state: SceneStateData.StateEnum.Stopped));
}

(bool successClose, _) = await GameManager.Instance.CloseScene(false, true);
SceneChanged = !successClose;
OnLoadScene?.Invoke(this, EventArgs.Empty);
Valid = true;
return true;
Expand Down
17 changes: 13 additions & 4 deletions arcor2_AREditor/Assets/BASE/Scripts/URDF/RobotActionObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public bool updatePose {
private Shader transparentShader;

private bool jointStateSubscribeIsValid = true;

private bool modelLoading = false;

protected override void Start() {
base.Start();
if (SceneManager.Instance.RobotsEEVisible && SceneManager.Instance.SceneStarted) {
if (GameManager.Instance.GetGameState() != GameManager.GameStateEnum.PackageRunning && SceneManager.Instance.RobotsEEVisible && SceneManager.Instance.SceneStarted) {
_ = EnableVisualisationOfEE();
}
}
Expand Down Expand Up @@ -168,6 +168,7 @@ public async override void InitActionObject(string id, string type, Vector3 posi
} else {
// Robot is not loaded yet, let's wait for it to be loaded
UrdfManager.Instance.OnRobotUrdfModelLoaded += OnRobotModelLoaded;
modelLoading = true;
}
}

Expand All @@ -186,6 +187,7 @@ private void OnRobotModelLoaded(object sender, RobotUrdfModelArgs args) {

// if robot is loaded, unsubscribe from UrdfManager event
UrdfManager.Instance.OnRobotUrdfModelLoaded -= OnRobotModelLoaded;
modelLoading = false;
}
}

Expand Down Expand Up @@ -557,8 +559,14 @@ public void SetJointValue(string name, float angle, bool angle_in_degrees = fals
}

public List<IO.Swagger.Model.Joint> GetJoints() {
if (RobotModel == null)
throw new RequestFailedException("Model not found for this robot.");
if (RobotModel == null) {
// if urdf model is still loading, return empty joint list
if (modelLoading) {
return new List<IO.Swagger.Model.Joint>();
} else {
throw new RequestFailedException("Model not found for this robot.");
}
}
else
return RobotModel.GetJoints();
}
Expand All @@ -567,6 +575,7 @@ public override void DeleteActionObject() {
base.DeleteActionObject();
UnloadRobotModel();
UrdfManager.Instance.OnRobotUrdfModelLoaded -= OnRobotModelLoaded;
modelLoading = false;
}

private void UnloadRobotModel() {
Expand Down
35 changes: 15 additions & 20 deletions arcor2_AREditor/Assets/BASE/Scripts/WebsocketManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ private void HandleChangedObjectTypesEvent(string data) {
IO.Swagger.Model.ChangedObjectTypes objectTypesChangedEvent = JsonConvert.DeserializeObject<IO.Swagger.Model.ChangedObjectTypes>(data);
switch (objectTypesChangedEvent.ChangeType) {
case IO.Swagger.Model.ChangedObjectTypes.ChangeTypeEnum.Add:
ActionsManager.Instance.ActionsReady = false;
OnObjectTypeAdded?.Invoke(this, new ObjectTypesEventArgs(objectTypesChangedEvent.Data));

break;
Expand All @@ -725,6 +726,7 @@ private void HandleChangedObjectTypesEvent(string data) {
break;

case ChangedObjectTypes.ChangeTypeEnum.Update:
ActionsManager.Instance.ActionsReady = false;
OnObjectTypeUpdated?.Invoke(this, new ObjectTypesEventArgs(objectTypesChangedEvent.Data));
break;
default:
Expand Down Expand Up @@ -1224,44 +1226,37 @@ public async Task FocusObjectDone(string objectId) {
/// Throws RequestFailedException when request failed
/// </summary>
/// <returns>List of scenes metadata</returns>
public async Task<List<IO.Swagger.Model.ListScenesResponseData>> LoadScenes() {
int id = Interlocked.Increment(ref requestID);
IO.Swagger.Model.ListScenesRequest request = new IO.Swagger.Model.ListScenesRequest(id: id, request: "ListScenes");
SendDataToServer(request.ToJson(), id, true);
IO.Swagger.Model.ListScenesResponse response = await WaitForResult<IO.Swagger.Model.ListScenesResponse>(id);
if (response == null)
throw new RequestFailedException("Failed to load scenes");
return response.Data;
public void LoadScenes(UnityAction<string, string> callback) {
int r_id = Interlocked.Increment(ref requestID);
responsesCallback.Add(r_id, Tuple.Create("", callback));
IO.Swagger.Model.ListScenesRequest request = new IO.Swagger.Model.ListScenesRequest(id: r_id, request: "ListScenes");
SendDataToServer(request.ToJson(), r_id, false);
}

/// <summary>
/// Loads all projects from server.
/// Throws RequestFailedException when request failed
/// </summary>
/// <returns>List of projects metadata</returns>
public async Task<List<IO.Swagger.Model.ListProjectsResponseData>> LoadProjects() {
public void LoadProjects(UnityAction<string, string> callback) {
int r_id = Interlocked.Increment(ref requestID);
responsesCallback.Add(r_id, Tuple.Create("", callback));
IO.Swagger.Model.ListProjectsRequest request = new IO.Swagger.Model.ListProjectsRequest(id: r_id, request: "ListProjects");
SendDataToServer(request.ToJson(), r_id, true);
IO.Swagger.Model.ListProjectsResponse response = await WaitForResult<IO.Swagger.Model.ListProjectsResponse>(r_id);
if (response == null)
throw new RequestFailedException("Failed to load projects");
return response.Data;
SendDataToServer(request.ToJson(), r_id, false);

}

/// <summary>
/// Loads all packages from server.
/// Throws RequestFailedException when request failed
/// </summary>
/// <returns>List of packages metadata</returns>
public async Task<List<IO.Swagger.Model.PackageSummary>> LoadPackages() {
public void LoadPackages(UnityAction<string, string> callback) {
int r_id = Interlocked.Increment(ref requestID);
responsesCallback.Add(r_id, Tuple.Create("", callback));
IO.Swagger.Model.ListPackagesRequest request = new IO.Swagger.Model.ListPackagesRequest(id: r_id, request: "ListPackages");
SendDataToServer(request.ToJson(), r_id, true);
IO.Swagger.Model.ListPackagesResponse response = await WaitForResult<IO.Swagger.Model.ListPackagesResponse>(r_id);
if (response == null)
throw new RequestFailedException("Failed to load packages");
return response.Data;
SendDataToServer(request.ToJson(), r_id, false);

}

/// <summary>
Expand Down
Loading

0 comments on commit 92a24a7

Please sign in to comment.