// ====================================
    // All button handlers.
    // ====================================

    private void onRosConnectButtonClick()
    {
        Logger.Log("Ros Connect Button clicked");
        string rosbridgeIp = Constants.DEFAULT_ROSBRIDGE_IP;

        // If user entered a different IP, use it, otherwise stick to default.
        if (this.rosInputText.text != "")
        {
            rosbridgeIp = this.rosInputText.text;
            Logger.Log("Trying to connect to roscore at " + rosbridgeIp);
        }
        if (this.rosManager == null || !this.rosManager.isConnected())
        {
            this.rosManager = new RosManager(rosbridgeIp, Constants.DEFAULT_ROSBRIDGE_PORT, this);
            this.storyManager.SetRosManager(this.rosManager);
            if (this.rosManager.Connect())
            {
                // If connection successful, update status text.
                this.rosStatusText.text  = "Connected!";
                this.rosStatusText.color = Color.green;
                this.hideElement(this.rosConnectButton.gameObject);
                this.showElement(this.enterLibraryButton.gameObject);
                // Set up the command handlers, happens the first time connection is established.
                this.registerRosMessageHandlers();
                Thread.Sleep(1000); // Wait for a bit to make sure connection is established.
                this.rosManager.SendHelloWorldAction().Invoke();
                Logger.Log("Sent hello ping message");
            }
            else
            {
                this.rosStatusText.text  = "Failed to connect, try again.";
                this.rosStatusText.color = Color.red;
            }
        }
        else
        {
            Logger.Log("Already connected to ROS, not trying to connect again");
        }
    }
 public void SetRosManager(RosManager ros)
 {
     this.rosManager = ros;
 }
Exemplo n.º 3
0
 public void SetRosManager(RosManager ros)
 {
     this.rosManager = ros;
     this.stanzaManager.SetRosManager(this.rosManager);
 }