// Initialization void Start() { //SIGVerseLogger.Info ("*********************************************** STARTING PLACING DATA COLLECTION **********************************************"); Texture texture = this.CreateTextureFromImageFile(teamLogoPath); if (texture != null) { this.teamLogoRenderer.material.mainTexture = texture; } else { this.teamLogoRenderer.gameObject.SetActive(false); } this.step = PlacingStep.Initialize; this.isAllTaskFinished = false; this.fakeCount = 0; this.scorePlacing = ""; if (sceneNumber >= totScenes) { this.step = PlacingStep.Final; } Vector3 size = test.GetComponent <Renderer> ().bounds.size; SIGVerseLogger.Info("Objeto " + test.name + "Size x = " + size.x + " y =" + size.y + " z = " + size.z); }
//To receive message from ros public void OnReceiveRosMessage(RosBridge.handyman.HandymanMsg handymanMsg) { //SIGVerseLogger.Info ("MESSAGE RECEIVED" + handymanMsg.message); if (handymanMsg.message == MsgIamReady) { this.step = PlacingStep.SetUpScene; } if (handymanMsg.message == MsgImagesCaptured) { tool.setTargetObject(); this.step = PlacingStep.ExcecutePlacing; } if (handymanMsg.message == MsgObjectPlaced) { this.step = PlacingStep.CalculateScore; } if (handymanMsg.message == MsgScoreSaved) { tool.disapearTarget(); this.step = PlacingStep.WaitForIamReady; } //Debug.Log ("Change " + this.step); }
// Update is called once per frame void Update() { try { if (this.isAllTaskFinished) { return; } switch (this.step) { case PlacingStep.Initialize: //Configure everything just the first time if (tool.IsConnectedToRos()) { this.step++; } break; case PlacingStep.WaitForIamReady: //Send Are you ready? message and wait for answer this.SendRosMessage(MsgAreYouReady, string.Empty); break; case PlacingStep.SetUpScene: //Cycle goes back here to start new scene this.scorePlacing = ""; if (this.fakeCount < numOfScenes) { //Scene configuration and showing this.setUpScene(); this.fakeCount++; this.step++; sceneNumber++; this.scoreValText.text = "XXX"; this.sceneValText.text = sceneNumber.ToString(); this.strategy = UnityEngine.Random.Range(1, numStrategies + 1); } else { //When finishing the number of scenes configured goes to last step this.step = PlacingStep.Stoping; } break; case PlacingStep.WaitForImagesCaptured: string cameraHeigth; if (PlacingTools.typeLower) { cameraHeigth = "L-"; } else { cameraHeigth = "U-"; } //Send Setting completed message and wait for Images captured message from robot //Sending camera height for metadata file cameraHeigth += tool.getFurnitureID(); //Sending strategy number from 1 to max strategies number cameraHeigth += "-" + this.strategy; this.SendRosMessage(MsgSettingCompleted, cameraHeigth); break; //While robot is placing object on table, unity starts scoring manager for scene case PlacingStep.ExcecutePlacing: tool.startPlacing(); break; //When receiving Object Placed message calculates score case PlacingStep.CalculateScore: this.scorePlacing = tool.finishPlacing(); this.step++; break; //Send score and wait for Score Saved message, finally goes back to WaitForIamReady case PlacingStep.WaitForNextTask: string sc = this.scorePlacing; this.scoreValText.text = this.scorePlacing.Split(':')[0]; sc += "-" + tool.getTargetID(); this.SendRosMessage(MsgScore, sc); tool.resetRobot(); break; //When finished all scenes send Stop Process message case PlacingStep.Stoping: this.scenes.moveHouse(); this.scoreValText.text = "XXX"; this.SendRosMessage(MsgStopProcess, string.Empty); this.isAllTaskFinished = true; Start(); break; case PlacingStep.Final: this.sceneValText.text = "FINISHED"; this.SendRosMessage(MsgStopProcess, string.Empty); this.isAllTaskFinished = true; break; } } catch (Exception exception) { SIGVerseLogger.Error(exception.Message); SIGVerseLogger.Error(exception.StackTrace); this.ApplicationQuitAfter1sec(); } }