Close

Simulating Needle Physics

A project log for Rack Mount MIDI Meters

Eight small colour screens display MIDI data, in a 1U rack format

tom-dowadTom Dowad 05/17/2022 at 20:350 Comments

There was some interest in the skeuomorph aspect of this project. That is, new tech simulating old. So I reckoned I might as well follow that thread. I got some new PNG images on order, inspired by vintage meters. And I reckoned I might as well get the needles moving in a way that is more realistic, ie simulating physics.

Maker [sjm4306] did it in this project:

https://hackaday.io/project/181004-digital-vu-meter-with-analog-physics

I had a look at the code for that project. While I'm sure its quite accurate, I couldn't get my head around the PI method used. But I did pick up something from this implementation: that physics only required a few lines of code.

I didn't really understand how one of these meters worked either. So I went to Youtube, what else? This video was helpful:

I knew about the spring and the magnet, but I was surprised to learn about the damper, and how it was implemented. I could see the hard stops on each end. I had certainly "pinned" one of these needles in my day, but never seen the inner mechanics of it.

I was just about to jump into writing C code, then realized it might not be as easy as imagined. I often write code in Xojo, a VB-like language, for testing algorithms. Its fast, inputting values is easy, and it has a good debugger. VB is, like most languages, similar to C.  And it was only a half-dozen lines of code.

Here is the code I settled on:

It is not the definitive physics simulation, but I am happy enough with the results.

Here is the simulation running:

Sorry its just a screen capture and no voice over. I will do better...next time.

The PULL setting is meant to simulate the amount of force applied by the spring (to the left) and the magnet (to the right). As it is increased, the needle moves faster. If set to 0.0 the needle won’t move at all.

The DAMPING setting is meant to simulate the damper, which is a drag on the needle movement and slows it down. In the code its as a multiplier on the velocity. If set to 1.0, the needle will oscillate, forever apparently. If set to 0.0, the needle will not move.

The VALUE setting only changes on mouse button release, not when dragging the slider. You’ll see when it changes as there is a numeric field up top.

Toward the end of the video I move the slider to minimum and maximum positions. Look for the needle bouncing off of the hard stops on either end.

I’ll get this algorithm into the rack unit shortly.

Discussions