# Why does my UR5 wobble and spin?

Hello I am training a UR5 with reinforcement learning. My agent takes a action which is the joint angles of the robot. These action i get it in the environment and publish it as a trajectory message to the corresponding rostopic (say A) which moves the robot in Gazebo. I have a another rostopic (say B) which subscribes the message from the simulation. The messabe that B subscribes is the new joint angles. Therefore, the agent gives A and so B should be equal to A. **Note: The limit of joint angles is from -pi to pi**

Now when I start the training, initially for about 50 episodes B also shows the value of A (Which should be true always). But after a certain number of episodes, some of the joint angles in B increases above 100 rad or 400 or 700 which doesn't make any sense. the robot starts spinning and wobbling and the training session is just over then.

What probably could be going wrong is it because of some parameters in the urdf, xacro or the controllers which I need to modify?

I am also attaching two pictures here, the first picture shows both the topic showing the same joint angles. The left one is the action taken by the agent and published to a topic to move the robot and the right is the topic which gets the joint angles from the simulation to calculate the states and the rewards

1) The first picture when everything is fine, (look the positions) C:\fakepath\70040905-910ffb00-15bc-11ea-99d8-c0c72d4b30df.png

2) After a certain number of episodes C:\fakepath\22225.png