private void PublishturtleMessage(double linear, double angular)
 {
     try
     {
         string topic   = "/turtle1/command_velocity";
         string msgtype = "turtlesim/Velocity";
         RosBridgeDotNet.RosBridgeDotNet.TurtleSim      turtleGo1 = new RosBridgeDotNet.RosBridgeDotNet.TurtleSim(linear, angular);
         RosBridgeDotNet.RosBridgeDotNet.PublishMessage m         = new RosBridgeDotNet.RosBridgeDotNet.PublishMessage(topic, msgtype, turtleGo1);
         string needToSend = JsonConvert.SerializeObject(m);
         //Object objData = SerializeEventData(new EventData(richTextTxName.Text));
         //byte[] byData = System.Text.Encoding.UTF8.GetBytes(objData.ToString());
         if (_clientSocket != null)
         {
             _clientSocket.Send(new byte[] { 0 });    // \x00
             _clientSocket.Send(Encoding.UTF8.GetBytes(needToSend));
             _clientSocket.Send(new byte[] { 255 });  // \xff
         }
     }
     catch (SocketException se)
     {
         MessageBox.Show(se.Message);
     }
 }
 private void ButtonSendPublishMessage(object sender, EventArgs e)
 {
     try
     {
         string topic   = "/turtle1/command_velocity";
         string msgtype = "turtlesim/Velocity";
         RosBridgeDotNet.RosBridgeDotNet.TurtleSim      turtleGo1 = new RosBridgeDotNet.RosBridgeDotNet.TurtleSim(20, 20);
         RosBridgeDotNet.RosBridgeDotNet.PublishMessage m         = new RosBridgeDotNet.RosBridgeDotNet.PublishMessage(topic, msgtype, turtleGo1);
         string needToSend = JsonConvert.SerializeObject(m);
         richTextBoxHistroryRequests.Text += "\n \\\\\\\\\\\\\\ \n Request : " + needToSend; //save the request in history.
         //Object objData = SerializeEventData(new EventData(richTextTxName.Text));
         //byte[] byData = System.Text.Encoding.UTF8.GetBytes(objData.ToString());
         if (m_clientSocket != null)
         {
             m_clientSocket.Send(new byte[] { 0 });   // \x00
             m_clientSocket.Send(Encoding.UTF8.GetBytes(needToSend));
             m_clientSocket.Send(new byte[] { 255 }); // \xff
         }
     }
     catch (SocketException se)
     {
         MessageBox.Show(se.Message);
     }
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            RosBridgeDotNet.RosBridgeDotNet turtleConnection = new RosBridgeDotNet.RosBridgeDotNet("10.2.230.124");
            string topic   = "/turtle1/command_velocity";
            string msgtype = "turtlesim/Velocity";

            Console.WriteLine(turtleConnection.Connected ? "Connected." : "No connection :(");
            if (turtleConnection.Connected)
            {
                ////'/turtle1/command_velocity', 'turtlesim/Velocity', '{"linear":20, "angular":20}'
                RosBridgeDotNet.RosBridgeDotNet.TurtleSim turtleGo1 = new RosBridgeDotNet.RosBridgeDotNet.TurtleSim(20, 20);
                turtleConnection.Publish(topic, msgtype, turtleGo1);
                //Console.WriteLine("Published: " + topic + " " + msgtype + " " + turtleGo1.linear + " " + turtleGo1.angular);
                //turtleConnection.Subscribe();

                turtleConnection.CloseConnection();
                Console.WriteLine("Connection closed, press a key.");
            }
            else
            {
                Console.WriteLine("End.");
            }
            Console.ReadKey();
        }