// 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)); }
// Use this for initialization void Start() { // send a message to ROS with the op, topic, and type ROS_Message send_message = new ROS_Message(Message_OP, Message_Topic, Message_Type); // initialize the websocket connection to the instance of ROS ws = new WebSocket("ws://" + IP + ":" + Port); ws.Connect(); // send the ROS message ws.Send(JsonUtility.ToJson(send_message)); // set the message recieved callback ws.OnMessage += (sender, e) => DecodeMessage(JSON.Parse(e.Data)); }