• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by abutalebmohsin1987 · Jan 31, 2019 at 06:19 AM · unityeditordisplayclient-serverrobot

Is it possible to receive data from Universal robot simulation software(Polyscope ) and display in Unity?

I am simulating a universal robot arm in the universal robot simulation software known as polyscope and connecting the simulated arm using websockets by creating an external server (Python server and have also tried using a C#server) for sending position commands to the arm in the simulator software(Polyscope) to move to a new position.

I wanted to ask is it possible to retrieve the position values from the robot simulation software and display it in unity. Do I need to write a C# script in unity to get the data from the universal robot simulation client or can I integrate the server I have created directly to unity? Or is it not possible?

I am sharing the code which is from the universal robot. Can anyone please let me know retrieve the values from the client so that when I play the scene in unity, the position values are displayed?

The server code from the universal robot is as follows :

   using System;
   using System.Net;
   using System.Net.Sockets;
   using System.Text;
 
   namespace URServer
  {

 class Program
 {

 static void Main(string[] args)
 {

  // The IP address of the server (the PC on which this program is running)
 string sHostIpAddress = "127.0.0.1";
 // Standard port number
  int nPort = 21;

  // The following names are used in the PolyScope script for refencing the
  // three working points:
   // Name of an arbitrary work point 1
   const string csMsgPoint1 = "Point_1";
 // Name of an arbitrary work point 2
  const string csMsgPoint2 = "Point_2";
  // Name of an arbitrary work point 3
  const string csMsgPoint3 = "Point_3";

  Console.WriteLine("Opening IP Address: " + sHostIpAddress);
   IPAddress ipAddress = IPAddress.Parse(sHostIpAddress);        // Create the IP address
  Console.WriteLine("Starting to listen on port: " + nPort);
  TcpListener tcpListener = new TcpListener(ipAddress, nPort);  // Create the tcp Listener
   tcpListener.Start();                                          // Start listening

   // Keep on listening forever
  while (true)
  {
   TcpClient tcpClient = tcpListener.AcceptTcpClient();        // Accept the client
   Console.WriteLine("Accepted new client");
   NetworkStream stream = tcpClient.GetStream();               // Open the network stream
   while (tcpClient.Client.Connected)
   {
     // Create a byte array for the available bytes
     byte[] arrayBytesRequest = new byte[tcpClient.Available];
     // Read the bytes from the stream
     int nRead = stream.Read(arrayBytesRequest, 0, arrayBytesRequest.Length);
     if (nRead > 0)
     {
       // Convert the byte array into a string
       string sMsgRequest = ASCIIEncoding.ASCII.GetString(arrayBytesRequest);
       Console.WriteLine("Received message request: " + sMsgRequest);
       string sMsgAnswer = string.Empty;

       // Check which workpoint is requested
       if (sMsgRequest.Substring (0,7).Equals(csMsgPoint1))
       {
         // Some point in space for work point 1
         sMsgAnswer = "(0.4, 0, 0.5, 0, -3.14159, 0)";
         }
       else if (sMsgRequest.Substring(0, 7).Equals(csMsgPoint2))
      {
         // Some point in space for work point 2
         sMsgAnswer = "(0.3, 0.5, 0.5, 0, 3.14159, 0)";;
      }
       else if (sMsgRequest.Substring(0, 7).Equals(csMsgPoint3))
       {
         // Some point in space for work point 3
        sMsgAnswer = "(0, 0.6, 0.5, 0, 3.14159, 0)";
       }

       if (sMsgAnswer.Length > 0)
       {
         Console.WriteLine("Sending message answer: " + sMsgAnswer);
          // Convert the point into a byte array
         byte[] arrayBytesAnswer = ASCIIEncoding.ASCII.GetBytes(sMsgAnswer+'\n');
         // Send the byte array to the client
         stream.Write(arrayBytesAnswer, 0, arrayBytesAnswer.Length);
       }
     }
     else
     {
        if (tcpClient.Available == 0)
       {
         Console.WriteLine("Client closed the connection.");
          // No bytes read, and no bytes available, the client is closed.
         stream.Close();
        }
      }
     }
   }
  }
 }
 }

The client code in Universal robot polyscope is as follows

   Program
   BeforeStart
  open≔socket_open("127.0.0.1",21)
  Loop open≟ False
  open≔socket_open("127.0.0.1",21)
  targetPos≔p[0,0,0,0,0,0]
  counter≔0
  Robot Program
  sendToServer≔'send to server'
  socket_send_string(sendToServer)
  receiveFromServ≔socket_read_ascii_float(6)
  Loop receiveFromServ[0]≠6
  Wait: 0.3
   receiveFromServ≔socket_read_ascii_float(6)
   Loop counter<6
   targetPos[counter]=receiveFromServ[counter+1]
   counter≔counter+1
   MoveJ
    targetPos
   counter:=0   
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

166 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to fix this error during invoke a robot movement in ROS ? 0 Answers

Need Help! How to give a command from ROS to robot? 0 Answers

Edit a script from another script 1 Answer

The count of buttons gives user 0 Answers

How to create an event trigger script for intercepted events 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges