Page 1 of 1

Sketch Feature to create linkage mechanism simulator

Posted: Tue Apr 11, 2017 1:57 pm
by NewbieSimulator
The sketch feature can be used to create linkage kinematics simulation using constraints such as lock, coincide, length, angle, etc...
And using the python script you can make an animation out of it.
It's good enough that you can make an animated jansen mechanism using it.

I'm new at python scripting, by the way.

Here I used a simple four-bar linkage.
1st.png
1st.png (177.59 KiB) Viewed 3313 times
The 30 mm crank is constrained angularly with the x-axis. That constraint is what I used to move the mechanism.
You only need to rotate the crank in order to move the entire mechanism.


editing the python script in macro editor, you can manipulate the angle constraint to change value at every instant of time, as well as the interval " i += 0.1"

from PySide import QtCore

i = 0
def update():
global i
# use the "Constraint Number minus 1" for the # in the (#.App.Units.Quantity(i)) in the line below
App.ActiveDocument.Sketch.setDatum(8,App.Units.Quantity(i))
App.ActiveDocument.recompute()
i += 0.1

timer = QtCore.QTimer()
timer.timeout.connect( update )
timer.start( 1 )
this code is the one responsible for changing the value of the selected constraint,
in this case, my angular constraint is number 9, but you must always subtract 1.
I honestly don't know why.
App.ActiveDocument.Sketch.setDatum(8,App.Units.Quantity(i))

you can copy the edited script from the macro editor and paste it in the python console, or execute it directly from the macros.
After that you can exit the sketcher and the animation will still continue.
Just type timer.stop() to stop the animation
3rd.png
3rd.png (130.17 KiB) Viewed 3304 times

Re: Sketch Feature to create linkage mechanism simulator

Posted: Tue Apr 18, 2017 7:43 am
by saiteja
Hello,

I'm new to FreeCad and the forum. Could you walk me through step by step on the procedure. I've tried what you did but it did not work for me. I'm hoping to simulate a Five Bar Mechanism one day similar to Dexter Robot.

Thank You
Sai

Re: Sketch Feature to create linkage mechanism simulator

Posted: Tue Apr 18, 2017 8:00 am
by r-frank
Hello sai.

Welcome to FreeCAD and the forum.
For more convenience i would use the animation workbench (extra add-on, Needs to be installed).
I made a tutorial for a four bar linkage with german audio.

Since the pace is slow i am hoping that it will give you a first start.

You may also have a look at the macro animated constraint.

Roland

Re: Sketch Feature to create linkage mechanism simulator

Posted: Tue Apr 18, 2017 12:49 pm
by NewbieSimulator
saiteja wrote:Hello,

I'm new to FreeCad and the forum. Could you walk me through step by step on the procedure. I've tried what you did but it did not work for me. I'm hoping to simulate a Five Bar Mechanism one day similar to Dexter Robot.

Thank You
Sai
This 2D technique is only limited to studying kinematics of linkage mechanisms.
If you want to animate an assembly you should follow Roland's advice.

You should study making constraints in the sketch mode, check it on youtube.

Constraints are used to limit the parameters of an element, for example, a line in sketch mode consists of 2 points, and 1 edge. You can constrain a point to a specific position, which means you lock it to that position. Or you constrain its length to a specific length.

You can use the concepts of mechanisms to choose which constraint you'll use. Since linkage mechanisms have links which are connected, you have to use coincident constraint at each intersection. And they also have constant lengths, so you have to constrain the lengths of each link. If you successfully constrained all the necessary elements you can interactively move the mechanism with your mouse. The animation us just extra.

Re: Sketch Feature to create linkage mechanism simulator

Posted: Wed Apr 19, 2017 5:44 pm
by mario52
hi

you must use the expression for create constraint and animate all "ensemble"

here example :
only the circle rotation create the movement for all objects connected

see here for + explanation Macro_Constraint_Draft

Image

the file
Constraint_Draft00.FCStd
(11.96 KiB) Downloaded 473 times
+ 1 For the same sketcher constraint system in the DraftWorkbench

mario

Re: Sketch Feature to create linkage mechanism simulator

Posted: Thu May 11, 2017 1:06 pm
by NewbieSimulator
I made a video regarding making a simple four-bar linkage and sliding linkage.

https://www.youtube.com/watch?v=8llFZxxloXg

there is no python scripting in the video , since the animation script doesn't seem to work in the version of freeCAD I'm using.

Re: Sketch Feature to create linkage mechanism simulator

Posted: Thu May 11, 2017 3:49 pm
by wandererfan
NewbieSimulator wrote:this code is the one responsible for changing the value of the selected constraint,
in this case, my angular constraint is number 9, but you must always subtract 1.
I honestly don't know why.
The OCC geometry kernel indexes arrays [1..n] rather than the usual C++/Python convention of [0..n-1]. The naming of Edges, Vertices, Faces, etc reflects the OCC convention, while the actual Python lists in FreeCAD follow the Python convention.

Now you know.

wf

Re: Sketch Feature to create linkage mechanism simulator

Posted: Tue May 16, 2017 4:16 pm
by NewbieSimulator
wandererfan wrote:
NewbieSimulator wrote:this code is the one responsible for changing the value of the selected constraint,
in this case, my angular constraint is number 9, but you must always subtract 1.
I honestly don't know why.
The OCC geometry kernel indexes arrays [1..n] rather than the usual C++/Python convention of [0..n-1]. The naming of Edges, Vertices, Faces, etc reflects the OCC convention, while the actual Python lists in FreeCAD follow the Python convention.

Now you know.

wf
Thanks for the extra info! I'll keep that in mind next time I do some coding.