Intro to Javascript

[From Adam Matic (2014.03.28 10.15 cet)]

I was going to make a demo of a two level system, but that turned into a week of partially successful attempts to learn advanced javascript’s design patterns. There is all these constructor functions, modules, revealing modules, function factories… And so much convoluted text written about them. (/end rant)

So, I decided I really like global variables. Here is a simulation of a basic single level control system: http://www.pct-labs.com/basicCS.html

(That’s my website, by the way. No home page yet)

Try changing every slider on the right. If the simulation breaks, just reload the page.

All files can be downloaded from the top domain. File basiccs.js is the javascript code of the simulation. File basiccs.html contains only a

element filled with canvas elements and can be rearranged without effecting functionality of the simulation (for example, instead of a column, the elements can be arranged visually in a loop). The ‘style.css’ is from a website I liked, contains some unnecessary parts.

File 'dat.gui.min.js" is a graphical user interface library that manages the sliders on right side. I liked it because it looks nice and is easy to set up, but it doesn’t appear to be working with touch screens, so it might not be the best choice for future projects. Perhaps they’ll add touch support later, it’s still in development. Here is the website with a tutorial http://workshop.chromeexperiments.com/examples/gui/#1–Basic-Usage

I didn’t comment the code, since it’s short and uncluttered this way, and I tried using self-explanatory variable and function names. I hope it can serve as an intro to making javascript simulations. Shouldn’t be too hard for example, to modify the model into a two-level system and add a few variables to the gui.

Or instead of the sticks moving up and down on the screen, have them rotating around a single point, representing angular position variables. Or add a random disturbance generator… or an ‘automatic play’ button and disturbance control to make the system live and responsive.

···

The main drawback of this approach is that models are still not easy to design for non-programmers, are not interchangeable between users and are not directly comparable. That’s where SimCon will be used. Models need to be designed by visually rearranging elements. The effect of each change in parameters should be instantly visible. Model’s internal structure should be applicable to different kinds of variables - position of a ball in 2D environment or rotation of a cube in 3D environment, or a sound from the speakers… Well, there is much more that ‘should be’, so I’ll stop there.

I found Douglas Crockford’s book “Javascript: the good parts” recommended widely. It’s nice and short. http://books.google.hr/books?id=PXa2bby0oQ0C&printsec=frontcover#v=onepage&q&f=false

A very, very, very useful reference site: http://www.w3schools.com/

Adam

It’s looking funky! When Bill did the live block diagram demo (with Bruce?), there was a diagram of a closes loop with the parameters in the location at which they operate. I found that very helpful as someone naive to all the short hand terms.

Warren

···

Sent from my iPhone

On 28 Mar 2014, at 10:15, Adam Matic adam.matic@GMAIL.COM wrote:

[From Adam Matic (2014.03.28 10.15 cet)]

I was going to make a demo of a two level system, but that turned into a week of partially successful attempts to learn advanced javascript’s design patterns. There is all these constructor functions, modules, revealing modules, function factories… And so much convoluted text written about them. (/end rant)

So, I decided I really like global variables. Here is a simulation of a basic single level control system: http://www.pct-labs.com/basicCS.html

(That’s my website, by the way. No home page yet)

Try changing every slider on the right. If the simulation breaks, just reload the page.

All files can be downloaded from the top domain. File basiccs.js is the javascript code of the simulation. File basiccs.html contains only a

element filled with canvas elements and can be rearranged without effecting functionality of the simulation (for example, instead of a column, the elements can be arranged visually in a loop). The ‘style.css’ is from a website I liked, contains some unnecessary parts.

File 'dat.gui.min.js" is a graphical user interface library that manages the sliders on right side. I liked it because it looks nice and is easy to set up, but it doesn’t appear to be working with touch screens, so it might not be the best choice for future projects. Perhaps they’ll add touch support later, it’s still in development. Here is the website with a tutorial http://workshop.chromeexperiments.com/examples/gui/#1–Basic-Usage

I didn’t comment the code, since it’s short and uncluttered this way, and I tried using self-explanatory variable and function names. I hope it can serve as an intro to making javascript simulations. Shouldn’t be too hard for example, to modify the model into a two-level system and add a few variables to the gui.

Or instead of the sticks moving up and down on the screen, have them rotating around a single point, representing angular position variables. Or add a random disturbance generator… or an ‘automatic play’ button and disturbance control to make the system live and responsive.


The main drawback of this approach is that models are still not easy to design for non-programmers, are not interchangeable between users and are not directly comparable. That’s where SimCon will be used. Models need to be designed by visually rearranging elements. The effect of each change in parameters should be instantly visible. Model’s internal structure should be applicable to different kinds of variables - position of a ball in 2D environment or rotation of a cube in 3D environment, or a sound from the speakers… Well, there is much more that ‘should be’, so I’ll stop there.

I found Douglas Crockford’s book “Javascript: the good parts” recommended widely. It’s nice and short. http://books.google.hr/books?id=PXa2bby0oQ0C&printsec=frontcover#v=onepage&q&f=false

A very, very, very useful reference site: http://www.w3schools.com/

Adam

Yeah, I agree, it would be much nicer if the parameters would be changed right on the diagram where they operate, and if the diagram was arranged as a control loop. I was looking into different GUI libraries and sliders for changing the parameters and I’m still not sure which one will be appropriate, but something that works in most browsers.

Adam

···

On Fri, Mar 28, 2014 at 11:39 AM, Warren Mansell wmansell@gmail.com wrote:

It’s looking funky! When Bill did the live block diagram demo (with Bruce?), there was a diagram of a closes loop with the parameters in the location at which they operate. I found that very helpful as someone naive to all the short hand terms.

Warren

Sent from my iPhone

On 28 Mar 2014, at 10:15, Adam Matic adam.matic@GMAIL.COM wrote:

[From Adam Matic (2014.03.28 10.15 cet)]

I was going to make a demo of a two level system, but that turned into a week of partially successful attempts to learn advanced javascript’s design patterns. There is all these constructor functions, modules, revealing modules, function factories… And so much convoluted text written about them. (/end rant)

So, I decided I really like global variables. Here is a simulation of a basic single level control system: http://www.pct-labs.com/basicCS.html

(That’s my website, by the way. No home page yet)

Try changing every slider on the right. If the simulation breaks, just reload the page.

All files can be downloaded from the top domain. File basiccs.js is the javascript code of the simulation. File basiccs.html contains only a

element filled with canvas elements and can be rearranged without effecting functionality of the simulation (for example, instead of a column, the elements can be arranged visually in a loop). The ‘style.css’ is from a website I liked, contains some unnecessary parts.

File 'dat.gui.min.js" is a graphical user interface library that manages the sliders on right side. I liked it because it looks nice and is easy to set up, but it doesn’t appear to be working with touch screens, so it might not be the best choice for future projects. Perhaps they’ll add touch support later, it’s still in development. Here is the website with a tutorial http://workshop.chromeexperiments.com/examples/gui/#1–Basic-Usage

I didn’t comment the code, since it’s short and uncluttered this way, and I tried using self-explanatory variable and function names. I hope it can serve as an intro to making javascript simulations. Shouldn’t be too hard for example, to modify the model into a two-level system and add a few variables to the gui.

Or instead of the sticks moving up and down on the screen, have them rotating around a single point, representing angular position variables. Or add a random disturbance generator… or an ‘automatic play’ button and disturbance control to make the system live and responsive.


The main drawback of this approach is that models are still not easy to design for non-programmers, are not interchangeable between users and are not directly comparable. That’s where SimCon will be used. Models need to be designed by visually rearranging elements. The effect of each change in parameters should be instantly visible. Model’s internal structure should be applicable to different kinds of variables - position of a ball in 2D environment or rotation of a cube in 3D environment, or a sound from the speakers… Well, there is much more that ‘should be’, so I’ll stop there.

