HOME

Run the latest version of VTVLsim

Posted on 2014-06-23
Comments on reddit hackernews
Tweet this

VTVLsim - v0.1

Video

Introduction

During past couple of years I watched several Youtube videos produced by SpaceX featuring experimental Grasshopper rocket capable of vertical takeoff and landing. Gradually tests demonstrated precise rocket movement becoming more and more graceful and daring each time. I'm cosmist, seeing mankind unearthing the steps for the stairway to the stars. Obviously I am intrigued by the goals SpaceX is trying to achieve in technology and space transportation industry.
I've tracked development and popularization of WebGL since its birth so couple of months ago I decided to make slightly more complex experiment involving JavaScript and WebGL to see how they might perform on various platforms (desktop and mobile) as environment for technical visualization and simulation. I assumed it would be fun educational experience as well.
By using three.js library (to authors: thanks!) I was able to avoid dealing with pure WebGL API. Also there is a lot of usable vector math related code included in this library so I didn't have to reimplement it by myself.
I think that in the future, huge machine-readable libraries of knowledge/code will be available to researchers and engineers for easy inclusion into their projects and AI computer experiments on the web. I'm going to try to modularize products of my experiments in form of independently reusable JavaScript code files so that simple script HTML element inclusion works fine. Later I might need to look into using RequireJS.

Project development principles and trade-offs

Development process (emacs, skewer)

Initially most of the time I used Emacs in combination with skewer-mode. This allows me to update certain functions and variables on-the-fly without full restart of simulation and with full preservation of simulation state. Later I noticed that full page reload is fast enough for quick edit-run cycle.
Influenced by Squeak Smalltalk I created basic in-page JavaScript Object Inspector which can be used to inspect and understand associations between various objects used in simulation. You can traverse complex properties by clicking on property/function name. By hovering cursor over property/function name you will see path expression tooltip. You can drag-and-drop path expression. This is very useful with JavaScript console. You can edit numeric and string values by clicking on them. Boolean values will be toggled. Changed values are persisted on page reload by default. There are few special camera position and orientation properties whose values are saved to local storage every 5s [see Setup.saveState].

Physics

I apologize for purely textual static description of physics that follows. It would be much better to create informative interactive document (inspired by Bret Victor's demonistrations and IPython web notebook [IPY]).
Physics simulation is *very approximate*. It's similar to basic spring-mass system. There are,
Forces distributed to nodes are always balanced according to Newton's Third law of motion. On contact with ground velocity damping coefficient is applied to simulate hydraulic dampeners (on legs).
I did few tests to compare precision of numerical simulation results to analytic solution for simple scenarios (like rocket going directly up). Results are within 0.01%, hopefully good enough for manifestation of interesting phenomena. [see function Tests.testPhysicsSimulationAccuracy1]
I made a guess about rocket mass distribution and placed fuel mass just above engine. For certain simulation scenarios, fuel mass will usually decrease as fuel is being spent for propulsion. I'm not even sure about total mass either. If somebody has more precise numbers, send them to me.
Interaction of rocket with atmosphere (aerodynamics) is not simulated. Everything exists in vacuum.

Thrust control, moving to target location

After basic physics simulation was finished I started to experiment with behavior of directed thrust located at bottom of the rocket. Simulations helped me gain insight and subsequently identify potential approach to implement rudimentary thrust control capable of moving the rocket to target location.
I noticed that the rocket must be tilted towards target location to begin moving in wanted direction. But this tilting must be limited and precisely controlled to avoid fall over of the rocket. By introducing several live monitor graphs that display interesting variables that must be controlled I was able to identify acceptable rules for relation between tilt angle, translational velocity and acceleration/deceleration towards target. No science nor engineering, just tinkering.
Without computer, for each part of thrust vector calculation simulation I would have to think very hard to analytically model all important aspects of the control, but with computer modeling and live simulation feedback I easily understood what needs to be done, what are the next steps, and how they must be constructed. The rudimentary control approach was obvious. This reminds me of Automatic Differentiation kind of algorithm but with a human in the loop.
The rocket always slightly overshoots target location but eventually converges to it. The energy is wasted because of this sub-optimal control system.

Visualization

Red spheres depict point masses. Sphere radius depends on value mass.
White lines depict major rigid connections in frame (body) and legs.

Conclusion

This is obviously toy simulation but experience developing it was very educational, interesting and fun. I have impression that everything on this world is possible to accomplish with planned gradual development. The only question is how fast and with what amount of resources?
VTVLsim might be used as a toy for digital entertainment, or as example in the search for interesting web representations of reusable modular technical simulations and visualization. Who knows, today we are toying with this thing, but in the future some fragments of its code after they get indexed by autonomous web code indexing crawler might be on its way to Mars and further to the stars.
This is definitively work in progress. If anyone has any suggestions for improvement or questions, please send them to me!
Github repo

Big thanks

jQuery three.js sprintf.js

Links

NASA Beginner's Guide to Rockets Grasshopper Merlin 1D Gimbaled thrust

Footnotes

[IPY]: During last two months I began to use IPython web notebook interface with Python kernel very frequently. I need to find similar tool that would execute JavaScript or altJS code (for better technical code notation at least) in the browser (client side only) to support incremental authoring of live composable interactive documents.