├── Assets
├── Materials.meta
├── Materials
│ ├── Floor.mat
│ ├── Floor.mat.meta
│ ├── Mat.mat
│ └── Mat.mat.meta
├── TCPTestServer.cs
├── TCPTestServer.cs.meta
├── UR5.meta
├── UR5.prefab
├── UR5.prefab.meta
├── UR5
│ ├── joint0.prefab
│ ├── joint0.prefab.meta
│ ├── joint1.prefab
│ ├── joint1.prefab.meta
│ ├── joint2.prefab
│ ├── joint2.prefab.meta
│ ├── joint3.prefab
│ ├── joint3.prefab.meta
│ ├── joint4.prefab
│ ├── joint4.prefab.meta
│ ├── joint5.prefab
│ ├── joint5.prefab.meta
│ ├── ur5original.dae
│ └── ur5original.dae.meta
├── UR5Controller.cs
├── UR5Controller.cs.meta
├── movement.cs
├── movement.cs.meta
├── ur5control.unity
└── ur5control.unity.meta
├── NetworkAdapter.PNG
├── README.md
├── UR Scripts
├── JointFunction.script
├── SocketTest.script
├── SocketTest.txt
├── SocketTest.urp
└── default.variables
├── UR.PNG
├── adapters.PNG
├── guestIP.PNG
├── ping.PNG
└── robotnet.PNG
/Assets/Materials.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e2d54deb933ea70419879efc6dba52b0
3 | folderAsset: yes
4 | timeCreated: 1476666671
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/Materials/Floor.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/Assets/Materials/Floor.mat
--------------------------------------------------------------------------------
/Assets/Materials/Floor.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7ac5a4df1e2dec441af8c734f59eaa6f
3 | timeCreated: 1476669155
4 | licenseType: Free
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Materials/Mat.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/Assets/Materials/Mat.mat
--------------------------------------------------------------------------------
/Assets/Materials/Mat.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: abcba99d2a26d4d4ab49f635cfee4a93
3 | timeCreated: 1476666671
4 | licenseType: Free
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/TCPTestServer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Net;
5 | using System.Net.Sockets;
6 | using System.Text;
7 | using System.Threading;
8 | using UnityEngine;
9 |
10 | public class TCPTestServer : MonoBehaviour
11 | {
12 | #region private members
13 | ///
14 | /// TCPListener to listen for incomming TCP connection
15 | /// requests.
16 | ///
17 | private TcpListener tcpListener;
18 | ///
19 | /// Background thread for TcpServer workload.
20 | ///
21 | private Thread tcpListenerThread;
22 | ///
23 | /// Create handle to connected tcp client.
24 | ///
25 | private TcpClient connectedTcpClient;
26 | #endregion
27 |
28 | // Use this for initialization
29 | void Start()
30 | {
31 | // Start TcpServer background thread
32 | tcpListenerThread = new Thread(new ThreadStart(ListenForIncommingRequests));
33 | tcpListenerThread.IsBackground = true;
34 | tcpListenerThread.Start();
35 | }
36 |
37 | // Update is called once per frame
38 | void Update()
39 | {
40 | if (Input.GetKeyDown(KeyCode.Space))
41 | {
42 | SendMessage();
43 | }
44 | }
45 |
46 | ///
47 | /// Runs in background TcpServerThread; Handles incomming TcpClient requests
48 | ///
49 | private void ListenForIncommingRequests()
50 | {
51 | try
52 | {
53 | // Create listener on localhost port 8052.
54 | tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8052);
55 | tcpListener.Start();
56 | Debug.Log("Server is listening");
57 | Byte[] bytes = new Byte[1024];
58 | while (true)
59 | {
60 | using (connectedTcpClient = tcpListener.AcceptTcpClient())
61 | {
62 | // Get a stream object for reading
63 | using (NetworkStream stream = connectedTcpClient.GetStream())
64 | {
65 | int length;
66 | // Read incomming stream into byte arrary.
67 | while ((length = stream.Read(bytes, 0, bytes.Length)) != 0)
68 | {
69 | var incommingData = new byte[length];
70 | Array.Copy(bytes, 0, incommingData, 0, length);
71 | // Convert byte array to string message.
72 | string clientMessage = Encoding.ASCII.GetString(incommingData);
73 | Debug.Log("client message received as: " + clientMessage);
74 | }
75 | }
76 | }
77 | }
78 | }
79 | catch (SocketException socketException)
80 | {
81 | Debug.Log("SocketException " + socketException.ToString());
82 | }
83 | }
84 | ///
85 | /// Send message to client using socket connection.
86 | ///
87 | private void SendMessage()
88 | {
89 | if (connectedTcpClient == null)
90 | {
91 | return;
92 | }
93 |
94 | try
95 | {
96 | // Get a stream object for writing.
97 | NetworkStream stream = connectedTcpClient.GetStream();
98 | if (stream.CanWrite)
99 | {
100 | string serverMessage = "This is a message from your server.";
101 | // Convert string message to byte array.
102 | byte[] serverMessageAsByteArray = Encoding.ASCII.GetBytes(serverMessage);
103 | // Write byte array to socketConnection stream.
104 | stream.Write(serverMessageAsByteArray, 0, serverMessageAsByteArray.Length);
105 | Debug.Log("Server sent his message - should be received by client");
106 | }
107 | }
108 | catch (SocketException socketException)
109 | {
110 | Debug.Log("Socket exception: " + socketException);
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/Assets/TCPTestServer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ac754e7815de9e64e99d2c9c43a58148
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Assets/UR5.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c73fc5d8ef8f04244988240b52fee900
3 | folderAsset: yes
4 | timeCreated: 1476666955
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/UR5.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/Assets/UR5.prefab
--------------------------------------------------------------------------------
/Assets/UR5.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5a0f46b23c6d65f49ab422a6ac75f635
3 | timeCreated: 1476668381
4 | licenseType: Free
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/UR5/joint0.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/Assets/UR5/joint0.prefab
--------------------------------------------------------------------------------
/Assets/UR5/joint0.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1934d47d3bac47d4fbea18882cda3920
3 | timeCreated: 1476666175
4 | licenseType: Free
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/UR5/joint1.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/Assets/UR5/joint1.prefab
--------------------------------------------------------------------------------
/Assets/UR5/joint1.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 86f26c95c73c11246b95076c5e9e1a79
3 | timeCreated: 1476666245
4 | licenseType: Free
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/UR5/joint2.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/Assets/UR5/joint2.prefab
--------------------------------------------------------------------------------
/Assets/UR5/joint2.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 360dd342ff14c144b99db53d767d272f
3 | timeCreated: 1476666504
4 | licenseType: Free
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/UR5/joint3.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/Assets/UR5/joint3.prefab
--------------------------------------------------------------------------------
/Assets/UR5/joint3.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: aa41e226c88177642b70bc3c08755dd8
3 | timeCreated: 1476666523
4 | licenseType: Free
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/UR5/joint4.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/Assets/UR5/joint4.prefab
--------------------------------------------------------------------------------
/Assets/UR5/joint4.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 62ccb2b34e85fc7489a481b5742e0fa0
3 | timeCreated: 1476666544
4 | licenseType: Free
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/UR5/joint5.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/Assets/UR5/joint5.prefab
--------------------------------------------------------------------------------
/Assets/UR5/joint5.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 40be2b75ab11eaa45a5ada5930e21157
3 | timeCreated: 1476666559
4 | licenseType: Free
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/UR5/ur5original.dae.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 41e2022a8a517fa4c8aa6e54c8ba6388
3 | timeCreated: 1476666671
4 | licenseType: Free
5 | ModelImporter:
6 | serializedVersion: 19
7 | fileIDToRecycleName:
8 | 100000: //RootNode
9 | 100002: ur5_joint_0
10 | 100004: ur5_joint_1
11 | 100006: ur5_joint_2
12 | 100008: ur5_joint_3
13 | 100010: ur5_joint_4
14 | 100012: ur5_joint_5
15 | 400000: //RootNode
16 | 400002: ur5_joint_0
17 | 400004: ur5_joint_1
18 | 400006: ur5_joint_2
19 | 400008: ur5_joint_3
20 | 400010: ur5_joint_4
21 | 400012: ur5_joint_5
22 | 2300000: ur5_joint_0
23 | 2300002: ur5_joint_1
24 | 2300004: ur5_joint_2
25 | 2300006: ur5_joint_3
26 | 2300008: ur5_joint_4
27 | 2300010: ur5_joint_5
28 | 3300000: ur5_joint_0
29 | 3300002: ur5_joint_1
30 | 3300004: ur5_joint_2
31 | 3300006: ur5_joint_3
32 | 3300008: ur5_joint_4
33 | 3300010: ur5_joint_5
34 | 4300000: ur5_joint_0
35 | 4300002: ur5_joint_1
36 | 4300004: ur5_joint_2
37 | 4300006: ur5_joint_3
38 | 4300008: ur5_joint_4
39 | 4300010: ur5_joint_5
40 | 9500000: //RootNode
41 | materials:
42 | importMaterials: 1
43 | materialName: 0
44 | materialSearch: 1
45 | animations:
46 | legacyGenerateAnimations: 4
47 | bakeSimulation: 0
48 | resampleCurves: 1
49 | optimizeGameObjects: 0
50 | motionNodeName:
51 | animationImportErrors:
52 | animationImportWarnings:
53 | animationRetargetingWarnings:
54 | animationDoRetargetingWarnings: 0
55 | animationCompression: 1
56 | animationRotationError: 0.5
57 | animationPositionError: 0.5
58 | animationScaleError: 0.5
59 | animationWrapMode: 0
60 | extraExposedTransformPaths: []
61 | clipAnimations: []
62 | isReadable: 1
63 | meshes:
64 | lODScreenPercentages: []
65 | globalScale: 1
66 | meshCompression: 0
67 | addColliders: 0
68 | importBlendShapes: 1
69 | swapUVChannels: 0
70 | generateSecondaryUV: 0
71 | useFileUnits: 1
72 | optimizeMeshForGPU: 1
73 | keepQuads: 0
74 | weldVertices: 1
75 | secondaryUVAngleDistortion: 8
76 | secondaryUVAreaDistortion: 15.000001
77 | secondaryUVHardAngle: 88
78 | secondaryUVPackMargin: 4
79 | useFileScale: 1
80 | tangentSpace:
81 | normalSmoothAngle: 60
82 | normalImportMode: 0
83 | tangentImportMode: 3
84 | importAnimation: 1
85 | copyAvatar: 0
86 | humanDescription:
87 | human: []
88 | skeleton: []
89 | armTwist: 0.5
90 | foreArmTwist: 0.5
91 | upperLegTwist: 0.5
92 | legTwist: 0.5
93 | armStretch: 0.05
94 | legStretch: 0.05
95 | feetSpacing: 0
96 | rootMotionBoneName:
97 | hasTranslationDoF: 0
98 | lastHumanDescriptionAvatarSource: {instanceID: 0}
99 | animationType: 2
100 | humanoidOversampling: 1
101 | additionalBone: 0
102 | userData:
103 | assetBundleName:
104 | assetBundleVariant:
105 |
--------------------------------------------------------------------------------
/Assets/UR5Controller.cs:
--------------------------------------------------------------------------------
1 | // Author: Long Qian
2 | // Email: lqian8@jhu.edu
3 |
4 | // Network supplemantation by Zain
5 | // Email : zainmehdi31@gmail.com
6 | // Special thanks to Bonghan Kim for help in command mapping
7 |
8 | using UnityEngine;
9 | using System.Collections;
10 | using System;
11 | using System.Collections.Generic;
12 | using System.Net;
13 | using System.Net.Sockets;
14 | using System.Text;
15 | using System.Threading;
16 | using UnityEngine.UI;
17 |
18 |
19 |
20 | public class UR5Controller : MonoBehaviour {
21 |
22 |
23 | ///
24 | /// TCPListener to listen for incomming TCP connection
25 | /// requests.
26 | ///
27 | private TcpListener tcpListener;
28 | ///
29 | /// Background thread for TcpServer workload.
30 | ///
31 | private Thread tcpListenerThread;
32 | ///
33 | /// Create handle to connected tcp client.
34 | ///
35 | private TcpClient connectedTcpClient;
36 |
37 |
38 |
39 | public GameObject RobotBase,port;
40 | public Button start;
41 |
42 | int Port = 0;
43 | private string[] buffer;
44 | public float[] jointValues = new float[6];
45 | private GameObject[] jointList = new GameObject[6];
46 | private float[] upperLimit = { 180f, 180f, 180f, 180f, 180f, 180f };
47 | private float[] lowerLimit = { -180f, -180f, -180f, -180f, -180f, -180f };
48 |
49 | bool run = false;
50 |
51 |
52 |
53 | void TaskOnClick()
54 | {
55 | //Output this to console when Button1 or Button3 is clicked
56 | run = !run;
57 | Debug.Log("clicked");
58 | }
59 |
60 | // Use this for initialization
61 | void Start () {
62 | initializeJoints();
63 |
64 | // var z= port.GetComponent();
65 | // Port = int.Parse(z.text);
66 |
67 | // Start TcpServer background thread
68 | tcpListenerThread = new Thread(new ThreadStart(ListenForIncommingRequests));
69 | tcpListenerThread.IsBackground = true;
70 | tcpListenerThread.Start();
71 |
72 | start.onClick.AddListener(TaskOnClick);
73 |
74 |
75 |
76 |
77 | }
78 |
79 | // Update is called once per frame
80 | void LateUpdate () {
81 |
82 | //for (int i = 0; i < 6; i++)
83 | for ( int i = 0; i < 6; i ++) {
84 | Vector3 currentRotation = jointList[i].transform.localEulerAngles;
85 | // Debug.Log(currentRotation);
86 | currentRotation.z = jointValues[i];
87 | jointList[i].transform.localEulerAngles = currentRotation;
88 |
89 |
90 | }
91 | }
92 |
93 | void OnGUI() {
94 | int boundary = 20;
95 |
96 |
97 | #if UNITY_EDITOR
98 | int labelHeight = 25;
99 | GUI.skin.label.fontSize = GUI.skin.box.fontSize = GUI.skin.button.fontSize = 18;
100 | #else
101 | int labelHeight = 40;
102 | GUI.skin.label.fontSize = GUI.skin.box.fontSize = GUI.skin.button.fontSize = 40;
103 | #endif
104 |
105 | GUI.skin.label.alignment = TextAnchor.MiddleLeft;
106 | for (int i = 0; i < 6; i++)
107 | {
108 | GUI.Label(new Rect(50, boundary + (i * 2 + 1) * labelHeight+250, labelHeight * 7, labelHeight), "Joint " + i +" = "+jointValues[i].ToString("F1")+" "+ " ");
109 | // jointValues[i] = GUI.HorizontalSlider(new Rect(boundary+50 + labelHeight * 4, boundary + (i * 2 + 1) * labelHeight + labelHeight / 4, labelHeight * 5, labelHeight), jointValues[i], lowerLimit[i], upperLimit[i]);
110 | }
111 | }
112 |
113 |
114 | // Create the list of GameObjects that represent each joint of the robot
115 | void initializeJoints() {
116 | var RobotChildren = RobotBase.GetComponentsInChildren();
117 | for (int i = 0; i < RobotChildren.Length; i++) {
118 | if (RobotChildren[i].name == "control0") {
119 | jointList[0] = RobotChildren[i].gameObject;
120 | }
121 | else if (RobotChildren[i].name == "control1") {
122 | jointList[1] = RobotChildren[i].gameObject;
123 | }
124 | else if (RobotChildren[i].name == "control2") {
125 | jointList[2] = RobotChildren[i].gameObject;
126 | }
127 | else if (RobotChildren[i].name == "control3") {
128 | jointList[3] = RobotChildren[i].gameObject;
129 | }
130 | else if (RobotChildren[i].name == "control4") {
131 | jointList[4] = RobotChildren[i].gameObject;
132 | }
133 | else if (RobotChildren[i].name == "control5") {
134 | jointList[5] = RobotChildren[i].gameObject;
135 | }
136 | }
137 | }
138 |
139 | ///
140 | /// Runs in background TcpServerThread; Handles incomming TcpClient requests
141 | ///
142 | private void ListenForIncommingRequests()
143 | {
144 | try
145 | {
146 | // Create listener on localhost port 8052.
147 | //tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8052);
148 | tcpListener = new TcpListener(IPAddress.Any, 5000);
149 | tcpListener.Start();
150 | Debug.Log("Server is listening");
151 | Byte[] bytes = new Byte[1024];
152 | while (true)
153 | {
154 | using (connectedTcpClient = tcpListener.AcceptTcpClient())
155 | {
156 | // Get a stream object for reading
157 | using (NetworkStream stream = connectedTcpClient.GetStream())
158 | {
159 | int length;
160 | // Read incomming stream into byte arrary.
161 | while ((length = stream.Read(bytes, 0, bytes.Length)) != 0)
162 | {
163 | var incommingData = new byte[length];
164 | Array.Copy(bytes, 0, incommingData, 0, length);
165 | // Convert byte array to string message.
166 | string clientMessage = Encoding.ASCII.GetString(incommingData, 0, incommingData.Length);
167 | buffer = clientMessage.Split(';');
168 |
169 | jointValues[0] = (float)((Convert.ToDouble(buffer[0])*(-1))*180/Math.PI);
170 | jointValues[1] = (float)(((Convert.ToDouble(buffer[1]))*(-1)) * 180 / Math.PI - 90f);
171 | jointValues[2] = -1f*(float)((Convert.ToDouble(buffer[2])) * 180 / Math.PI);
172 | jointValues[3] = (float)((Convert.ToDouble(buffer[3])) * 180 / Math.PI) * (-1) - 90f;
173 | jointValues[4] = (float)((Convert.ToDouble(buffer[4])) * 180 / Math.PI);
174 | jointValues[5] = (float)((Convert.ToDouble(buffer[5])) * 180 / Math.PI);
175 |
176 |
177 | //Debug.Log("Angle 3" + jointValues[2]);
178 | }
179 | }
180 | }
181 | }
182 | }
183 | catch (SocketException socketException)
184 | {
185 | Debug.Log("SocketException " + socketException.ToString());
186 | }
187 | }
188 | ///
189 | /// Send message to client using socket connection. just a test
190 | ///
191 | private void SendMessage()
192 | {
193 | if (connectedTcpClient == null)
194 | {
195 | return;
196 | }
197 |
198 | try
199 | {
200 | // Get a stream object for writing.
201 | NetworkStream stream = connectedTcpClient.GetStream();
202 | if (stream.CanWrite)
203 | {
204 | string serverMessage = "This is a message from your server.";
205 | // Convert string message to byte array.
206 | byte[] serverMessageAsByteArray = Encoding.ASCII.GetBytes(serverMessage);
207 | // Write byte array to socketConnection stream.
208 | stream.Write(serverMessageAsByteArray, 0, serverMessageAsByteArray.Length);
209 | Debug.Log("Server sent his message - should be received by client");
210 | }
211 | }
212 | catch (SocketException socketException)
213 | {
214 | Debug.Log("Socket exception: " + socketException);
215 | }
216 | }
217 |
218 |
219 |
220 |
221 | }
222 |
--------------------------------------------------------------------------------
/Assets/UR5Controller.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7ecef9e11ab72cc498fc423a41f92fa4
3 | timeCreated: 1476669283
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/movement.cs:
--------------------------------------------------------------------------------
1 | // Author: Zain
2 | // Email : zainmehdi31@gmail.com
3 | using System;
4 | using System.Collections;
5 | using System.Collections.Generic;
6 | using UnityEngine;
7 | using UnityEngine.UI;
8 |
9 | public class movement : MonoBehaviour
10 | {
11 |
12 |
13 | public GameObject target;//the target object
14 | private float speedMod = 10.0f;//a speed modifier
15 | private Vector3 point;//the coord to the point where the camera looks at
16 |
17 | private bool rotateClock = false;
18 | private bool rotateAnticlock = false;
19 |
20 | public Button rotateclockwise, rotateanticlockwise;
21 | void Start()
22 | {
23 | point = target.transform.position;
24 | //get target's coords
25 | //transform.LookAt(new Vector3(point.x,point.y,point.z+3));//makes the camera look to it
26 | rotateanticlockwise.onClick.AddListener(TaskOnRotateAntiClockwise);
27 | rotateclockwise.onClick.AddListener(TaskOnRotateClockwise);
28 | }
29 |
30 | private void TaskOnRotateClockwise()
31 | {
32 |
33 | rotateClock = !rotateClock;
34 |
35 | }
36 |
37 | private void TaskOnRotateAntiClockwise()
38 | {
39 | rotateAnticlock = !rotateAnticlock;
40 |
41 | }
42 |
43 | // Update is called once per frame
44 | void Update()
45 | {
46 | if (rotateClock)
47 | {
48 | transform.RotateAround(point, new Vector3(0.0f, 1.0f, 0.0f), 5 * Time.deltaTime * speedMod);
49 | }
50 |
51 | if (rotateAnticlock)
52 | {
53 | transform.RotateAround(point, new Vector3(0.0f, 1.0f, 0.0f), -5 * Time.deltaTime * speedMod);
54 | }
55 |
56 | }
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/Assets/movement.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f4b2ff6da93691d449d188eca1466a1a
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Assets/ur5control.unity:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/Assets/ur5control.unity
--------------------------------------------------------------------------------
/Assets/ur5control.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 77eca27774daf9542987aa5bdcbd223f
3 | timeCreated: 1476668940
4 | licenseType: Free
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/NetworkAdapter.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/NetworkAdapter.PNG
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot-
2 |
3 | **All the credit for original package and controller goes to [Long Qian](http://longqian.me/aboutme), [Shuyang Chen](https://www.linkedin.com/in/shuyang-shawn-chen-346ab6109) for creating the prefab and initial script.
4 |
5 | This fork Simulates UR using joint angles being published by a real robot over TCP IP.
6 | ### Additions and Modifications are as follows:
7 | #### - TCP server that can connect to real UR5/UR10
8 | #### - Some modifications in the joint angle mapping to replicate actual robot.
9 | (*Thanks to Bonghan Kim for his assistance)
10 | #### - Buttons for camera rotation.
11 | #### - Guide for setting up URSIM for simulation ( Would like to Thank Jeong Il Hwan for his guidance)
12 |
13 | You need to publish joint angles from UR script to this server in order to replicate motion.
14 |
15 | Results on Editor:
16 | 
17 |
18 | ## Instructions for URsim / Actual Robot
19 | ### UR Simulator
20 | I have used URSIM version 3.11 which can be downloaded from https://www.universal-robots.com/download/?option=18940.
21 |
22 | ### VMware
23 | Download vmware from https://www.vmware.com/products/workstation-pro/workstation-pro-evaluation.html. I think any version not so obsolete should work. Once you have installed vmware you should have two VMware Network Adapters named VMnet1 and VMnet8 in Windows network Connections.
24 |
25 | 
26 |
27 | ### Setup
28 | - First you need to configure network settings in vmware. Go to Player->Manage-> Virtual Machine Settings. In "Device" panel choose
29 | "Network Adapter". In my case I choose VMnet8(NAT).
30 |
31 | 
32 |
33 | - Open network adapter's properties in Windows and set static ip address of VMnet8 adapter. In my case it was
34 | "192.168.102.128". I set ip of VMnet8 as "192.168.102.1" with same subnet mask. This will be the IP of your server.
35 |
36 | - Check ipv4 address of guest in vmware using ifconfig.
37 |
38 | 
39 |
40 | - Open URsim10/URsim5 and check robots network setting in "Setup Robot" -> Network. Choose DHCP. It will assign the same ip address to
41 | the robot as that of guest (192.168.102.128) in my case.
42 |
43 | 
44 |
45 | - Disable firewall in windows otherwise guest wont be able to communicate with the host.
46 | - If everything goes well you should be able to ping back and forth between guest and the host.
47 |
48 | 
49 |
50 | ### UR Script
51 | Here is a simple UR script that will get joint angles and publish it to our server. Make sure to adjust IP addresses and ports
52 | accordingly.
53 |
54 | ```
55 | Program
56 | BeforeStart
57 | Script: JointFunction.script
58 | Robot Program
59 | MoveJ
60 | Waypoint_1
61 | Waypoint_2
62 | Thread_1
63 | Loop sockon≟ True
64 | getjointAngles()
65 | Wait: 0.05
66 | If sockon≟ False
67 | socket_close("sock1")
68 | sockon=socket_open("192.168.102.1",5000)
69 | Wait: 0.01
70 | ```
71 | #### jointFunction Script
72 |
73 | ```
74 | global angles=[0,0,0,0,0,0]
75 | global angles_send=""
76 |
77 | sockon=socket_open("192.168.102.1",5000,"sock1")
78 | def getjointAngles():
79 | angles=get_actual_joint_positions()
80 | angles_send=str_cat(angles[0],";")
81 | angles_send=str_cat(angles_send,angles[1])
82 | angles_send=str_cat(angles_send,";")
83 | angles_send=str_cat(angles_send,angles[2])
84 | angles_send=str_cat(angles_send,";")
85 | angles_send=str_cat(angles_send,angles[3])
86 | angles_send=str_cat(angles_send,";")
87 | angles_send=str_cat(angles_send,angles[4])
88 | angles_send=str_cat(angles_send,";")
89 | angles_send=str_cat(angles_send,angles[5])
90 | sockon= socket_send_line(angles_send)
91 |
92 | end
93 |
94 | ```
95 | ### Results
96 | https://youtu.be/tdT8hij__Fo
97 |
--------------------------------------------------------------------------------
/UR Scripts/JointFunction.script:
--------------------------------------------------------------------------------
1 | global angles=[0,0,0,0,0,0]
2 | global angles_send=""
3 |
4 | sockon=socket_open("192.168.102.1",5000,"sock1")
5 | def getjointAngles():
6 | angles=get_actual_joint_positions()
7 | angles_send=str_cat(angles[0],";")
8 | angles_send=str_cat(angles_send,angles[1])
9 | angles_send=str_cat(angles_send,";")
10 | angles_send=str_cat(angles_send,angles[2])
11 | angles_send=str_cat(angles_send,";")
12 | angles_send=str_cat(angles_send,angles[3])
13 | angles_send=str_cat(angles_send,";")
14 | angles_send=str_cat(angles_send,angles[4])
15 | angles_send=str_cat(angles_send,";")
16 | angles_send=str_cat(angles_send,angles[5])
17 | sockon= socket_send_line(angles_send)
18 |
19 |
20 | end
21 |
--------------------------------------------------------------------------------
/UR Scripts/SocketTest.script:
--------------------------------------------------------------------------------
1 | def SocketTest():
2 | set_tcp(p[0.0,0.0,0.0,0.0,0.0,0.0])
3 | set_payload(0.0)
4 | set_standard_analog_input_domain(0, 1)
5 | set_standard_analog_input_domain(1, 1)
6 | set_tool_analog_input_domain(0, 1)
7 | set_tool_analog_input_domain(1, 1)
8 | set_analog_outputdomain(0, 0)
9 | set_analog_outputdomain(1, 0)
10 | set_input_actions_to_default()
11 | set_tool_voltage(0)
12 | set_safety_mode_transition_hardness(1)
13 | set_gravity([0.0, 0.0, 9.82])
14 | $ 1 "BeforeStart"
15 | $ 2 "Script: JointFunction.script"
16 | global angles=[0,0,0,0,0,0]
17 | global angles_send=""
18 |
19 | sockon=socket_open("192.168.102.1",5000,"sock1")
20 | def getjointAngles():
21 | angles=get_actual_joint_positions()
22 | angles_send=str_cat(angles[0],";")
23 | angles_send=str_cat(angles_send,angles[1])
24 | angles_send=str_cat(angles_send,";")
25 | angles_send=str_cat(angles_send,angles[2])
26 | angles_send=str_cat(angles_send,";")
27 | angles_send=str_cat(angles_send,angles[3])
28 | angles_send=str_cat(angles_send,";")
29 | angles_send=str_cat(angles_send,angles[4])
30 | angles_send=str_cat(angles_send,";")
31 | angles_send=str_cat(angles_send,angles[5])
32 | sockon= socket_send_line(angles_send)
33 |
34 |
35 | end
36 | $ 7 "Thread_1"
37 | thread Thread_1():
38 | while (True):
39 | $ 8 "Loop sockon≟ True "
40 | thread Thread_while_8():
41 | while (True):
42 | $ 9 "getjointAngles()"
43 | getjointAngles()
44 | $ 10 "Wait: 0.05"
45 | sleep(0.05)
46 | end
47 | end
48 | if (sockon == True ):
49 | global thread_handler_8=run Thread_while_8()
50 | while (sockon == True ):
51 | sync()
52 | end
53 | kill thread_handler_8
54 | end
55 | $ 11 "If sockon≟ False "
56 | if (sockon == False ):
57 | $ 12 "socket_close('sock1')"
58 | socket_close("sock1")
59 | $ 13 "sockon=socket_open('192.168.102.1',5000)"
60 | sockon=socket_open("192.168.102.1",5000)
61 | $ 14 "Wait: 0.01"
62 | sleep(0.01)
63 | end
64 | end
65 | end
66 | threadId_Thread_1 = run Thread_1()
67 | while (True):
68 | $ 3 "Robot Program"
69 | $ 4 "MoveJ"
70 | $ 5 "Waypoint_1"
71 | movej([6.938893903907228E-18, -1.7271001974688929, -2.2029998938189905, -0.8079999128924769, 1.5951000452041626, -0.03099996248354131], a=1.3962634015954636, v=1.0471975511965976)
72 | $ 6 "Waypoint_2"
73 | movej([1.5707963705062866, -1.7271001974688929, -2.2029998938189905, -0.8079999128924769, 1.5951000452041626, -0.03099996248354131], a=1.3962634015954636, v=1.0471975511965976)
74 | end
75 | end
76 |
--------------------------------------------------------------------------------
/UR Scripts/SocketTest.txt:
--------------------------------------------------------------------------------
1 | Program
2 | BeforeStart
3 | Script: JointFunction.script
4 | Robot Program
5 | MoveJ
6 | Waypoint_1
7 | Waypoint_2
8 | Thread_1
9 | Loop sockon≟ True
10 | getjointAngles()
11 | Wait: 0.05
12 | If sockon≟ False
13 | socket_close("sock1")
14 | sockon=socket_open("192.168.102.1",5000)
15 | Wait: 0.01
16 |
--------------------------------------------------------------------------------
/UR Scripts/SocketTest.urp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/UR Scripts/SocketTest.urp
--------------------------------------------------------------------------------
/UR Scripts/default.variables:
--------------------------------------------------------------------------------
1 | #
2 | #Sat Nov 16 01:09:23 CET 2019
3 |
--------------------------------------------------------------------------------
/UR.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/UR.PNG
--------------------------------------------------------------------------------
/adapters.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/adapters.PNG
--------------------------------------------------------------------------------
/guestIP.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/guestIP.PNG
--------------------------------------------------------------------------------
/ping.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/ping.PNG
--------------------------------------------------------------------------------
/robotnet.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zainmehdi/UR-Simulation-in-Unity-Hardware-in-the-loop-Animation-of-Real-Robot/c5c2dea23ea43b7d7b48ef7b02fa5fe92a120b44/robotnet.PNG
--------------------------------------------------------------------------------