示例#1
0
    public void SendGridInformation(int x, int y)
    {
        message_back       = new ROS_Out_Message();
        message_back.op    = "publish";
        message_back.topic = "/ShieldVRComm";
        message_back.msg   = new Message("<" + x + "," + y + ">");

        if (ws.IsAlive)
        {
            ws.Send(JsonUtility.ToJson(message_back));
        }
    }
示例#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));
    }