# 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?

Cross-posted to Gazebo Answers: Why does my UR5 wobble and spin?.