Giter Club home page Giter Club logo

numpy-pendulum's Introduction

banner image

Pendulum Simulation

Here I've implemented a 3D multi-link, rigid-body pendulum simulation from the Newton-Euler equations of motion, using explicit Euler integration, rotational damping, and Baumgarte stabilization of the hinge constraints. 1-8 links are combined into a single matrix representing the linear system of motion and constraints, which is solved using Numpy's linalg.solve function. The link's 3D rotations are stored and manipulated using quaternions.

An optional ground collision plane is placed at y=0 - press 'p' to toggle this on and off. Pendulums with < 3 links are too short to hit this! (Add links by pressing '+')

Instructions

Requires:

  • Python (I use 3.5)
  • Numpy
  • Pyquaternion
  • PyOpenGL
  • PyOpenGL-accelerate
  • Matplotlib

Run: python sim.py [-t|--track]

Options:

  • -t/--track: Enable energy tracking

Controls:

  • 'r' : reset the simulation
  • 'SPACE' : toggle pause
  • 'p' : toggle ground plane
  • '+' : add a link - up to 8
  • '-' : remove a link - minimum 1
  • 's' : plot energy over time (requires tracking)
  • 'q/ESC' : quit

Plotting

Pressing the 's' key during a tracked (--track command line option) simulation pops up a plot for the simulation's energy over time. This isn't interactive right now, but it gives an idea of how accurate the simulation is (not very!), and shows how kinetic and potential energy are traded off against one another.

Energy plot for fairly highly damped single-link pendulum:

energy plot

Energy plot for 5-link pendulum colliding with ground plane, which was then removed:

energy plot

Energy plot showing underdamped 8-link pendulum's energy accumulation (physically inaccurate):

energy plot

numpy-pendulum's People

Contributors

alishug avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

thales-sac

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.