I found Douglas Crockford’s book “Javascript: the good parts” recommended widely. It’s nice and short. http://books.google.hr/books?id=PXa2bby0oQ0C&printsec=frontcover#v=onepage&q&f=false

A very, very, very useful reference site: http://www.w3schools.com/

Adam

[From Bruce Abbott (2014.03.28.0835 EDT)]

Adam Matic (2014.03.28 10.15 cet)]

AM: I was going to make a demo of a two level system, but that turned into a week of partially successful attempts to learn advanced javascript’s design patterns. There is all these constructor functions, modules, revealing modules, function factories… And so much convoluted text written about them. (/end rant)

BA: Thanks for persisting. I know from personal experience how frustrating it can be to learn how to use such things. They don’t always work as expected!

AM: So, I decided I really like global variables. Here is a simulation of a basic single level control system: http://www.pct-labs.com/basicCS.html

(That’s my website, by the way. No home page yet)

AM: Try changing every slider on the right. If the simulation breaks, just reload the page.

BA: That’s an excellent start. Is the simulation supposed to run in real time? I only see movement when changing a parameter value or dragging the “playerindex” slider.

AM: All files can be downloaded from the top domain. File basiccs.js is the javascript code of the simulation. File basiccs.html contains only a

element filled with canvas elements and can be rearranged without effecting functionality of the simulation (for example, instead of a column, the elements can be arranged visually in a loop). The ‘style.css’ is from a website I liked, contains some unnecessary parts.

AM: File 'dat.gui.min.js" is a graphical user interface library that manages the sliders on right side. I liked it because it looks nice and is easy to set up, but it doesn’t appear to be working with touch screens, so it might not be the best choice for future projects. Perhaps they’ll add touch support later, it’s still in development. Here is the website with a tutorial http://workshop.chromeexperiments.com/examples/gui/#1–Basic-Usage

AM: I didn’t comment the code, since it’s short and uncluttered this way, and I tried using self-explanatory variable and function names. I hope it can serve as an intro to making javascript simulations. Shouldn’t be too hard for example, to modify the model into a two-level system and add a few variables to the gui.

Or instead of the sticks moving up and down on the screen, have them rotating around a single point, representing angular position variables. Or add a random disturbance generator… or an ‘automatic play’ button and disturbance control to make the system live and responsive.

BA: The Javascript syntax looks like an object-oriented version of the C language, (as does Processing). I didn’t have any trouble following what the code in basics.js does, but I’ve had plenty of exposure to object-oriented programming.

···

AM: The main drawback of this approach is that models are still not easy to design for non-programmers, are not interchangeable between users and are not directly comparable. That’s where SimCon will be used. Models need to be designed by visually rearranging elements. The effect of each change in parameters should be instantly visible. Model’s internal structure should be applicable to different kinds of variables - position of a ball in 2D environment or rotation of a cube in 3D environment, or a sound from the speakers… Well, there is much more that ‘should be’, so I’ll stop there.

BA: Have you seen Vensim? It allows you to create a diagram with components representing flows (of variables and signals), quantities, etc. And the run it as a simulation. A definite plus is that it includes sophisticated procedures for doing integration, etc. accurately. Apparently there is now a free version available online “for evaluation and educational use,” see https://www.shodor.org/tutorials/vensim/pre.php .

AM: I found Douglas Crockford’s book “Javascript: the good parts” recommended widely. It’s nice and short. http://books.google.hr/books?id=PXa2bby0oQ0C&printsec=frontcover#v=onepage&q&f=false

AM: A very, very, very useful reference site: http://www.w3schools.com/

BA: Thanks, Adam, much appreciated!

Bruce

[From Adam Matic (2014.03.28 1430 cet)]

BA: That’s an excellent start. Is the simulation supposed to run in real time? I only see movement when changing a parameter value or dragging the “playerindex” slider.

AM:
No real time simulation yet, only fast time. Changing any of the parameters on the GUI recalculates the whole simulation, and the 'playerIndex' just goes over it.
I considered adding a real-time 'live' mode, that would be fun. To be able to set reference and disturbance values in real time, and have them graphed, like in the Live Block Demo

