Robust context screenshot handling

parent e891326b
......@@ -152,7 +152,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5fc6ba51380c1458f9ecd3a8b7030dd5, type: 3}
m_Name:
m_EditorClassIdentifier:
contextScene: KitchenNao
contextScene: Kitchen
captureVideo: 0
timeoutAfterSeconds: 40
--- !u!4 &1309245142
......@@ -190,7 +190,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1309245140}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0bf19aac958d45fba9fe660e211e56a, type: 3}
m_Name:
......
......@@ -10740,7 +10740,7 @@ MeshCollider:
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 3
serializedVersion: 4
m_Convex: 1
m_CookingOptions: 30
m_Mesh: {fileID: 2199168969773900211, guid: 777930a286a884240885b925f58479dc, type: 3}
......
......@@ -26,6 +26,20 @@ public class SceneControllerEditor : Editor
EditorGUILayout.Space();
ShowSemanticLabels(sc);
EditorGUILayout.Space();
DeleteOldScreenshots(sc);
}
private void DeleteOldScreenshots(SceneController sc)
{
if (GUILayout.Button("Cleanup context screenshots"))
{
foreach (FileInfo fi in new DirectoryInfo(Application.persistentDataPath).GetFiles("context*.png"))
{
fi.Delete();
}
}
}
private void ShowSemanticLabels(SceneController sc)
......
......@@ -2,6 +2,7 @@ using System.IO;
using System.Collections.Generic;
using SimpleJSON;
using UnityEngine;
using System;
namespace dlu
{
......@@ -77,7 +78,8 @@ public class JSONHandler
public JSONNode GenerateContextJSON()
{
string screenShotPath = $"{Application.persistentDataPath}/context.png";
string now = DateTime.Now.ToString("yyyy-MM-ddTHH-mm-ss");
string screenShotPath = $"{Application.persistentDataPath}/context_{now}.png";
ScreenCapture.CaptureScreenshot(screenShotPath, 3);
Dictionary<string, JSONObject> sceneDict = new Dictionary<string, JSONObject>();
......
......@@ -81,10 +81,18 @@ public class SceneController : MonoBehaviour
}
else
{
StartCoroutine(replyToRequest(JSONHandler.instance.GenerateContextJSON().ToString()));
StartCoroutine(ReplyContext(replyToRequest));
}
}
private IEnumerator ReplyContext(Func<string, IEnumerator> replyToRequest)
{
string response = JSONHandler.instance.GenerateContextJSON().ToString();
// Should better wait until context screenshot is available, but this works good enough
yield return new WaitForSeconds(3);
yield return replyToRequest(response);
}
public IEnumerator EvaluateInstruction()
{
Dictionary<string, JSONObject> taskDict = new Dictionary<string, JSONObject>();
......
......@@ -41,13 +41,13 @@ public class ZMQServer : MonoBehaviour
void Update()
{
if (server == null)
{
Debug.LogWarning("Restarting server...");
StartServer();
}
if (!workingOnRequest)
{
if (server == null)
{
Debug.LogWarning("Restarting server...");
StartServer();
}
server.Poll(TimeSpan.FromMilliseconds(100));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment