rparak / Unity3D_Robotics_UR

A digital-twin of the Universal Robots UR3 integrated into the Unity3D development platform.
MIT License
142 stars 50 forks source link

UR3 robot in Unity3D did not change joint states as the URSim robot. #5

Open 2000222 opened 1 year ago

2000222 commented 1 year ago

Hello, I've successfully connect the Unity3D with URSim with the IP address and it's possible to utilize the "Joystick Panel" to control URSim robot remotely. But the robot in Unity3D did not change its condition to be the same as that in URSim. Then when I close the Unity running mode, I obtained the following issue:

ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 size) (at <0463b2ef957545c0a51b42f372cd4fbb>:0)
ur_data_processing+UR_Stream.UR_Stream_Thread () (at Assets/Scripts/UR3/ur_data_processing.cs:234)
System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Threading.ThreadHelper.ThreadStart () (at <695d1cc93cca45069c528c15c9fdd749>:0)
UnityEngine.<>c:<RegisterUECatcher>b__0_0(Object, UnhandledExceptionEventArgs)

How can I fix the problem, thank u very much.

ZiruiHong commented 1 year ago

Hi Roman Parak,

I encountered the same problem as mentioned by 2000222. And my situation is exactly the same.

I attached the debug info and some snapshots regarding the issue for your reference.

Error 1: ObjectDisposedException

System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 size) (at <0463b2ef957545c0a51b42f372cd4fbb>:0)
ur_data_processing+UR_Control.UR_Control_Thread () (at Assets/Scripts/UR3/ur_data_processing.cs:354)
System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Threading.ThreadHelper.ThreadStart () (at <695d1cc93cca45069c528c15c9fdd749>:0)
UnityEngine.<>c:<RegisterUECatcher>b__0_0(Object, UnhandledExceptionEventArgs)

Error 2: SocketException

SocketException: A blocking operation was interrupted by a call to WSACancelBlockingCall.

System.Net.Sockets.Socket.Receive (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags) (at <0463b2ef957545c0a51b42f372cd4fbb>:0
![IMG1](https://user-images.githubusercontent.com/56145438/202973158-67d8ae9e-7dc4-4703-8e31-df3073a51284.png)
![IMG2](https://user-images.githubusercontent.com/56145438/202973159-33b4f358-93f3-4070-9e07-ad25fc5a9d08.png)
![IMG3](https://user-images.githubusercontent.com/56145438/202973160-2195264f-171a-4052-bb4c-0f416df3e010.png)
![IMG4](https://user-images.githubusercontent.com/56145438/202973161-45d3ae76-8633-4f09-8f86-68c7224da29c.png)
![IMG5](https://user-images.githubusercontent.com/56145438/202973164-e86b4a10-d760-4556-9671-d16cc9875c9f.png)
![IMG6](https://user-images.githubusercontent.com/56145438/202973165-231b39df-2482-48ab-893c-25b59185910e.png)
)
System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 size) (at <0463b2ef957545c0a51b42f372cd4fbb>:0)
Rethrow as IOException: Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall.

I get stuck in these problems for quite some time. Any help from you will be really appreciated!

IMG1 IMG2 IMG3 IMG4 IMG5 IMG6

rparak commented 1 year ago

Hey (@2000222 , @ZiruiHong ),

sorry for the late response, but as always, I'm busy.

I have tested the app and everything works properly (simulation only). Since I only have the CB version in my lab, I have not tested the latest UR-e version in real-world. However, I have received a lot of positive feedback that everything works without problems.

First of all, If you are using the UR-e version of the robot, you need to change lines 93 and 97 in the C# script. Link: https://github.com/rparak/Unity3D_Robotics_UR/blob/main/Universal_Robots_Unity_App/Assets/Scripts/UR3/ur_data_processing.cs

Because the communication rate of the CB-version of the robot I used is 125 Hz (8 milliseconds) and the new one is 500 Hz (2 milliseconds). Just change the time step value from 8 to 2.

But I suppose that's not the main problem. You will probably need to enable the remote control.

Remote Control option on the UR robot controller if you have a UR-e robot (UR3e, UR5e or UR10e): 1.Select the Settings menu from the top right button. 2.Select System-Remote Control. 3.Select Enable. 4.Change the mode of operation to Remote Control

Note: The first generation of UR robots (non UR-e) such as UR3, UR5 and UR10 already has the Remote Control option enabled by default.

I hope everything is clear, if not, contact me at: Roman.Parak@outlook.com

Have a great day.

RP