Bringing objects to my Processing simulation

Two years ago I’ve written a post on building an object-oriented multibody structure in Matlab. The project has since been sleeping, but since my experiments with Processing I decided to implement a comparable structure there. This means:

  • A structure that is hopefully easy to expand and modify
  • Code that is running in Java (with the possibility to port it to C++ / Arduino) that should be reasonably fast.
  • A slightly modified approach compared to my original Matlab implementation (in some cases with clear improvements)

This approach allows a very elegant interface for simulation: Adding an object is just one line of code, as is simulating one timestep:

screenshot_MBSim_Processing.png

Continue reading

Advertisements

Interactive multibody dynamics in Processing

Processing is a programming language / IDE built on top of Java that’s intended for simple and visual programming, making it a great tool for WYSIWYS (what you see is what you simulate, actually that is not a real term, I just made it up).

If you’re unsure what Processing is, you might want to check out either the examples on processing.org or the double-pendulum I’ve just built into it. It is a port of my code for Arduino with TFT, but with Processing, it’s cleaner and way nicer to play with!

screenshot_double_pendulum.png

You can find an interactive version of my program here on openprocessing.org. It also includes a general implementation of the Runge-Kutta algorithm for solving ODEs, in case this is needed (without giving any guarantee of correctness or code quality – use on your own risk).

Update 2018-02-11: I’ve just published an updated version that simulates three pendulums in parallel with different algorithms (explicit euler, symplectic euler and runge-kutta). You can find it here.

Real-time simulations on an Arduino (double pendulum)

I got a small display compatible with my Due for christmas. And since I really wanted to see some arduino-in-the-loop simulations, I decided to use it for exactly this: real-time multibody simulations on the Ardunio and the results displayed on the tft.

Continue reading

Speed comparisons for Arduino Uno/Nano, Due and Teensy 3.5

It’s been more than a year since I published my post on numerical integration on an Arduino. Since then, the post has been quite popular, recieving a steady stream of visitors (mostly via Google). When I originally wrote it, I only had an Arduino Uno at hand – since then I’ve added a couple of Nanos and lately an Arduino Due to my inventory and decided it would be interesting to do a couple of speed tests to see how they perform. The latest addition to my growing circus of microcontroller boards is a Teensy 3.5 board.

As I pointed out in the original post, numerical integration relies heavily on floating-point math – which is something the Arduino’s 8-bit processor is not particularly good at. The Due features a 32-bit processor, a clock frequency of 84 instead of 16 MHz and the possibility to use double (64 bit) instead of float (32 bit) as a data type – so I was curious to see how it would compare to the Arduino Uno. The Nano is supposed to have more or less the same characteristics as an Uno, but is a lot smaller and cheaper – see below for details.

Now added to the comparison, the Teensy 3.5 includes a 32-bit processor with 120 MHz clock speed and a FPU for speedier floating-point math.

Continue reading

Object-oriented multibody simulation models in Matlab

What’s better suited for object-oriented programming (OOP) than building a simulation of a physical system? Each physical object (e.g. mass, spring etc.) can be implemented as an object and then we should be able to easily build and modify large models.

However, there are a lot of challenges to get there, including:

  • How to work with classes and objects at all (if you’re like me new to OOP)?
  • How to build a working object structure that adopts to the requirements of a typical ODE solver (which usually requires access to all state variables in the so-called state-space representation)
  • How to design classes for different object types in a way that allows them interact with each other to calculate and transmit forces and accelerations.

Getting there turned out to be quite interesting and I finally got a simple object-oriented multibody model to simulate in Matlab and GNU Octave. This post is a wrapup of all the stuff I learned to get there.

Update: There is now also a newer post I’ve just written on a comparable multibody simulation structure in Processing / Java.

Continue reading

How to solve differential equations on an arduino with the runge-kutta method

This is just a small update on my experiments with the Arduino. I implemented the runge-kutta-method for solving a multibody system a few weeks ago. So this is a working implementation of the standard 4th-order runge-kutta ODE (ordinary differential equations) solver for the arduino platform, something I haven’t seen elsewhere.

(Note: If you are just looking for the arduino sketch, you’ll find a link at the end of this blog post. If you are wondering about related questions or have trouble adopting it to your needs, please leave a comment. Also see this post on how numerical integration of differential equations works.
Update in August 2016: See also my new post on achievable simulation rates with an Arduino Uno/Nano and Due)

My main goal was to get a better grip on simulation speeds. Why is my simulation so slow? is a question I’m really thinking about a lot. Since I wasn’t able to find a good example of an arduino sketch for ODE solving online, this may be interesting anyway.

Continue reading

Viewing friction in dynamics as a hybrid system

It’s been almost a year since I wrote my post on how to model friction in a dynamic multibody system. Since then, I’ve reconsidered my ideas from the post a few times and finally found out that there’s a theory called “hybrid systems” that intersects with the problems described there.

Continue reading