jes notes Index Gallery . 4th axis Blog ideas Micro-machining CNC milling machine Paint colours CNC Router Shaft passers Software ideas Stepper motor clock Toy ideas Watchmaking

2024-04-28

Last modified: 2024-04-28 21:47:46

< 2024-04-27 2024-04-29 >

Deadbeat escapement simulator

I've been reading more Goodrich, and his explanation of laying out a deadbeat escapement is quite clear. I am once again motivated to try to make an escapement simulator. But I'd rather not fight Matter.js again, so I'm going to use one of the JavaScript Box2D ports, which Luke Wallin suggested to me.

Which Box2D JavaScript library should I use?

https://github.com/piqnt/planck.js has the most github stars so let's start there.

Plan is maybe:

  1. make a pendulum
  2. make the rest of the escapement?

If I can get a pendulum working tonight I shall be pleased.

I'm following the "script tag" instructions on https://piqnt.com/planck.js/docs/install to try to get planck-with-testbed.min.js. It works if I literally copy and paste the example, but if I download planck-with-testbed.min.js from jsDelivr and try to load it locally it doesn't work, either from a file:/// URL ot with SimpleHTTPServer. Does it need to be loaded over https? Nope, if I host it under [https://incoherency.co.uk/](https://incoherency.co.uk/`) it still doesn't work.

The error I'm getting is Uncaught TypeError: t is null at planck-with-testbed.min.js:38. So what is it about jsDelivr that is making it work?

Oh! It's actually not jsDelivr. It's that if I write

<script src="..."></script>

then it doesn't work, but if I write:

<script src="..." />

then it does. Wtf?

Is it actually working? Maybe it doesn't work anyway but the /> form hides the error message?

I think the latter. If I put a console.log in my code it doesn't even execute that.

I've reported an issue on github: https://github.com/piqnt/planck.js/issues/276

OK, figured it, it's because it assumes the existence of some HTML elements that it hasn't created.

Woo, got a working pendulum:

< 2024-04-27 2024-04-29 >