void Update() { if ((sendReceiveROSMessages) && (internalGameState == Constants.START_GAME)) { this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishGameStateMsg( Constants.STATE_ROSTOPIC, Constants.GAME_STATE_START, new Dictionary <string, float>())); } if ((sendReceiveROSMessages) && (internalGameState == Constants.TUTORIAL)) { this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishGameStateMsg(Constants.STATE_ROSTOPIC, Constants.TUTORIAL, new Dictionary <string, float>())); internalGameState = Constants.STARTED_GAME; } if (internalGameState == Constants.START_GAME) { // set the explainerMode to building explainerMode = Constants.EXPLAINER_BUILDING; if (firstRound) { // robot utterance that introduces the game SendRobotUtterance("game-start", true, -1, -1, -1); // no longer the first round (after this round) firstRound = false; } if (tutorial) { saveLevel = levelNumber; levelNumber = 1; if (scene == Constants.CHILD_GUESSING_SCENE) { SendRobotUtterance("child-guesser-start", true, -1, -1, -1); SceneManager.LoadScene("Child_guessing_L1"); } else if (scene == Constants.ROBOT_GUESSING_SCENE) { SendRobotUtterance("child-builder-start", true, -1, -1, -1); SceneManager.LoadScene("Builder_Tutorial"); } } else { //Logger.Log("here"); SceneManager.LoadScene("StartMenu"); } internalGameState = Constants.STARTED_GAME; } if (internalGameState == Constants.END_GAME) { // send goobye message SendRobotUtterance("end-game", true, -1, -1, -1); SendPerformanceMetrics(); Application.Quit(); } }
private void SendPerformanceMetrics() { //performanceMetricsChildGuesser = 1; //performanceMetricsRobotGuesser = 1; if (sendReceiveROSMessages) { Dictionary <string, float> performanceMetrics = new Dictionary <string, float>(); performanceMetrics.Add("child-guesser-percentage-correct", performanceMetricsChildGuesser); performanceMetrics.Add("child-builder-percentage-correct", performanceMetricsRobotGuesser); this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishGameStateMsg(Constants.STATE_ROSTOPIC, Constants.GAME_STATE_END, performanceMetrics)); } /*Dictionary<string, float> averagePerformanceMetrics = new Dictionary<string, float> (); * * foreach (KeyValuePair<int, List<float>> performanceMetricEntry in performanceMetrics) { * if (performanceMetricEntry.Value.Count > 0) { * * // get the average value * float averageMetricValue = 0f; * foreach (float value in performanceMetricEntry.Value) { * averageMetricValue += value; * } * averageMetricValue = averageMetricValue / (float)performanceMetricEntry.Value.Count; * * // get the name of the metric in there * if (performanceMetricEntry.Key == Constants.CHILD_BUILDER_CHOICE_ACCURACY) { * averagePerformanceMetrics.Add ("child-builder-piece-choice-accuracy", averageMetricValue); * } else if (performanceMetricEntry.Key == Constants.CHILD_BUILDER_LOCATION_ACCURACY) { * averagePerformanceMetrics.Add ("child-builder-location-accuracy", averageMetricValue); * } else if (performanceMetricEntry.Key == Constants.CHILD_EXPLAINER_CHOICE_ACCURACY) { * averagePerformanceMetrics.Add ("child-explainer-piece-choice-accuracy", averageMetricValue); * } else if (performanceMetricEntry.Key == Constants.CHILD_EXPLAINER_LOCATION_ACCURACY) { * averagePerformanceMetrics.Add ("child-explainer-location-accuracy", averageMetricValue); * } else { * Debug.Log ("Error: performance metric type not recognized in the sender"); * return; * } * } * } * * if (sendReceiveROSMessages) { * this.clientSocket.SendMessage (RosbridgeUtilities.GetROSJsonPublishGameStateMsg ( * Constants.STATE_ROSTOPIC, * Constants.GAME_STATE_END, * averagePerformanceMetrics)); * }*/ }
void Start() { // set up rosbridge websocket client // note: does not attempt to reconnect if connection fails! if (this.clientSocket == null && sendReceiveROSMessages) { // load file if (this.gameConfig.server.Equals("") || this.gameConfig.port.Equals("")) { Logger.LogWarning("Do not have opal configuration... trying hardcoded IP 192.168.1.254 and port 9090"); this.clientSocket = new RosbridgeWebSocketClient( "192.168.1.254", // server, // can pass hostname or IP address "9090"); //port); } else { this.clientSocket = new RosbridgeWebSocketClient( this.gameConfig.server, // can pass hostname or IP address this.gameConfig.port); } if (this.clientSocket.SetupSocket()) { this.clientSocket.receivedMsgEvent += new ReceivedMessageEventHandler(HandleClientSocketReceivedMsgEvent); // advertise that we will publish log messages this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg( Constants.LOG_ROSTOPIC, Constants.LOG_ROSMSG_TYPE)); // advertise that we'll publish game state messages this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg( Constants.STATE_ROSTOPIC, Constants.STATE_ROSMSG_TYPE)); // advertise that we'll publish robot command messages this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg( Constants.ROBOT_CMD_ROSTOPIC, Constants.ROBOT_CMD_ROSMSG_TYPE)); // subscribe to opal command messages this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonSubscribeMsg( Constants.CMD_ROSTOPIC, Constants.CMD_ROSMSG_TYPE)); } else { Logger.LogError("Could not set up websocket!"); } } // Send ROS message to show that game is ready if (sendReceiveROSMessages) { this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishGameStateMsg( Constants.STATE_ROSTOPIC, Constants.GAME_STATE_READY, new Dictionary <string, float>())); } // if we're not sending/receiving ROS messages, then we'll start the game right away else if (!sendReceiveROSMessages) { internalGameState = Constants.START_GAME; } saveLevel = levelNumber; }