BA: The Javascript syntax looks like an object-oriented version of the C language, (as does Processing). I didn’t have any trouble following what the code in basics.js does, but I’ve had plenty of exposure to object-oriented programming.

AM:
Yeah, looks like OOP. Watch out for pointers to functions, those are weird at first, but very useful.

BA: Have you seen Vensim? It allows you to create a diagram with components representing flows (of variables and signals), quantities, etc. And the run it as a simulation. A definite plus is that it includes sophisticated procedures for doing integration, etc. accurately. Apparently there is now a free version available online “for evaluation and educational use,” see <https://www.shodor.org/tutorials/vensim/pre.php&gt;https://www.shodor.org/tutorials/vensim/pre.php .

AM:
I've downloaded several of the analog circuit simulators of the SPICE variety, and there are online tools like the Circuit lab. There is also "DESIRE" by Granino A. Korn, author of Electronic Analog Computers book that Bill mentioned. There is the modern, free and open source SciLab recommend by control engineers.
I can't say I'm a fan. They are certainly useful to some people, but for me, there's too many options and elements to choose from, they are big and cluttered. The biggest pain is that they lack connection to some kind of a 'world'. If you want to simulate something with realistic physics, you really need to understand the physics of it. That is one reason I like robotics - the physics part takes care of it self, I just program the control part.
In recent years there was some amazing work on physics engines, mostly driven by game developers, and I'm hoping to find a way way of connecting control systems design with 2D and 3D environments with relatively realistic physics, and all that in the browser, so people could see it and feel what happens instantly.
There are great tools to do that naively on a desktop, such as the free Microsoft Robotics Simulator or V-Rep studio: <http://www.coppeliarobotics.com/&gt;http://www.coppeliarobotics.com/ Wonderful thing, very fun, but also too many options and models and scripts and ways to control the robot. I made an inverse pendulum in V-Rep, it kinda worked, but never as stable as I wanted it.

Adam

[From Rick Marken (2014.03.30.0625)}

Just testing to see if the list is still working. They made some
changes to it, apparently, onMarch 28 and I posted something earlier
and go no acknowledgement.

···

On Fri, Mar 28, 2014 at 6:24 AM, Adam Matic <adam.matic@gmail.com> wrote:

[From Adam Matic (2014.03.28 1430 cet)]

BA: That's an excellent start. Is the simulation supposed to run in real
time? I only see movement when changing a parameter value or dragging the
"playerindex" slider.

AM:
No real time simulation yet, only fast time. Changing any of the parameters
on the GUI recalculates the whole simulation, and the 'playerIndex' just
goes over it.

I considered adding a real-time 'live' mode, that would be fun. To be able
to set reference and disturbance values in real time, and have them graphed,
like in the Live Block Demo

BA: The Javascript syntax looks like an object-oriented version of the C
language, (as does Processing). I didn't have any trouble following what
the code in basics.js does, but I've had plenty of exposure to
object-oriented programming.

AM:
Yeah, looks like OOP. Watch out for pointers to functions, those are weird
at first, but very useful.

BA: Have you seen Vensim? It allows you to create a diagram with
components representing flows (of variables and signals), quantities, etc.
And the run it as a simulation. A definite plus is that it includes
sophisticated procedures for doing integration, etc. accurately. Apparently
there is now a free version available online "for evaluation and educational
use," see https://www.shodor.org/tutorials/vensim/pre.php .

AM:
I've downloaded several of the analog circuit simulators of the SPICE
variety, and there are online tools like the Circuit lab. There is also
"DESIRE" by Granino A. Korn, author of Electronic Analog Computers book that
Bill mentioned. There is the modern, free and open source SciLab recommend
by control engineers.

I can't say I'm a fan. They are certainly useful to some people, but for me,
there's too many options and elements to choose from, they are big and
cluttered. The biggest pain is that they lack connection to some kind of a
'world'. If you want to simulate something with realistic physics, you
really need to understand the physics of it. That is one reason I like
robotics - the physics part takes care of it self, I just program the
control part.

