[Robot, Python] Calculation of Trajectory fails with continuous waypoints on a line

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
HannesW
Posts: 2
Joined: Sun Feb 03, 2019 3:37 pm

[Robot, Python] Calculation of Trajectory fails with continuous waypoints on a line

Post by HannesW »

In some cases the calculation of a Robot.Trajectory fails, when it consists of three points that are placed exactly on a line and the middle point is continuous.
As a result of the failure all values of the trajectory are NaN, the Duration, the Length and the positions at every time. An exception is never raised.

The weird thing is, the success or failure of the calculation seems to depend on the exact element values of the position vectors.
In the example below two sets of points are used:
set1: {(0, 0, 0), (500, 500, 500), (1000, 1000, 1000)}
set2: {(0, 0, 0), (600, 600, 600), (1200, 1200, 1200)}
With set1 the trajectory becomes invalid (all values Nan, but no exception), set2 leads to a perfectly valid trajectory.

I think the problem is inside the KD-library used to build the trajectory.
My guess is the Path_RoundedComposite::Add method. But I don't have the FreeCAD sources set up in a development environment and therefore can not debug it.

The following Python code leads to the mentioned problem (first the Python console output I received in FreeCad 0.17 or 0.18-pre. The raw code is below).
One can see that the first point set leads to an invalid trajectory (without exceptions) while the second set succeeds as expected:

Code: Select all

from FreeCAD import Placement,Vector,Rotation
>>> from Robot import Trajectory, Waypoint
>>> 
>>> t=Trajectory()
>>> t.insertWaypoints(Waypoint(Placement(Vector(0.0,0,0.0),Rotation()), type="LIN", cont=False))
Trajectory [size:1 length:0 duration:0 ]
>>> t.insertWaypoints(Waypoint(Placement(Vector(500.0,500.0,500.0),Rotation()), type="LIN", cont=True))
Trajectory [size:2 length:866.03 duration:5.8857 ]
>>> t.insertWaypoints(Waypoint(Placement(Vector(1000.0,1000.0,1000.0),Rotation()), type="LIN", cont=False))
Trajectory [size:3 length:-1.#IND duration:-1.#IND ]
>>> t.Duration
nan
>>> t.Length
nan
>>> t.position(0)
Placement [Pos=(-1.#IND,-1.#IND,-1.#IND), Yaw-Pitch-Roll=(-1.#IND,-1.#IND,-1.#IND)]
>>> 
>>> t=Trajectory()
>>> t.insertWaypoints(Waypoint(Placement(Vector(0.0,0,0.0),Rotation()), type="LIN", cont=False))
Trajectory [size:1 length:0 duration:0 ]
>>> t.insertWaypoints(Waypoint(Placement(Vector(600.0,600.0,600.0),Rotation()), type="LIN", cont=True))
Trajectory [size:2 length:1039.2 duration:6.4474 ]
>>> t.insertWaypoints(Waypoint(Placement(Vector(1200.0,1200.0,1200.0),Rotation()), type="LIN", cont=False))
Trajectory [size:3 length:2078.5 duration:9.118 ]
>>> t.Duration
9.11802822781911
>>> t.Length
2078.460969082653
>>> t.position(0)
Placement [Pos=(0,0,0), Yaw-Pitch-Roll=(0,0,0)]
The raw code:

Code: Select all

from FreeCAD import Placement,Vector,Rotation
from Robot import Trajectory, Waypoint

t=Trajectory()
t.insertWaypoints(Waypoint(Placement(Vector(0.0, 0.0, 0.0),Rotation()), type="LIN", cont=False))
t.insertWaypoints(Waypoint(Placement(Vector(500.0, 500.0, 500.0),Rotation()), type="LIN", cont=True))
t.insertWaypoints(Waypoint(Placement(Vector(1000.0, 1000.0, 1000.0),Rotation()), type="LIN", cont=False))
t.Duration
t.Length
t.position(0)

t=Trajectory()
t.insertWaypoints(Waypoint(Placement(Vector(0.0, 0.0, 0.0),Rotation()), type="LIN", cont=False))
t.insertWaypoints(Waypoint(Placement(Vector(600.0, 600.0, 600.0),Rotation()), type="LIN", cont=True))
t.insertWaypoints(Waypoint(Placement(Vector(1200.0, 1200.0, 1200.0),Rotation()), type="LIN", cont=False))
t.Duration
t.Length
t.position(0)
I tested it with FreeCAD 0.17 and the current 0.18 pre release:

Code: Select all

FreeCAD OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13522 (Git)
Build type: Release
Branch: releases/FreeCAD-0-17
Hash: 3bb5ff4e70c0c526f2d9dd69b1004155b2f527f2
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: German/Germany (de_DE)

Code: Select all

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15805 (Git)
Build type: Release
Branch: master
Hash: f431226bb827d960588485fbae5b5c072c7b640c
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: German/Germany (de_DE)
Can somebody else confirm this behavior or can tell me the reason for this issue?
Post Reply