Assembly4: Strange behaviour when rotating LCS about Y axis

Discussion about the development of the Assembly workbench.
keithp
Posts: 7
Joined: Fri May 14, 2021 1:42 pm

Assembly4: Strange behaviour when rotating LCS about Y axis

Postby keithp » Fri May 14, 2021 1:51 pm

First I'd like to thank Zolko and the others who have worked to develop the Assembly4 workbench. It's a really great addition to FreeCAD.

I've been trying to model a robot arm using LCSs, and found something unexpected. I have attached a small test file, and I'd be grateful if others could try this to see if they get the same results.

The file just contains four LCSs, LCS_Origin, LCS_X, LCS_Y and LCS_Z. Each of the last three are attached to LCS_Origin and are offset along the X, Y and Z directions respectively (just so they can be seen easily; the offset doesn't appear to affect the behaviour). They are arranged to rotate around the X, Y and Z axes respectively, controlled by Variables AngleX, AngleY and AngleZ.

In the Assembly4 workbench, select Assembly/Animate Assembly. Select variable AngleX, set the range to 0 to 360, click Run and watch LCS_X rotate. Nothing unexpected there. Select AngleZ, and LCS_Z will also rotate nicely. Now try AngleY. At least on my setup, LCS_Y rotates until it gets to 90 degrees, then reverses and rotates the other way until it reaches 270 degrees, then reverses again and rotates back to the start position.

Oddly, if I change the angle by using the current value slider in the Animate Assembly window, LCS_Y rotates in one direction without reversals.

Another strange thing can happen if I fiddle with the Run/Stop buttons and the current value slider (I can't give an exact way to reproduce this, just play). LCS_Y can permanently rotate, such that when AngleY current value is 0, the LCS is rotated by 180 degrees around the Y axis. In this condition, the LCS_Y Attachment Offsets around the X and Z axes are changed to -180 or +180. To see this, right click on LCS_Y in the Attributes pane, then choose Assembly/Edit Placement of a Datum object from the popup menu.

I'd appreciate any confirmation or otherwise of this effect, and advice on whether this should be reported as a bug.

FreeCAD Assembly 4 workbench
Current version 0.9.16, 2021-05-03

OS: Mageia 7 (KDE//usr/share/xsessions/01plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24276 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 0.19.1)
Hash: a88db11e0a908f6e38f92bfc5187b13ebe470438
Python version: 3.8.8
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United Kingdom (en_GB)
Attachments
AngleTest.FCStd
(6.58 KiB) Downloaded 29 times
keithp
Posts: 7
Joined: Fri May 14, 2021 1:42 pm

Re: Assembly4: Strange behaviour when rotating LCS about Y axis

Postby keithp » Sat May 15, 2021 2:21 pm

Here's another even simpler example file which clearly shows the rotation reversals and flips on the Y axis.

This just has a single LCS, LCS_XYZ, which is set up to rotate about the X, Y and Z axes, controlled by variables AngleX, AngleY and AngleZ respectively.

When AngleX is varied from 0 to 360 degrees, the LCS rotates continously about the X axis (red), as expected:
AngleX.gif
AngleX.gif (23.11 KiB) Viewed 1872 times
Similarly for AngleZ:
AngleZ.gif
AngleZ.gif (20.04 KiB) Viewed 1872 times
However with AngleY, the LCS reverses direction at 90 and 270 degrees and flips by 180 degrees:
AngleY.gif
AngleY.gif (23.08 KiB) Viewed 1872 times
Gifs were generated by the Assembly4 workbench Animate Assembly Export feature and tweaked with gifsicle.
Attachments
AngleTest2.FCStd
(5.72 KiB) Downloaded 22 times
User avatar
Zolko
Posts: 1427
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly4: Strange behaviour when rotating LCS about Y axis

Postby Zolko » Sat May 15, 2021 7:39 pm

keithp wrote: Sat May 15, 2021 2:21 pm However with AngleY, the LCS reverses direction at 90 and 270 degrees and flips by 180 degrees:AngleY.gif
This is clearly a guimbal lock

Gifs were generated by the Assembly4 workbench Animate Assembly Export feature and tweaked with gifsicle.
nice, do you like that feature ?
try the Assembly4 workbench for FreCAD v0.19
install with Tools > Addon Manager > Assembly4 — tutorials here and here
keithp
Posts: 7
Joined: Fri May 14, 2021 1:42 pm

Re: Assembly4: Strange behaviour when rotating LCS about Y axis

Postby keithp » Sun May 16, 2021 11:04 am

Zolko wrote: Sat May 15, 2021 7:39 pm
keithp wrote: Sat May 15, 2021 2:21 pm However with AngleY, the LCS reverses direction at 90 and 270 degrees and flips by 180 degrees:AngleY.gif
This is clearly a guimbal lock
I'm not familiar with the internals of FreeCAD or the Assembly4 workbench. Are Euler angles used to represent rotations? Is the issue a bug which is fixable or is it an inherent limitation which has to be lived with and worked around?

Aside: the flipping behaviour reminds me of this.

Zolko wrote: Sat May 15, 2021 7:39 pm
keithp wrote: Sat May 15, 2021 2:21 pm Gifs were generated by the Assembly4 workbench Animate Assembly Export feature and tweaked with gifsicle.
nice, do you like that feature ?
Yes, it's great! Much easier than messing about with screen recorders and the like. The ability to set a background is a nice touch. One minor detail: it doesn't appear to be possible to generate a single loop. Apparently the loop count in a gif has to be set to one less than the number of loops you want, but 0 has the special meaning of "loop forever". There should be another way to tell your gif generator to produce a single loop (gifsicle has a --no-loopcount option).
User avatar
Zolko
Posts: 1427
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly4: Strange behaviour when rotating LCS about Y axis

Postby Zolko » Sun May 16, 2021 12:07 pm

keithp wrote: Sun May 16, 2021 11:04 am
Zolko wrote: Sat May 15, 2021 7:39 pm This is clearly a guimbal lock
I'm not familiar with the internals of FreeCAD or the Assembly4 workbench. Are Euler angles used to represent rotations? Is the issue a bug which is fixable or is it an inherent limitation which has to be lived with and worked around?
it's a bug that was introduced by someone else, who did so by improving another feature. I thought that it will someday cause problems, but the improvement was so good that I left it. I was also curious to see how the problem will materialize. Now it's here, we need to fix it.

Aside: the flipping behaviour reminds me of this:

phpBB [video]
nice, but I think that's a different story (I'd bet on conservation of circular momentum and precession). That's also probably the explanation to the inversion of Earth's magnetic poles.
try the Assembly4 workbench for FreCAD v0.19
install with Tools > Addon Manager > Assembly4 — tutorials here and here
keithp
Posts: 7
Joined: Fri May 14, 2021 1:42 pm

Re: Assembly4: Strange behaviour when rotating LCS about Y axis

Postby keithp » Mon May 17, 2021 6:40 pm

If rotations about the local Y axis are avoided, everything works very well. As an example, here's a simulated walk cycle for a simple servo-driven robot leg. The inverse kinematics equations were implemented as FreeCAD expressions using Assembly4 variables. The simulation was generated using Assembly Animate and exported as a gif, which was then tweaked with gifsicle.
walk.gif
walk.gif (313.28 KiB) Viewed 1685 times
The Assembly4 workbench appears to be an effective way to integrate design, assembly and simulation of this type of system within FreeCAD. Of course it will be even better if the Y axis issue can be resolved.
heron
Posts: 131
Joined: Mon Apr 20, 2020 5:32 pm

Re: Assembly4: Strange behaviour when rotating LCS about Y axis

Postby heron » Tue May 18, 2021 4:19 am

keithp wrote: Fri May 14, 2021 1:51 pm I'd appreciate any confirmation or otherwise of this effect, and advice on whether this should be reported as a bug.


That doesn't happen to me
AngleTest.gif
AngleTest.gif (169.04 KiB) Viewed 1617 times
keithp
Posts: 7
Joined: Fri May 14, 2021 1:42 pm

Re: Assembly4: Strange behaviour when rotating LCS about Y axis

Postby keithp » Tue May 18, 2021 6:54 am

heron wrote: Tue May 18, 2021 4:19 am That doesn't happen to me
Interesting. Could you post your Assembly4 Workbench version (from Addon Manager) and your FreeCAD version info (Help --> About FreeCAD, Copy to clipboard)?

Thank you.
heron
Posts: 131
Joined: Mon Apr 20, 2020 5:32 pm

Re: Assembly4: Strange behaviour when rotating LCS about Y axis

Postby heron » Tue May 18, 2021 12:34 pm

keithp wrote: Tue May 18, 2021 6:54 am Could you post your Assembly4 Workbench version (from Addon Manager) and your FreeCAD version info
Of course, but I think that the question is the way to get the LCS rotation. If I open your file and run Animate Assembly with AngleY variable, ocurrs the same to you.
I did it as explained in the manual, you did something that I do not understand. Your "Variables" icon of the Model Tree is diferent to mine.
icon_Variables.png
icon_Variables.png (17.45 KiB) Viewed 1519 times
It has a property called "Animation Hints/Animation Hint List" that mine does not have.
The LCS_XYZ also is different. The Base/Expression Engine field has code that I guess relates the variables to the LCS. I don't even know how to write in this field.

I wrote the post because I was curious, you do not take me into account to solve the issue.
:mrgreen:
Assy4_info.png
Assy4_info.png (43.12 KiB) Viewed 1519 times


OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24291 (Git)
Build type: Release
Branch: (HEAD detached at 0.19.2)
Hash: 7b5e18a0759de778b74d3a5c17eba9cb815035ac
Python version: 3.8.8
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.4.0
Locale: Spanish/Spain (es_ES)
keithp
Posts: 7
Joined: Fri May 14, 2021 1:42 pm

Re: Assembly4: Strange behaviour when rotating LCS about Y axis

Postby keithp » Wed May 19, 2021 8:51 am

Hi heron,

Thank you for your very informative reply.

I notice you are using a slightly newer FreeCAD version than I am. I've now updated mine to be the same, 0.19.24291. The strange Y axis behaviour I see is still the same. There is still the difference that you are running on Windows 10 and I'm running the AppImage on Linux.

On my system, the Variables icon for my AngleTest2 file hasn't changed - it's the same as the one you show for your AngleTest3.

I unzipped the AngleTest2 file and I see that the properties Animation Hints/Animation Hint List and Base/Expression Engine are both present in the file. They only appear in the Property pane if the Show all option is ticked (right click in the Property pane to see/change this).

Is it possible that you have Show all turned on for one document and not for the other? Another possibility is that these properties are only written to the file when it is saved, so if you hadn't saved your file after running Animate Assembly, they may not have been present.

heron wrote: Tue May 18, 2021 12:34 pm you did something that I do not understand.
I agree. I don't understand it either!

I've tried different ways of creating and attaching the LCS, but I always get the strange Y axis behaviour.

It would be very helpful if you could point me to the part of the manual which explains how you created your file. Perhaps you could also attach your AngleTest3 file so I can compare it against my efforts.

Thank you again for your help.