Inline-four engine animation

Show off your FreeCAD projects here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
JMG
Posts: 287
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Inline-four engine animation

Post by JMG »

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
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Inline-four engine animation

Post by yorik »

Cool!!
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Inline-four engine animation

Post by abdullah »

Very nice!!

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

Re: Inline-four engine animation

Post by JMG »

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: 680
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Re: Inline-four engine animation

Post by kwahoo »

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 1917 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()
JMG
Posts: 287
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: Inline-four engine animation

Post by JMG »

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: 680
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Re: Inline-four engine animation

Post by kwahoo »

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
User avatar
bejant
Veteran
Posts: 6075
Joined: Thu Jul 11, 2013 3:06 pm

Re: Inline-four engine animation

Post by bejant »

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!
User avatar
psicofil
Posts: 154
Joined: Thu Dec 15, 2011 11:02 pm

Re: Inline-four engine animation

Post by psicofil »

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.
Ing. Gomez Lucio
Scope Ingenieria (scopeingenieria.com)
JMG
Posts: 287
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: Inline-four engine animation

Post by JMG »

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
Post Reply