Inline-four engine animation

Show off your FreeCAD projects here!
User avatar
JMG
Posts: 262
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Inline-four engine animation

Postby JMG » Fri Jun 13, 2014 7:47 am

Hi!

I've created a new animation (for fun and because I think this things attract people to FreeCAD)

https://www.youtube.com/watch?v=HvcdKKO-wPU

Is not complete and it has errors like the valves not opening where they should (because of the circular cam), and there is no crankshaft. But I just couldn't wait to show it :)

OS: Linux Mint 17 Qiana
Platform: 64-bit
Version: 0.14.3671 (Git)
Branch: master
Hash: 57999cb78d5eb0964ba3a81de73a04f539771bce
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
SoQt version: 1.6.0a


Greetings, Javier.
FreeCAD scripts, animations, experiments and more: http://linuxforanengineer.blogspot.com.es/
Open source CNC hot wire cutter project (NiCr): https://github.com/JMG1/NiCr
Exploded Assembly Workbench: https://github.com/JMG1/ExplodedAssembly
User avatar
yorik
Site Admin
Posts: 8570
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Inline-four engine animation

Postby yorik » Fri Jun 13, 2014 1:31 pm

Cool!!
abdullah
Posts: 1504
Joined: Sun May 04, 2014 3:16 pm

Re: Inline-four engine animation

Postby abdullah » Fri Jun 13, 2014 7:53 pm

Very nice!!

Do you have handy a link/forum post where I can read how it is done?
User avatar
JMG
Posts: 262
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: Inline-four engine animation

Postby JMG » Fri Jun 13, 2014 8:43 pm

Thanks!

Abdullah, you can find more info in my blog:

http://linuxforanengineer.blogspot.com. ... ation.html

The engine shown there is more simple but the method remains the same.
FreeCAD scripts, animations, experiments and more: http://linuxforanengineer.blogspot.com.es/
Open source CNC hot wire cutter project (NiCr): https://github.com/JMG1/NiCr
Exploded Assembly Workbench: https://github.com/JMG1/ExplodedAssembly
User avatar
kwahoo
Posts: 186
Joined: Fri Nov 29, 2013 3:09 pm

Re: Inline-four engine animation

Postby kwahoo » Fri Jun 13, 2014 11:56 pm

Cannot sleep (2 a.m. now), because of this animation;) I've started thinking about different, sketch-based method.

My simple animation uses sketch and sketcher solver to determine piston position and conrod position/rotation.

To test the animation:
1. Open the attached file
crank_simul.fcstd
(7.77 KiB) Downloaded 716 times

2. Paste the script in the Python console and hit Enter:

Code: Select all

import FreeCAD as App, FreeCADGui as Gui, Part, time, sys, math, Draft, DraftGeomUtils
from PyQt4 import QtGui,QtCore

class Animation(object):
    def __init__(self):
        App.Console.PrintMessage('init')

        App.ActiveDocument.recompute()

        self.timer = QtCore.QTimer()
        QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.my_update)
        self.timer.start(50)

        self.an = 0.1

    def my_update(self):
        string = '{0}'.format(self.an)
        self.an = self.an + 0.01 if self.an < (2 * math.pi) else 0.0

        angle = math.degrees(self.an)
        App.ActiveDocument.Sketch.setDatum(5,App.Units.Quantity(str(angle)+' deg'))
        App.ActiveDocument.recompute()
        p1 = App.ActiveDocument.Sketch.Shape.Vertexes[0].Point
        p2 = App.ActiveDocument.Sketch.Shape.Vertexes[1].Point
        conrodangle = math.degrees(Draft.DraftVecUtils.angle(App.Vector(1,0,0),(p1-p2))) - 90
        App.ActiveDocument.getObject("Cylinder").Placement = App.Placement(p1,App.Rotation(App.Vector(1,0,0),-90))
        App.ActiveDocument.getObject("Sketch001").Placement = App.Placement(p1,App.Rotation(App.Vector(0,0,1),conrodangle))

    def stop(self):
        self.timer.stop()
         

animation = Animation()

Sorry, no video because of recording software issues (it doesn't like my Intel driver?).
Image

To stop animation type

Code: Select all

animation.stop()
User avatar
JMG
Posts: 262
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: Inline-four engine animation

Postby JMG » Sat Jun 14, 2014 7:57 am

kwahoo, I really like your aproximation, because it involves almost 0 math :)

On the other side, you are using the "recompute" command inside update(). For simple parts this is ok, but when complexity grows, it can be very very slow (my experience: http://linuxforanengineer.blogspot.com. ... heets.html )
FreeCAD scripts, animations, experiments and more: http://linuxforanengineer.blogspot.com.es/
Open source CNC hot wire cutter project (NiCr): https://github.com/JMG1/NiCr
Exploded Assembly Workbench: https://github.com/JMG1/ExplodedAssembly
User avatar
kwahoo
Posts: 186
Joined: Fri Nov 29, 2013 3:09 pm

Re: Inline-four engine animation

Postby kwahoo » Sat Jun 14, 2014 8:26 am

Afaik "recompute()" itself is not the problem, number of sketch constraints/DOF is. But do we need such complicated mechanisms?

PS. Imagine psicofil's buggy with animated suspension simulation. Any volunteers here? :D
bejant
Posts: 4094
Joined: Thu Jul 11, 2013 3:06 pm

Re: Inline-four engine animation

Postby bejant » Sat Jun 14, 2014 4:19 pm

At about 46 - 47 seconds into the video a couple of the piston faces are pre-selected, and it looks like ignition. Nice job Javier!
My Part Design tutorials on YouTube (aimed at beginners).
psicofil
Posts: 153
Joined: Thu Dec 15, 2011 11:02 pm

Re: Inline-four engine animation

Postby psicofil » Sun Jun 15, 2014 5:17 pm

Excellent Javier :shock: !A while ago I did an animation with freecad, python and vrml, on a 7-cylinder radial engine (https://www.youtube.com/watch?v=kzPeJnFNLPI). I'll try to use your script to do it without using vrml.
Thanks for sharing this!!

PS. Imagine psicofil's buggy with animated suspension simulation. Any volunteers here? :D

Would be great! I signed up to help :)

I've started thinking about different, sketch-based method.

kwahoo: Wonderful work! It seems that the kinematics module is approaching to FreeCAD ;)

regards.
User avatar
JMG
Posts: 262
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: Inline-four engine animation

Postby JMG » Sun Jun 15, 2014 5:32 pm

Thanks :D !

It seems that the kinematics module is approaching to FreeCAD


I have something in mind...

Even one or two scripts ;)
FreeCAD scripts, animations, experiments and more: http://linuxforanengineer.blogspot.com.es/
Open source CNC hot wire cutter project (NiCr): https://github.com/JMG1/NiCr
Exploded Assembly Workbench: https://github.com/JMG1/ExplodedAssembly