In recent years there was some amazing work on physics engines, mostly
driven by game developers, and I'm hoping to find a way way of connecting
control systems design with 2D and 3D environments with relatively realistic
physics, and all that in the browser, so people could see it and feel what
happens instantly.

There are great tools to do that naively on a desktop, such as the free
Microsoft Robotics Simulator or V-Rep studio:
http://www.coppeliarobotics.com/ Wonderful thing, very fun, but also too
many options and models and scripts and ways to control the robot. I made an
inverse pendulum in V-Rep, it kinda worked, but never as stable as I wanted
it.

Adam

--
Richard S. Marken PhD
www.mindreadings.com

It is difficult to get a man to understand something, when his salary
depends upon his not understanding it. -- Upton Sinclair

[From Adam Matic (2014.3.31.1620 cet]

Hi Rick,

I see the testing post, but not the post from March 28. I think I have the same problem with a post from March 29.

Adam

···

On Mon, Mar 31, 2014 at 3:25 AM, Richard Marken rsmarken@gmail.com wrote:

[From Rick Marken (2014.03.30.0625)}

Just testing to see if the list is still working. They made some

changes to it, apparently, onMarch 28 and I posted something earlier

and go no acknowledgement.

On Fri, Mar 28, 2014 at 6:24 AM, Adam Matic adam.matic@gmail.com wrote:

[From Adam Matic (2014.03.28 1430 cet)]

BA: That’s an excellent start. Is the simulation supposed to run in real

time? I only see movement when changing a parameter value or dragging the

“playerindex” slider.

AM:

No real time simulation yet, only fast time. Changing any of the parameters

on the GUI recalculates the whole simulation, and the ‘playerIndex’ just

goes over it.

I considered adding a real-time ‘live’ mode, that would be fun. To be able

to set reference and disturbance values in real time, and have them graphed,

like in the Live Block Demo

BA: The Javascript syntax looks like an object-oriented version of the C

language, (as does Processing). I didn’t have any trouble following what

the code in basics.js does, but I’ve had plenty of exposure to

object-oriented programming.

AM:

Yeah, looks like OOP. Watch out for pointers to functions, those are weird

at first, but very useful.

BA: Have you seen Vensim? It allows you to create a diagram with

components representing flows (of variables and signals), quantities, etc.

And the run it as a simulation. A definite plus is that it includes

sophisticated procedures for doing integration, etc. accurately. Apparently

there is now a free version available online "for evaluation and educational

use," see https://www.shodor.org/tutorials/vensim/pre.php .

AM:

I’ve downloaded several of the analog circuit simulators of the SPICE

variety, and there are online tools like the Circuit lab. There is also

“DESIRE” by Granino A. Korn, author of Electronic Analog Computers book that

Bill mentioned. There is the modern, free and open source SciLab recommend

by control engineers.

I can’t say I’m a fan. They are certainly useful to some people, but for me,

there’s too many options and elements to choose from, they are big and

cluttered. The biggest pain is that they lack connection to some kind of a

‘world’. If you want to simulate something with realistic physics, you

really need to understand the physics of it. That is one reason I like

robotics - the physics part takes care of it self, I just program the

control part.

In recent years there was some amazing work on physics engines, mostly

driven by game developers, and I’m hoping to find a way way of connecting

control systems design with 2D and 3D environments with relatively realistic

physics, and all that in the browser, so people could see it and feel what

happens instantly.

There are great tools to do that naively on a desktop, such as the free

Microsoft Robotics Simulator or V-Rep studio:

http://www.coppeliarobotics.com/ Wonderful thing, very fun, but also too

many options and models and scripts and ways to control the robot. I made an

inverse pendulum in V-Rep, it kinda worked, but never as stable as I wanted

it.

Adam

Richard S. Marken PhD

www.mindreadings.com

It is difficult to get a man to understand something, when his salary

depends upon his not understanding it. – Upton Sinclair