# Multibody Simulation using sympy, scipy and vpython

113 views

Citation of segment
Embed Code

 Title Multibody Simulation using sympy, scipy and vpython Title of Series EuroPython 2015 Part Number 170 Number of Parts 173 Author Braun, Oliver License CC Attribution - NonCommercial - ShareAlike 3.0 Unported:You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license. DOI 10.5446/20177 Publisher EuroPython Release Date 2015 Language English Production Place Bilbao, Euskadi, Spain

 Subject Area Computer Science Abstract Oliver Braun - Multibody Simulation using sympy, scipy and vpython The talk is about the implementation of multibody simulation in the scientific python world on the way to a stage usefull for engineering and educational purposes. Multibody simulation (MBS) requires two major steps: first the formulation of the specific mechanical problem. Second step is the integration of the resulting equations. For the first step we use the package sympy which is on a very advanced level to perform symbolic calculation and which supports already Lagrange's and Kane's formalism. The extensions we made are such that a complex mechanical setup can be formulated easily with several lines of python code. The functionality is analogous to well known MBS-tools, with that you can assemble bodies, joints, forces and constraints. Also external forces even in a cosimulation model can be added on top. The second step, the integration is done via ode- integrators implemented in scipy. Finally for visual validation the results are visualized with the vpython package and for further analytics with matplotlib. Conclusion: not only highly constrained pendulums with many rods and springs but also driving simulation of passenger cars an be performed with our new extension using python packages off the shelf. Keywords EuroPython Conference EP 2015 EuroPython 2015
Series
Annotations
Transcript
the but so this is the outline of my
my talk today at the 1st of all an introduction about what about simulation next um yeah OK some background information and then I would like to show you some assemblies so I would fill this talk um at least half of it but to show you some assemblies so that you get an X. impression what is in
fact possible that this package in the end and this package is not uh in public already it will be published maybe in September and in the end I will give you a short short note of Due to work and
and some think baggage name it is said what move Boston which is variance mortarboard
symbolic so in fact there are 2 different ways to approach this problem you can use symbolic equations and you can stick more to it American side most of the most of the in Industrial Park and industrial products that stick to the numerical side but we decided to approach it analytically a what aim is to provide on the basis of existing bed Python packages to pro-whites once in a while a complete multibody simulation to with soul why is this important for us and mean you can guess that we want to be independent from market leaders and market leaders in for example a simple or also yellow or also Adams and cause a whole lot
of money and the license and and all of these companies are now not so they are now yeah bought by a very big companies so it is not possible to work with them to stick in this development process much the 2nd scripting abilities include its head and of course that's in Python so it's uh it's so I'm of course include and 3rd educational purposes so what this modified simulation wanted but assimilation deals with them systems which can be described by these equations do that in Newtonian on the equations and they they had differential equations and so they are well known since several hundred
years what is the problem writing them down and integrating them well the problem here is as you will see it in my talk
and this is not only an expression which you can write down on it said it happens that most of what he body simulation assemblies include constraints and constraints on like a ball which runs on the table and or sliders so what so ever so this constraint forces are infects the difficult thing in multiple assimilation and we look back at the development process of 30 years more or there's not ask but in general so that there a the on the community at the end the scientific community and work on was working on this problem since more than 30 years and you can imagine there come up with a whole constant papers or the fair and and yeah and you cannot expect to to climb up within half a year on top but we are very enthusiastic and we think we can go ahead to so use cases itself this mode of assimilation is mechanical engineering grounding the dynamic robotics and by mechanics each of these branches and more of where
a each of the spreading branches and it's
modern and relevant so I'm working and ground read the dynamics and some on 7 years and I'm doing right and handling simulation for another company right now and I know but how what would do difficulties oranges
and so what package of using empire smallest the the basis of this 1 simple idea
is edited these guys who produce some pie they were doing a really really really great job and I would like to
thank you with those people it's a symbolic algebra package so 100 places more than these 3 product and it's on a very it's a right at the moment it's on the advanced level so it's not that you can just through some guided by derivatives so integrals it's it's on the high advanced level and it also includes already you want mechanics so why do not pass all these together so these loose ends together and and produce something which with which you can do all your multiple discrimination so finally we tried to do
this and yeah I
not I would like not to forget these packages it's really
really helpful and maybe the core of numerical and scientific Python programming compliance and and without these it would not happen anything about the of these
foreign linear algebraic so was the username and they're very very worried that once and not forget well tested so with these packages are so well tested that you can trust
and this is good and there are some ODE solvers in some fine the way will so in the end we need some
graphics graphics we did with the Python the price in is that yeah and medium
bonds it's it's really really nice but it's the test primitives called primitive some rocks springs and so on and you can put these together and make all of of these your some of your graphics simulation in fact you need this to make sure that your are assembled equations behave value so just a visual check off your own solutions I mean you cannot just solve your operations and then put some some some graphs and then you cannot judge if this this done really nice so a really good have some visualize them j
now some background theory on the other side to make this short William blocks of from mechanical system and you have your body's everybody has 6 degrees of freedom the translation of patients including the time derivatives you end up with 12 degrees of freedom so each body shirts and leads to uh uh yeah tool to 12th lines in your and system of ordinary differential equations if there wouldn't be some possibilities to boil it down my each of these
bodies has much mass the moment of inertia of intrinsic so this is the figure citation this is not mine this is all some of my figures so either side it's you can't boil down
but you can boil down on the number of degrees of freedom by 2 points joints you can think about these 2 bodies are connected to reinstalling sliding of scarlet color and in fact it's technically done more necessary in each of these joints and can be produced in a technical sense and In the end but this joints you reduce the numbers of degrees of freedom here we
it's just read the except that appear in front front tire can also steer but Monasterevin good so it's a revenue joint these in
these equations appears forces and torques forces and torques accelerates masters so forces most of the time appear pairwise so if 1 body and subtracting another it's it's it's the same done for you for that for the other body so but you have different types of forces pairwise forces so think about son and Earth for example the external forces if you just want to find um a system of government out of a mechanical system on earth you would enter degradation of force of course and you wouldn't include office as an independent and mask but just would at your gravitational field as an ex kind of external forces and the difficult things the constraint forces for example if you have here so affairs and a abortus running on the surface the surface would x the force on the ball to be on surface so
in we divide assimilation will see most many times these kind of and these kind of drawings because these kind of drawings so most of the things included here for example you have a change of bodies and their their yard joints and you can see if you if you switch from Cartesian coordinates to adjust the angle here you can reduce it somehow the number of degrees of freedom nobody will write this down in Cartesian coordinates at an angle so that's you know if the generalized coordinates are minimal it equals the number of degrees of freedom but it is not always the case so you can have more generalized coordinates so you would have on top of it some equations which gives you with the constraints and even the generalized coordinates are not unique so you can for example measured the angle towards the that axis or towards the axis of the previous body so is not at all unique the dataset often corner
uh 1 problem which is really a maybe a domain on the call 1 of the core problems in which a body simulation is this 1 so if you have uh this is called the constrained you if you do not just have a yacht yachts joins but if you have another constraint in the end which yields a constrained you or you can say OK these angles here on top of that are somehow connected to each other they cannot see the cannot be independent at all and this is called constraint you and this constant produces another equation most of the time algebraic equations and as added vibration you can take care of it in the several possibilities to to to solve these kind of problems that most of the time there are dead differential algebraic equation methods but they are very costly and in Python may be too slow so we propose here solution according to the partial 1 with additional job force for
linearization you can always put this like job at the right equation into your answer to the question and here
this is this is the set of methods we can use to make to generate our equations of motion and in this package some pie they produced you already canes method which is also called the principle of function and low-cost methods number 2 evidence patients this and another possible possibility but not used OK so I will show you what how it is used and just needs to spend you're using you just need to have an object which set up your world and just give you of world coordinate system and a market a market is always the coordinate system in the language of antibodies which and there are methods provided to and bodies and markers so extra coordinate systems and external forces extra constraints and for example reflective balls an ODE solver is connected 1 is automatically in a 3 D strategic geographical vector and connected automatically so each each body you signs up in the graphical back and and appears somehow as you want it to be a period I will show you examples later some physical quantities are provided like energy forces velocity and so on you can if and if you what I mean we are inside Python so you can you can calculate what ever you want here and this is this is the advantage new and interesting so uh what what put what did we put into this work we would like to have a completeness of joints and tools and that the Jacobian is calculated for linearization analysis so this is on top of and nice feature of the nice features the linearization toward which is already in some part is kind of completed and you can we can detect automatically independent independent coordinates and so on constraints you our more this kind of solves to external models and parameters can be included as a very important point here the external models which I will show you in 1 example would I We have also some B-splines which can be used if you don't have an analytical expression for the force you can
also include some kind of B-splines for having a representative of the 4th functions so sometimes measurements don't give you analytical expressions OK according size set up the system here is this your your model simulation world you enter bodies democracy forces and your force models to external force model your geometric constraint and
solving sampling and solving this the US Justice 1 here you have maybe use some constant like the gravitational constant you give it a number you produced equations of motion and integrates them processing is calculation of linear analysis of linearizations of stability analysis to prepare and animate your wrist OK if you would like to be developed once in time or if you would like to work with some pie once the time you should be aware of these 3 things I mean you should be be aware of many things but these 3 especially never use empire for numerics and do not try to use for for example to use some prior to solve for the eigenvectors it is it will
never happen that it is it will never be as fast as online so find the the right steps between simple to employ OK so I get assigned for 10 minutes and also I will
hurry and up and land if i is 1 of the core functions of some part I mean if you have an edge of rights expression what
can you do with it and uh in a computer you would like to introduce that as a function and to use it as a function you use this word which is called 95 you 95 expressions into Python functions and this is remote maybe the most impressive in mention here not our from supply and ODE solvers that don't use your own so even if you
if it looks like fun to produce 1 it is not never as good as those which are around and use those we use and audio so I and this is also called sundials maybe if you are interested in these topics
you know did sundials is an open source which is all there but not connected to Python at the moment disconnected but it stopped kind of enterprise and 2 . 6 or so so I would like to really I would like to connect to floor and used to send us all of which is really good my OK
I will show say examples and for his
examples and not
only the picture but also the results movies this could be strike
OK this is bad because knowledge of this here on my screen and not on the screen I wanted it to be a so this is what comes out more this is the crank slide something called prints light and the system this is a simple example for constrained you hear this goes round and round and this goes linearly so this is rotating linear this CV and put in all forces and here and uh extra constraint so so this if you don't put this constraint forces here would be just dependent so I don't
know if I give you a little sigh 11 skip some
of these because they have 12 and this is too much maybe this 1 and yeah some some spring and so reflective walls here it said that this uh um positioned as a reflective for it's interesting because it's not so fluent but I don't know why because it's in the middle of 2 2 screens be here so this is reflective for example that
would show on this 1 this is a simple kind and this is non-trivial and mean maybe you can you can see there's uh that status sampling these equations takes around 60 seconds ago yeah so in these
equations state has come out by this mechanism and this mechanism has told you it was quite easy so we just bodies markers special forces and so on and in the end here this is the steering wheel is in India and India and the existence of studying starting vector so you need starting vectors and India and we just call here came the fife and then these equations are assembled and now it's and 60 seconds something which was of motion and a wise
is non-trivial because there is not only the mechanics which you can see here is also kind of an external model that's a prior model which you plug in and prior models gives you a mean if you if you think about tires and if you think about tires it's a nontrivial external model and I'm working in ground because
dynamics so it matters a lot to plug it into your system nontrivial external models and bigger the nice thing here is that did it as a possible to do this now it's integrating but the have
their own 27 degrees of freedom in fact want to get a not 28 so it's it's OK it's fast it's not real time at the moment but it's fast so it's not about I mean if you would like to make it real time you would have to export its on it in a C or Fortran codes then it would be real time but at this level it does not
but it's OK so but somehow it's a little bit slower don't know why meaning some resources here yeah and I can tell you this we used Pacheco model and particle maybe 1 of the uh some some of you
may know this but you guys so it's a professor on his working on time models and he's really really famous on this in this area of research and tires they are quite interesting to model the cost that's rubble and rapid it's always difficult so for example if you think about and Rolling rolling tyres so uh you all of these sometimes include the no-slip and no slip um constraint but the bias this would never work was highest producing and the longitudinal and vertical force only with slip so you have to include in your calculations some known and you on top of this we have calculated in the and the eigenvalues of the Jacobian so you can see this and now I will I will go into the animation In
this step all of these degrees
of freedom has to keep that in Cartesian coordinates that it works with so now here's let's this is this is
all kind model it looks simple but that's OK and it is in fact moralist fixed on 1 0 so that and this is the sign staring at a simple manner assigned during and but it's nice that it's but it's working working
well can see it's breaking India and here on top I can show you just we have also some outputs calculated for the Tigers special special values for the tires and put this into these and graph OK
so I would give the
examples and goes to a future work what do is the this the last this is
not very but but but and
I was really thought about what make it this as simply a creations persistent is is non-trivial because they understand yeah OK there simply is an hour not
they're quite a complex objects so that ordered view which is marked with which I really like but it's based on a serialization and very complex objects can be serialized this way and then I would like to do is to make it persistent because to skip the Assembly which may take a little bit of time so graphics always some
improvements to be done model validation and testing time compilation is another nice idea to speed up the cost of processing is upon us maybe you you know this package OK so Due to the work completed basic sciences September and for the the simulation so going to to end up with a nice for the assimilation better than that 1 I showed you October and December 1915 and thank you for your attention and I would like to invite you to ask questions thank you very much be it a if
you want all the but you talked about transitioning from symphytum number right to do an American compilations computations is the ultimate that ball from symphytum hard perhaps and and at the moment I'm not aware that they are closely connected and and this is this is a kind of a picture for I think that you have to yeah and except for this land like land defined you need sometimes if you plot the numbers in just a converts your system climate justice to to to nonparametric this 1 by 1 and this is how I did it and this works fine thanks OK so what few
Computer animation
Assembly language
Information
Computer simulation
Backup
Computer font
Computer animation
Variance
Integrated development environment
Backup
Computer simulation
Metropolitan area network
Product (category theory)
Process (computing)
Nichtnewtonsche Flüssigkeit
Software developer
Basis (linear algebra)
Computer simulation
Computer simulation
Independence (probability theory)
Computer animation
Equation
Integrated development environment
Scripting language
Physical system
Metropolitan area network
Multiplication
Constraint (mathematics)
Process (computing)
Assembly language
Forcing (mathematics)
Software developer
Robot
Expression
Auto mechanic
Computer simulation
Branch (computer science)
Computer simulation
Table (information)
Computer animation
Personal digital assistant
Asynchronous Transfer Mode
System dynamics
Metropolitan area network
Computer animation
Computer simulation
Branch (computer science)
Computer simulation
System dynamics
Metropolitan area network
Product (category theory)
INTEGRAL
Moment (mathematics)
Basis (linear algebra)
Auto mechanic
Computer simulation
Symbol table
Derivation (linguistics)
Pi
Process (computing)
Algebra
Computer animation
Energy level
Right angle
Algebra
Metropolitan area network
Computer programming
Numeral (linguistics)
Algebra
Computer animation
Core dump
Computer simulation
Ordinary differential equation
Linear map
Metropolitan area network
Algebra
Computer animation
Ordinary differential equation
Computer simulation
Ordinary differential equation
Computer simulation
Primitive (album)
Bit rate
Computer simulation
Graph (mathematics)
Spring (hydrology)
Spring (hydrology)
Computer animation
Operator (mathematics)
System programming
Equation
Software testing
Cuboid
Moment (mathematics)
Multiplication sign
Auto mechanic
Translation (relic)
Mass
Computer simulation
Theory
Cartesian coordinate system
Derivation (linguistics)
Degrees of freedom (physics and chemistry)
Type theory
Physical system
Metropolitan area network
Block (periodic table)
Point (geometry)
Ordinary differential equation
Mass
Moment of inertia
Line (geometry)
Derivation (linguistics)
Moment of inertia
Computer animation
Figurate number
Block (periodic table)
Boiling point
Physical system
Point (geometry)
Degrees of freedom (physics and chemistry)
Type theory
Computer animation
Graph coloring
Block (periodic table)
Computer simulation
Boiling point
Physical system
Cartesian coordinate system
Number
Metropolitan area network
Logical constant
Computer animation
Data Encryption Standard
Block (periodic table)
Computer simulation
Film editing
Data type
Physical system
Cartesian coordinate system
Force
Multiplication sign
Auto mechanic
Angle
Computer simulation
Number
Degrees of freedom (physics and chemistry)
Mathematics
Torque
Office suite
Subtraction
Physical system
Pairwise comparison
Logical constant
Constraint (mathematics)
Forcing (mathematics)
Surface
Cartesian coordinate system
Position operator
Computer animation
Angle
Personal digital assistant
Equation
Gravitation
Data Encryption Standard
Block (periodic table)
Data type
Physical system
Force
Domain name
Multiplication sign
Computer simulation
Ordinary differential equation
Vibration
Core dump
Loop (music)
Metropolitan area network
Constraint (mathematics)
Algebraic equation
Forcing (mathematics)
Point (geometry)
Propositional formula
Computer simulation
Independence (probability theory)
Port scanner
System call
Process (computing)
Computer animation
Angle
Equation
Linearization
Block (periodic table)
Physical system
Force
Differential algebraic equation
Parameter (computer programming)
Complete metric space
Ordinary differential equation
Computer simulation
Mereology
Food energy
Formal language
Virtual reality
Velocity
Multiplication
Physical system
Metropolitan area network
Simulation
Logical constant
Constraint (mathematics)
Reflection (mathematics)
Point (geometry)
Internet service provider
Computer simulation
Coordinate system
Parameter (computer programming)
Mass
Port scanner
Physical quantity
Functional (mathematics)
Measurement
Front and back ends
Vector space
Linearization
Physical system
Point (geometry)
Set (mathematics)
Mathematical analysis
Number
Frequency
Pi
Thetafunktion
Equations of motion
Representation (politics)
Gamma function
Loop (music)
Linear map
Data type
Forcing (mathematics)
Expression
Mathematical analysis
Ordinary differential equation
Set (mathematics)
Transformation (genetics)
Inclusion map
Jacobi method
Computer animation
Object (grammar)
Force
Metropolitan area network
Process (computing)
Software developer
Multiplication sign
Mathematical analysis
Sampling (statistics)
Computer simulation
Storage area network
Number
Mach's principle
Calculation
Pi
Numeral (linguistics)
Moment of inertia
Computer animation
Equations of motion
Eigenvalues and eigenvectors
Function (mathematics)
Eigenvalues and eigenvectors
Linearization
Regular expression
Physical system
Stability theory
Data type
Metropolitan area network
Software developer
Expression
Ordinary differential equation
Computer simulation
Computer simulation
Mereology
Functional (mathematics)
Storage area network
Tabu search
Word
Computer animation
Function (mathematics)
Core dump
Right angle
Regular expression
Metropolitan area network
Enterprise architecture
Computer animation
Open source
Software developer
Function (mathematics)
Moment (mathematics)
Regular expression
Ordinary differential equation
Icosahedron
Computer simulation
Metropolitan area network
Computer animation
Analog-to-digital converter
Regular expression
Computer simulation
Resultant
Rotation
Linear map
Storage area network
Maxima and minima
Metropolitan area network
Slide rule
Constraint (mathematics)
Roundness (object)
Touchscreen
Computer animation
Forcing (mathematics)
Data acquisition
Physical system
Metropolitan area network
Touchscreen
Spring (hydrology)
Computer animation
Reflection (mathematics)
Data acquisition
Metropolitan area network
Existence
Sine
State of matter
Executive information system
Forcing (mathematics)
Auto mechanic
2 (number)
Computer animation
Vector space
Equation
Statistics
Metropolitan area network
Logical constant
Cloud computing
Computer simulation
Auto mechanic
Cartesian coordinate system
Maxima and minima
Arithmetic mean
Computer animation
Boom (sailing)
Gamma function
Force
Physical system
System dynamics
Metropolitan area network
Logical constant
Moment (mathematics)
Computer simulation
Real-time operating system
Bit
Code
Maxima and minima
Plane (geometry)
Particle system
Degrees of freedom (physics and chemistry)
Sample (statistics)
Computer animation
Pi
Energy level
Code
Gamma function
Force
Newton's law of universal gravitation
Area
Metropolitan area network
Logical constant
Constraint (mathematics)
Eigenvalues and eigenvectors
Set (mathematics)
Forcing (mathematics)
Multiplication sign
Computer simulation
Maxima and minima
Degree (graph theory)
Calculation
Sample (statistics)
Computer animation
Moving average
Key (cryptography)
Gamma function
Uniform space
Force
Metropolitan area network
Sign (mathematics)
Logical constant
Sample (statistics)
Computer animation
Computer simulation
Data Encryption Standard
Key (cryptography)
Gamma function
Force
Variable (mathematics)
Maxima and minima
Metropolitan area network
Computer animation
Function (mathematics)
Alpha (investment)
Uniform space
Metropolitan area network
Logical constant
Computer animation
Maxima and minima
Metropolitan area network
Computer icon
Method of lines
Computer simulation
Storage area network
Maxima and minima
Tabu search
Voting
Computer animation
Analog-to-digital converter
Regular expression
Gamma function
Loop (music)
Metropolitan area network
Standard deviation
Serial port
Process (computing)
Validity (statistics)
View (database)
Multiplication sign
Computer simulation
Bit
Computer simulation
Interface (computing)
Compiler
Computer animation
Software testing
Object (grammar)
Computer animation
Moment (mathematics)
Computer simulation
Right angle
Data conversion
Physical system
Number
Compiler

### Timings

```  671 ms - page object
```

### Version

AV-Portal 3.8.0 (dec2fe8b0ce2e718d55d6f23ab68f0b2424a1f3f)