private void Advertise()
    {
        var adMsg = new AdvertiseMessage();

        adMsg.id    = id;
        adMsg.topic = "/mobile_base/commands/velocity";
        adMsg.type  = "geometry_msgs/Twist";
        string adJson = JsonUtility.ToJson(adMsg);

        Debug.Log(adJson);
        ws.Send(adJson);
    }
예제 #2
0
    // Use this for initialization
    void Start()
    {
        advertise_message    = new AdvertiseMessage();
        advertise_message.op = "advertise";
        //advertise_message.id = "s1h2ie3l5d";
        advertise_message.topic = "/ShieldVRComm";
        advertise_message.type  = "std_msgs/String";

        shieldvr_subscribe       = new ROS_Message();
        shieldvr_subscribe.op    = "subscribe";
        shieldvr_subscribe.topic = "/ShieldVRComm";
        shieldvr_subscribe.type  = "std_msgs/String";

        bucket_advertise    = new AdvertiseMessage();
        bucket_advertise.op = "advertise";
        //bucket_advertise.id = "shBucketvr1";
        bucket_advertise.topic = "/ShieldVRCoordinates";
        bucket_advertise.type  = "std_msgs/String";

        bucket_coordinates       = new ROS_Out_Message();
        bucket_coordinates.op    = "publish";
        bucket_coordinates.topic = "/ShieldVRCoordinates";

        message_back       = new ROS_Out_Message();
        message_back.op    = "publish";
        message_back.topic = "/ShieldVRComm";

        //creates a new message to be sent to ROS
        send_message = new ROS_Message();

        //set the op, topic, and type parameters (as detailed in the ROS message protocol)
        send_message.op    = Message_OP;
        send_message.topic = Message_Topic;
        send_message.type  = Message_Type;


        //use WebSocketSharp to connect to the rosbridge
        ws = new WebSocket("ws://" + IP + ":" + PORT);
        ws.Connect();

        if (ws.IsAlive)
        {
            SendConnectionMessages();
        }
        else
        {
            StartCoroutine(Connect());
        }
        //call a method whenever a message comes from ROS
        ws.OnMessage += (sender, e) => DecodeMessage(JSON.Parse(e.Data));
    }
    private void Publish(string id, float forward, float side, float updown, float angle)
    {
        var adMsg = new AdvertiseMessage();

        adMsg.id    = id;
        adMsg.topic = topic;
        adMsg.type  = type;
        string adJson = JsonUtility.ToJson(adMsg);

        Debug.Log(adJson);
        ws.Send(adJson);
        var pubMsg = new PublishMessage(id, forward, side, updown, 0, 0, angle);

        pubMsg.id    = id;
        pubMsg.topic = topic;
        string pubJson = JsonUtility.ToJson(pubMsg, true);

        Debug.Log(pubJson);
        ws.Send(pubJson);
    }