Example #1
0
    // Update is called once per frame in Unity
    void Update()
    {
        if (!started && Input.GetButtonDown("Start"))
        {
            ConnectionStatus.text = "Connected";
            started = true;
            ros     = new ROSBridgeWebSocketConnection("ws://localhost", 8080);

            ros.AddPublisher(typeof(CommandPublisher));
            ros.AddPublisher(typeof(VelocityPublisher));

            // Fire up the subscriber(s) and publisher(s)
            ros.Connect();
        }

        ControlCommand command_msg = GetControlCommand();

        Debug.Log("Sending: " + command_msg.ToYAMLString());
        ControlVelocity velocity_msg = new ControlVelocity(GetPitch(), GetRoll(), GetThrottle(), GetYaw());

        Debug.Log("Sending: " + velocity_msg.ToYAMLString());

        // Publish it (ros is the object defined in the first class)
        ros.Publish(CommandPublisher.GetMessageTopic(), command_msg);
        ros.Publish(VelocityPublisher.GetMessageTopic(), velocity_msg);

        ros.Render();
    }