Acceleration measuring

About advanced scenes, and the Thyme scripting language used in Algodoo.

Acceleration measuring

Postby KarateBrot » Fri Oct 28, 2011 12:33 am

Now that we have direct access to every object's velocity via readable(owner)).vel we can make an acceleration sensor in just 1 minute.

Open your console (F10) and declare some variables. Type in
Code: Select all
scene.my.acc := [0,0];
scene.my.vel1 : [0,0];
scene.my.time1 := 0;


Now to let the following code refresh itself put it eg. into controllerAcc in the object's script menu:
Code: Select all
{
    scene.my.acc = ((readable(owner)).vel - scene.my.vel1) / (sim.time - scene.my.time1);
    scene.my.time1 = sim.time;
    scene.my.vel1 = (readable(owner)).vel;
    11.000000
}


I really like it. I always wanted to have direct access to position and velocity because now practically there is no error while measuring.

Oh and don't worry when your acceleration variable displays [NaN, NaN] after stopping the simulation. The cause for this is simple. The code refreshes even if the simulation isn't running. So time doesn't fly by, meaning the difference between two timesteps is 0. So velocity's difference will be divided by zero. But as soon as you start the simulation again it will calculate properly again.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Acceleration measuring

Postby daniels220 » Fri Oct 28, 2011 3:24 am

Note that as of 2.0.1 beta, that you can embed this on an object without scene.my.* variables, and it will save.

You would go to the top of the script menu for that object, where there's a text field, and type:

Code: Select all
_acc := [0,0];
_vel1 := [0,0];
_time1 := 0;


Then modify the second codeblock to use those variable names.

Unfortunately you can't just put the dynamic variable directly on _acc, it doesn't seem to update all the time like it's supposed to. Still, your workaround of using ControllerAcc or whatever works just fine.
daniels220
 
Posts: 95
Joined: Mon Aug 31, 2009 11:30 pm

Re: Acceleration measuring

Postby KarateBrot » Fri Oct 28, 2011 3:35 am

yep i know. i forgot to say that so thanks for mentioning!
i often need the velocity or something else of an object in the global scope so i'm nearly always using scene.my. variables.

about the update thingy... did you try using (_acc) instead? i don't have 2.0.1 yet so i can't try that out.

edit:
i downloaded 2.0.1 but don't know what you mean. i tried it with _acc and it updates properly :wtf:

edit2:
oh okay i get it. i know what you mean
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Acceleration measuring

Postby daniels220 » Sat Oct 29, 2011 2:44 am

Just to be clear (especially for anyone else reading the thread...):

Code: Select all
_acc := {//code that calculates acceleration}


doesn't work.

Code: Select all
controllerAcc := {_acc = ... }


does.
daniels220
 
Posts: 95
Joined: Mon Aug 31, 2009 11:30 pm

Re: Acceleration measuring

Postby silversmart » Tue Nov 01, 2011 12:05 pm

its great.... i like it... thank you karatebrot...
now i (and maybe other persons) can measure the speed without kilinchis k1probe...
i send you a scene in skype. with a little question... ^^

best regards bluebravo


btw i use algodoo 2.0.0
silversmart
 
Posts: 27
Joined: Tue Jul 05, 2011 7:48 pm

Re: Acceleration measuring

Postby KarateBrot » Tue Nov 01, 2011 1:02 pm

well actually it's nothing special or new it's just the normal formula you can find in every physics book^^ i just wanted to post it because i like the precision of the values and the minimal amount of time you need to create it.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Acceleration measuring

Postby hiltropper » Tue Nov 01, 2011 9:28 pm

how do i adress "owner" ? is it the entity ID or should i type in e.this ?
thanks for answers
yup yup
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
hiltropper
 
Posts: 85
Joined: Mon Dec 20, 2010 12:02 pm
Location: Germany

Re: Acceleration measuring

Postby Matten » Tue Nov 01, 2011 9:50 pm

hiltropper wrote:how do i adress "owner" ? is it the entity ID or should i type in e.this ?
thanks for answers

If you want to know the position of for example a box, you should use something like:
Code: Select all
scene.my.pos := (readable(owner)). pos

I think you can also use other words than owner, but I don't know them. In the newest beta version of Algodoo you can also get info from object by using the geom ID by using something like:
Code: Select all
scene.my.pos := (Scene.geomByID(31)).pos

Where the geom ID is 31 in this example.
Cave Johnson wrote:Do you know who I am? I'm the man who's gonna burn your house down! With the lemons! I'm gonna get my engineers to invent a combustible lemon that burns your house down!
User avatar
Matten
 
Posts: 435
Joined: Mon Apr 05, 2010 2:03 pm
Location: The Netherlands

Re: Acceleration measuring

Postby hiltropper » Tue Nov 01, 2011 10:08 pm

ok , i thought "owner" was just for the example above :D thank you
yup yup
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
hiltropper
 
Posts: 85
Joined: Mon Dec 20, 2010 12:02 pm
Location: Germany


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 6 guests