# Robot doesn't turn correctly in user frame

• I am trying to make my robot detect a user frame and rotate about the Y-Axis in a certain number of degrees.

I am using PR to populate the value of the 5th position and apply these changes to the point in my tp program.

The problem I am facing is that if the frame is created at 45 degree from world it will rotate correctly. However, if the frame is created at 0 degrees, it rotates about the X-axis instead. when checking how the user frame looks, they both looks correct.

• ## 95devilsNov 14th 2023

• What are you trying to rotate about? The frame origin? A point? The TCP?

Check out the Fanuc position converter I wrote here! Now open source!

Check out my example Fanuc Ethernet/IP Explicit Messaging program here!

• So here is the code below, I define a frame and set it in UF:1, and then I am trying to rotate about Y and Z. However, I am getting rotation about X and Z instead, if I change the orientation of the frame I get rotation about Y and Z.

The rotation is supposed to take place at the TCP point, which is recorded in P[1]

• Here are a couple of articles that explain what is causing your robot to behave the way that it is.

How is Orientation in Space Represented with Euler Angles? | Mecademic Robotics
Learn how orientation in space is represented with Euler angles and understand their importance in defining tool reference frames.

As you noticed, creating the UFrame at a 45° offset to world gives you the behavior you want. I have no idea what your process or part geometry is, but if it's possible to define your UFrame that way that would be the easiest solution.

• Definitely sounds like Gimbal lock. A quick fix is to use a tool offset for your rotation.

Only use the regular offset for x,y,z frame offsets.

Always use tool offset for w,p,r offsets.

If you follow that rule then you shouldn't experience Gimbal lock.

You can apply both a frame and tool offset onto a single motion instruction if needed.