Example #1
0
 public void sendPerformanceMetrics()
 {
     if (sendReceiveROSMessages)
     {
         performanceMetricsOrderErrors = 1 - performanceMetricsOrderErrors;
         performanceMetricsTrainErrors = 1 - performanceMetricsTrainErrors;
         Dictionary <string, float> PerformanceMetrics = new Dictionary <string, float>();
         PerformanceMetrics.Add("train-piece-errors", performanceMetricsTrainErrors);
         PerformanceMetrics.Add("train-order-errors", performanceMetricsOrderErrors);
         clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishGameStateMsg(Constants.STATE_ROSTOPIC, Constants.GAME_STATE_END, PerformanceMetrics));
     }
 }
Example #2
0
        void Update()
        {
            if (internalGameState == Constants.END_GAME)
            {
                SendRobotUtterance("end-game", false, -1, -1, -1, -1);
                sendPerformanceMetrics();
                Logger.Log("GoingToQuit");
                Application.Quit();
            }

            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, -1);

                    // no longer the first round (after this round)
                    firstRound = false;
                }
                //SceneManager.LoadScene("Builder_L1");
                SceneManager.LoadScene("Start_menu");


                internalGameState = Constants.STARTED_GAME;
            }
        }
Example #3
0
        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;
        }