## Thursday, 6 August 2015

### FreeCAD: Double Slider Mechanism Animation

Since few days ago, this blog is two years old, and, also, last month it crossed the 4000 views/month barrier.
I was thinking about a way of celebrating this events, and last night I saw a .gif image about a flat mechanism at which I could be staring the whole day:

I don't know its exact name, but "double slider mechanism" seems appropriate. It belongs to the family of flat, four bar linkage mechanisms, and, possibly, there is no real use for this one. But it moves very smoothly, with the outer end of the rotating arm drawing some kind of ellipse.

The kinematics of this one are not too difficult (none of the family of four bar linkage mechanism are), and for the animation I have solved it in an analytical way.

The code:

```# Javier Martinez Garcia    August 2015   GPL V2.0

from PySide import QtCore
from math import sin, cos, radians

# retrieve the objects from the document

# store initial placement (needed to restore initial position)
slider_x_placement = slider_x.Placement
slider_y_placement = slider_y.Placement
arm_placement = arm.Placement

# store object placements in a new variable
r_slider_x_pl = slider_x.Placement
r_slider_y_pl = slider_y.Placement
r_arm_pl = arm.Placement

def reset():
# function to restore initial position of the objects
slider_x.Placement = r_slider_x_pl
slider_y.Placement = r_slider_y_pl
arm.Placement = r_arm_pl

# In this mechanism, "i" represents the angle of the rod in degrees
i = 0

# update function calculates object position as f(i) and increases i
def update():
global i
x = 150.0*cos( alpha )
y = 150.0*sin( alpha )
slider_x_placement.Rotation )

slider_y_placement.Rotation )

# update the scene
# increase mechanism input position
i += 1

# create a timer object
timer = QtCore.QTimer()
# connect timer event to function "update"
timer.timeout.connect( update )
# start the timer to trigger "update" every 10 ms
timer.start( 10 )
```