Inline-four engine animation

Show off your FreeCAD projects here!
wbr
Posts: 2
Joined: Thu Aug 07, 2014 1:09 pm
Location: Atlanta Georgia United States

Re: Inline-four engine animation

Postby wbr » Fri Aug 08, 2014 11:41 pm

kwahoo,

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


I used your code (I found it originally on the FreeCAD tutorial Piston + conrod sketch-based animation) to get my own animations started. I posted about it originally in the Open Discussion forum:
Project to simulate motion from control system output

Now that I've spent some time in the forums, that post probably fits better in the Python scripts forum. :oops:

Thanks to your code, I now have simple linear and rotary simulations to work with. I have the PLC and motion control simulations already. Now I can work on getting the position updates out of the control simulation and into the FC models. When the Assembly workbench is farther along, I'll figure out how to convert over to that.

Regards
rogerj
Posts: 2
Joined: Mon Nov 10, 2014 8:33 pm

Re: Inline-four engine animation

Postby rogerj » Mon Nov 10, 2014 10:33 pm

"from PyQt4 import QtGui,QtCore" returns an error message:
File "<input>", line 1, in <module>
ImportError: No module named PyQt4

I found riverbankcomputing.com, and their web page saying SIP must already be installed and built before installying PyQt4. Searching "PyQt4" in this forum returns overwhelming results. Then I found http://www.freecadweb.org/wiki/index.php?title=PyQt saying FreeCAD switched to PySide. So I...
Edited the script to read "from PySide import QtGui,QtCore" rather than "from PyQt4 import QtGui,QtCore".

An error message that I can not reproduce or remember occurred when I ctrl-v pasted the script into Pyton Console. So I put the script in a macro, which appeared to do nothing when ran as well as no error messages (previously it complained about PyQt4). Then restarted FreeCAD, loaded crank_simul.fcstd, and the graphics automatically animated with very rapid twitching between two crank angles (less than 180 degrees of each other) and slowly moving. I'm guessing if the solver was not twitching, it would produce a smooth graphic.

Looking to hide the script to confirm its whats running, I
renamed "crank_simul.FCMacro" file to something different, like crank_____simul.FCMacro, restarted and crank.fcstd loads without automatically animating. Manually running the newly named script started smoothly animating the graphics (after a wait for it to load). Renamed it back to "crank_simul.FCMacro", restarted and re-opened crank_simulate.fcstd, but it did not automatically load, and seems to work fine when manually running the script in a macro.

But, "animation.stop()" in the python console still produces: "NameError: name 'animation' is not defined"
and trying "my_animation = Animation()" in the python console, I get "NameError: name 'Animation' is not defined". Unlike when I type "App." in the console, which displays a list of properties - typing "application." does not produce a list of properties.

I am new to FreeCAD and Python.
Any pointers?
User avatar
clintonsam75
Posts: 291
Joined: Thu Jun 19, 2014 5:54 pm
Location: South Korea
Contact:

Re: Inline-four engine animation

Postby clintonsam75 » Wed Nov 12, 2014 7:56 am

I have not looked at the code but from the error message, it looks like animate is outside the namespace. What is the api you're importing? For example, if I use the pygame API and I want to call a method called animation.stop() within the API without importing the namespace then I would call the method like this: pygame.animation.stop(). Obviously you're not using pygame because that API doesn't have an animation class. I just used it as an example. That's why I asked what API you're using.

Anyway, someone who is familiar with the code can probably help you more if my thoughts aren't helpful enough.
User avatar
clintonsam75
Posts: 291
Joined: Thu Jun 19, 2014 5:54 pm
Location: South Korea
Contact:

Re: Inline-four engine animation

Postby clintonsam75 » Wed Nov 12, 2014 7:59 am

rogerj wrote:"from PyQt4 import QtGui,QtCore" returns an error message:
File "<input>", line 1, in <module>
ImportError: No module named PyQt4


Oops. My bad. I guess I skimmed over that part. Sorry.

Did you check your path environment settings?
rogerj
Posts: 2
Joined: Mon Nov 10, 2014 8:33 pm

Re: Inline-four engine animation

Postby rogerj » Thu Nov 13, 2014 4:22 am

I edited the script to use PySide rather than PyQt4
User avatar
clintonsam75
Posts: 291
Joined: Thu Jun 19, 2014 5:54 pm
Location: South Korea
Contact:

Re: Inline-four engine animation

Postby clintonsam75 » Fri Nov 14, 2014 12:33 am

rogerj wrote:But, "animation.stop()" in the python console still produces: "NameError: name 'animation' is not defined"
and trying "my_animation = Animation()" in the python console, I get "NameError: name 'Animation' is not defined". Unlike when I type "App." in the console, which displays a list of properties - typing "application." does not produce a list of properties.


I noticed that you capitalized animation the second time but it is not capitalized the first time. Was that just a typo you made here in the post or do you think it might be that way in the code as well?
User avatar
clintonsam75
Posts: 291
Joined: Thu Jun 19, 2014 5:54 pm
Location: South Korea
Contact:

Re: Inline-four engine animation

Postby clintonsam75 » Fri Nov 14, 2014 12:49 am

Ah. Nevermind. I just looked at the link to the code you posted. Obviously you were trying to instantiate a new object from class Animation and that is not working. It looks like Python isn't seeing the animation class, but that's weird because you said the animation is running. It's kind of as if Python uses the animation class to start the animation then forgets about it. Hmmm......

Anyone else have any ideas?
User avatar
clintonsam75
Posts: 291
Joined: Thu Jun 19, 2014 5:54 pm
Location: South Korea
Contact:

Re: Inline-four engine animation

Postby clintonsam75 » Fri Nov 14, 2014 1:07 am

I'm going to download the fcstd file and work on this tomorrow (Saturday Korea time). It's about time I learn how to do this in detail anyway.
peterl94
Posts: 658
Joined: Thu May 23, 2013 7:31 pm
Location: United States

Re: Inline-four engine animation

Postby peterl94 » Fri Nov 14, 2014 4:41 am

rogerj wrote:NameError: name 'animation' is not defined


It is because when you run a macro it is not interpreted by the console. That script wasn't designed to be run as a macro because there is no way to stop it besides calling animation.stop(). However, what you can do is rename the macro file with a .py extension and than just run from crank_simul import * and then you will be able to run animation.stop()
User avatar
clintonsam75
Posts: 291
Joined: Thu Jun 19, 2014 5:54 pm
Location: South Korea
Contact:

Re: Inline-four engine animation

Postby clintonsam75 » Fri Nov 14, 2014 5:13 am

peterl94 wrote:
rogerj wrote:NameError: name 'animation' is not defined


It is because when you run a macro it is not interpreted by the console. That script wasn't designed to be run as a macro because there is no way to stop it besides calling animation.stop(). However, what you can do is rename the macro file with a .py extension and than just run from crank_simul import * and then you will be able to run animation.stop()


I had just figured that out myself. hahaha. I was just working on it. Yes, I cannot access variables defined within a macro. :lol: