Count current velocity of geom for ABS

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

Count current velocity of geom for ABS

Postby hiltropper » Mon Dec 20, 2010 12:26 pm

hi
i am new at this forum and i can not guarantee a perfect english ;)

my problem :
im working on an anti blocking system (ABS we call it in germany) that controlls the wheels of a car.
everything works but one thing could be better : I change a scene.my.var with onlaserhit AND now what i want: the fade dist of this laser should have the same value as the speed of the car.so i thought i point with another laser at one geom from my car and let it count its current velocity on hit by this one laser and this current vel is equal to scene.my.var2 (that would be the fade dist of the ABS laser). -> If you drive fast , long dist ,if you dont move no (or in real very minimal) dist .
how is it possible to count the current velocity?
thanks for help!
yup yup
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
hiltropper
 
Posts: 85
Joined: Mon Dec 20, 2010 12:02 pm
Location: Germany

Re: Count current velocity of geom for ABS

Postby Rideg » Tue Dec 21, 2010 12:55 pm

Just to make this clear for me. Do you want the speed or the velocity (velocity = [x, y]; speed = x)
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: Count current velocity of geom for ABS

Postby hiltropper » Tue Dec 21, 2010 7:16 pm

velocity would be better (for driving on a slope)
yup yup
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
hiltropper
 
Posts: 85
Joined: Mon Dec 20, 2010 12:02 pm
Location: Germany

Re: Count current velocity of geom for ABS

Postby Rideg » Wed Dec 22, 2010 3:41 pm

Make a box and a laser. (laser hits to the box)

This code will get you the velocity of your mouse cursor but you can make a box + laser on the car and in the box's onHitByLaser you type: (e)=>{scene.my.carpos = e.pos}

Then you can replace all app.mousePos with scene.my.carpos

Code: Select all
(e)=>{
    scene.my.vel = (app.mousePos - [color(0), color(1)]) / (sim.time - color(2));
    color = [app.mousePos(0), app.mousePos(1), sim.time, 0.6]
}


Hope it was what you were looking for ;)

-Johan
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: Count current velocity of geom for ABS

Postby hiltropper » Wed Dec 22, 2010 7:25 pm

thanks , its working! :thumbup:
final script
Code: Select all
(e)=>{
    scene.my.carpos = e.pos;
    scene.my.vel = (scene.my.carpos - [color(0), color(1)]) / (sim.time - color(2));
    color = [scene.my.carpos(0), scene.my.carpos(1), sim.time, 0.6]
}


but why has it something to do with the color? :?:
its not really important but if you could explain it in short sentences it were nice

one last thing : would you please explain to me how to express an amount in algodoo ( i just know the way to write it " |x| " )
i only need the keys to write that in algodoo nothing else maybe you know.
thank you so far ;)
yup yup
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
hiltropper
 
Posts: 85
Joined: Mon Dec 20, 2010 12:02 pm
Location: Germany

Re: Count current velocity of geom for ABS

Postby KarateBrot » Thu Dec 23, 2010 10:45 am

it has nothing to do with the color. he just used the color array to store data. the geometry does change the color over time but if you hide it it won't matter. instead you could also use another variable/array which you or your object doesn't need or you could make arrays for position and time + a variable for velocity. it's just a matter of taste
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Count current velocity of geom for ABS

Postby hiltropper » Thu Dec 23, 2010 3:57 pm

Du bist aus Deutschland ? Kannst du mir sagen wie ich in algodoo einen Betrag ( |x| ) ausdrücken kann ? :mrgreen:
Das mit dem color dachte ich mir schon weil der sich die ganze Zeit geändert hat.
i already thought the color saved a value for a moment i just wondered why espacially the color has been taken for this.
yup yup
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
hiltropper
 
Posts: 85
Joined: Mon Dec 20, 2010 12:02 pm
Location: Germany

Re: Count current velocity of geom for ABS

Postby KarateBrot » Wed Dec 29, 2010 12:28 pm

ja da machste einfach eine funktion dafür. wenn du etwas zum quadrat nimmst wird es immer positiv. dann nur noch die wurzel ziehen um wieder den ausgangswert zu haben.
öffne die konsole (F11) und deklariere eine neue funktion

Code: Select all
scene.my.betrag := (x) => { (x^2)^0.5 }


dann kannst du die funktion in deiner szene für alles verwenden. du schme9ßt einen wert in die funktion und bekommst den betrag raus. zum beispiel:
Code: Select all
scene.my.betrag(-3)
scene.my.betrag(irgendnevariable)

das kannst du auch in der konsole testen. das mach ich zumindest oft bevor ich was irgendwo in algodoo einprogrammiere.

- - - - -

i just explained how to make an absolute function
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Count current velocity of geom for ABS

Postby kilebantick » Wed Dec 29, 2010 12:49 pm

Good job Karate ;)
Image
User avatar
kilebantick
 
Posts: 1267
Joined: Tue Sep 01, 2009 9:50 am

Re: Count current velocity of geom for ABS

Postby hiltropper » Tue Jan 04, 2011 1:44 am

gut funktioniert ,danke-
everything clear :thumbup:
thanks!
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 3 guests