Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illustrative ex for viz #11

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open

Conversation

tarzzz
Copy link
Contributor

@tarzzz tarzzz commented Jun 23, 2013

Added code according to PEP8 conventions

point = link.get_masscenter()
forces.append((point, -mass * g * I.y) )

kinetic_differentials = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a picky comment, but differentials are different from differential equations. Also are these kinematic or kinetic? The word kinetic is sometimes used to mean "dynamic" (that is, coming from F=ma).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are kinematic equations.

On 6/23/13, Christopher Dembia [email protected] wrote:

+#Applying forces on all particles , and adding all forces in a list..
+forces = []
+for particle in particles:
+

  • mass = particle.get_mass()
  • point = particle.get_point()
  • forces.append((point, -mass * g * I.y) )

+#Applying forces on rigidbodies ..
+for link in links:

  • mass = link.get_mass()
  • point = link.get_masscenter()
  • forces.append((point, -mass * g * I.y) )

+kinetic_differentials = []

This is a picky comment, but differentials are different from differential
equations. Also are these kinematic or kinetic? The word kinetic is
sometimes used to mean "dynamic" (that is, coming from F=ma).


Reply to this email directly or view it on GitHub:
https://github.com/PythonDynamics/pydy_examples/pull/11/files#r4833547

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the correct term is "kinematic differential equations"

@chrisdembia
Copy link
Contributor

Hey Tarun, cool stuff. I made some notes.

@moorepants
Copy link
Member

How about changing this example so that it imports the results of your three pendulum example and this would only have the code for the simulation and visualization. Right now you have the same code in both files and have to maintain them both.

'l3':1.0, 'm1':2, 'm2':2, 'm3':2, \
'M1':5, 'M1':5, 'M1':5]

json = frame1.generate_json(initial_conditions, q)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this take the results from odeint + some output equations numerical results and then generate a json file? It doesn't seem like the correct info will be available here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a visualization at (well in this case) t=0.
so we know initial-conditions and shapes/objects info at t=0. we can
visualize it.

for animation we would certainly require json generated from this
output + numerical-vals from odeint.
although if we want to implement the visualization at any specific
time other than initial(t=0), then it would certainly require
numerical-vals.
but on the other hand, in future we will allow user to fast fwd
animations to specific time, so it might be deprecated.

On 6/24/13, Jason Moore [email protected] wrote:

+numerical_vals = odeint(right_hand_side, init_conditions, t)
+
+#Now for each t, we have numerical vals of coordinates ..
+#Now we set up a visualization frame,
+
+frame1 = VisualizationFrame('frame1',I , O)
+
+frame1.add_rigidbodies(links)
+
+frame1.add_particles(particles)
+
+param_vals_for_viz = {'g':9.8, 'l1':1.0, 'l2':1.0, \

  •                  'l3':1.0, 'm1':2, 'm2':2, 'm3':2, \
    
  •                  'M1':5, 'M1':5, 'M1':5]
    
    +json = frame1.generate_json(initial_conditions, q)

Shouldn't this take the results from odeint + some output equations
numerical results and then generate a json file? It doesn't seem like the
correct info will be available here.


Reply to this email directly or view it on GitHub:
https://github.com/PythonDynamics/pydy_examples/pull/11/files#r4846400

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is any reason to make different things for visualizations at t=t1 versus t=t0 versus t=[1, 2, 3, 4, 5]. You're methods should accept any numerical values of t and output equations (functions of q) to generate the visualization. If you supply values at one instant of time then you get a static visualization, but if you supply lists/arrays then you should be able to play the animation through time. These are not distinct cases (static viz at one config and animations). A static viz is just one frame of the animation.

#also it doesnot check for TypeErrors etc.

class MeshShape(object):
def __init__(self,name,point_list,color='grey',origin=[0,0,0]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces after commas

@chrisdembia
Copy link
Contributor

I know that the essential.py is posted so that the example can work, but I would encourage you to use a more descriptive name in the future. The name essential doesn't really tell me what's in that file.

@chrisdembia
Copy link
Contributor

How come there are 2 three_link_pendulum.py files now?

frame3 = VisualizationFrame('frame3', link3, shape=shape3)

scene = Scene('scene1',I,O)
scene.vframes = [frame1,frame2,frame3]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better if there was not a setter like this; see other comment.

@chrisdembia
Copy link
Contributor

This has to do with illustrative_example.py:

I know I've said it before but I find it unnecessary for the user to make the visualization frames on their own. They could easily just forget to add one of the bodies in their multibody system. I imagine something like this:

scene = Scene('scene1', KanesMethod) # assuming Kane's Method knows about inertial frame.
# This will initialize a VisualizationFrame for each rigid body, with names <body_name>
print scene.vframe['link1']
scene.vframe['link1'].shape = shape1
scene.vframe['link2'].shape = shape2
scene.vframe['link3'].shape = shape3

I wish the pydy interface were a little different, so that this would ideally be:

sys = System('three_link_pendulum')
sys.add_rigid_body(RigidBody('link1', ...)
sys.add_rigid_body(RigidBody('link2', ...)
sys.add_rigid_body(RigidBody('link3', ...)
km = KanesMethod(sys)
# ...
scene = Scene('scene1', sys)
# as above

If we need to, we could resort to:

scene = Scene('scene1', body_list)
# as above

just as we pass a body list to KanesMethod. I think that this is better than doing the wiring between VFrames and RigidBody's ourselves. I'm happy to discuss this though.

@moorepants
Copy link
Member

Tarun,

Please git rm js/output.json because there are always conflicts when trying to switch branches and merging etc. It is a real nuisance. My modifications to the code allowed for much faster generation so it shouldn't be necessary to hang on to it. We can speed things up faster too once I figure out a few issues.

self._transform = Identity(4).as_mutable()

def transform(self, reference_frame, point):
# TODO : make sure this actually works correctly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this here because I was having some trouble with evaluating the matrix with lambdify and array arguments. There may be a better way to construct this matrix, but it is probably fine for now.

@moorepants
Copy link
Member

Remaining items before merge:

  • Fixed links in animation to have cylinders end at the joints.
  • Add spheres for the particles.
  • Add a better figure.

@tarzzz
Copy link
Contributor Author

tarzzz commented Sep 22, 2013

@moorepants It can be merged now ..


$ git clone https://github.com/PythonDynamics/pydy-viz

2) Add the directory to the PYTHONPATH::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to instruct them to actually install it here:

cd pydy-viz
python setup.py install # use sudo if you want system wide install

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do the python path trick addition as an option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be best if you showed how to run each file in this directory indenpendently. You have the derivation file, the simulation, and the visualization.

Ideally the user could type three commands to run things individually:

python derive.py
python simulate.py
python visualize.py

The results of the previous command could be pickled to file so that the subsequent file could load the data. If the data isn't available on disk, then it can run

try:
    open('simulate-data.p')
except IOError:
    import simulate # runs simulate.py if data doesn't exits

# do the simulation ...

# pickle the results
pickle.dump(simulation_results)

moorepants added a commit to pydy/pydy that referenced this pull request Jun 29, 2014
This adds the example problem Tarun developed and used when designing the
visualization package. I've updated it to run with the current version of PyDy.
The original pull request can be found here:

pydy/pydy_examples#11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants