Box-in-box Dynamic Simulation
September 2023 - December 2023, Northwestern-MSR
This a project about simulating dynamic system with multiple objects and collisions between them.
- Dynamic simulation in 2D with impact between 2 objects
- Programmatically generate equations and lambda functions for 20 collision pair with minimal manual coding.
- Visualization and animate the system working using plotly.
The project uses sympy for symbolic equation generation, and numpy for numerically solving and simulating.
The general steps are:
- Use sympy to define and solve for the euler lagrange of the system, with mass, inertia, gravity, and external force
- Generate lambda function for each object in the system from equations of last step.
- Use sympy to construct the collision equations for each pair of collision objects (vertex and edge)
- Create lambda function for collision updates and collision checking
- Construct a simulation function that takes all the lambda function from above, simulate it at discrete time step and integrate object’s motion.
- Collect object’s dynamic data over simulation and generate plots and animations.
The simulation is done using Runge-Kutta method. The integration basically takes pose and velocity and gives out new pose after delta time. However our dynamic systems equations are second order with acceleration. Thus a state function technique is used. By widen the state variables to include velocity, the systems equation is dropped down to first order, which is then solvable.
There are 20 collision pairs, between each vertex of inner box and edge of outter box, and between vertex of outter box and ground. There will be lots of repeated work when defining the impact update and impact check lambdas. Thus some helper function are created, only the impact condition (phi) is defined for each pair, then everything is generated in while loops.