Calculate distance using laser

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

Calculate distance using laser

Postby rod_igo » Tue Nov 10, 2009 7:10 am

Hi all, I'm trying to calculate the current height of a flying vehicle I'm making, and i'd like to do it with lasers.
I've tried to calculate the distance between the laser and the laser hit (on the ground, using a vertical laser), but I can only get e.pos(1), and that's the laser position, not the collision position.

How can I get the collision position, instead os the laser pos, OR another and better method to get that distance?
Image
User avatar
rod_igo
 
Posts: 5
Joined: Tue Nov 10, 2009 7:04 am

Re: Calculate distance using laser

Postby KarateBrot » Tue Nov 10, 2009 1:46 pm

That's no problem. Just let a second laser collide with a geometry exactly at the position of the first laser or anywhere else you want to define your car's position.
btw. e.pos shows at which position the laser is colliding with something. so it doesn't give you the position of the laser. e.pos is a vector and because of that you can call it's x and it's y value. e.pos(0) is the x value and e.pos(1) is the y value.

open the console and type
scene.my.laser1pos = [0,0]
scene.my.laser2pos = [0,0]
scene.my.height = { scene.my.laser2pos(1) - scene.my.laser1pos(1) }

For the first laser you put this into it's onLaserHit:
Code: Select all
scene.my.laser1pos = e.pos


For the second laser:
Code: Select all
scene.my.laser2pos = e.pos


and now scene.my.height always calculates the height between car and ground. You can visualize it by typing something into the scripting menu of a box. next to "text =" you type:
Code: Select all
{"" + scene.my.height}


and now your height will be displayed in that box.

[Edit]
I forgot to say:
In the scripting menu of the lasers turn down "maxRays" to 1 so that the lasers won't be reflected on the surface. It prevents that the lasers collide with other objects after they collided with the ground.
Last edited by KarateBrot on Wed Nov 11, 2009 3:27 am, edited 1 time in total.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Calculate distance using laser

Postby algadoodle123 » Tue Nov 10, 2009 4:53 pm

my altimeter...

Rating: rated 5
Filesize: 299.99 kB
Comments: 0
Ratings: 1
download


can replace gear with laser
made with phun
codes may not be the same in algodoo

the box on the left displays the number of meters between the BOTTOM of the probe and the plane

just this basic idea

the box displays the number of meters betwwen the "airplane" and the "sea-level"(or 0)
**/\ /\
>( ' ; ' )<***<---------- cat
*((")("))
i'm right-side-up
uʍop-ǝpısdn ɯ,ı
http://www.sherv.net/flip.html
User avatar
algadoodle123
 
Posts: 66
Joined: Tue Sep 08, 2009 6:04 pm

Re: Calculate distance using laser

Postby KarateBrot » Tue Nov 10, 2009 8:12 pm

algadoodle123 wrote:codes may not be the same in algodoo


the scripting language in phun is the same in algodoo so every scripting command that's working in phun is working in algodoo, too.
Your altimeter only measures the height above sea level but not the height above the ground. I know it's not possible in Phun to detect the height above the ground because there are no lasers. Maybe I'm wrong but it sounds like rod_igo want's to know this.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Calculate distance using laser

Postby davidz40 » Tue Nov 10, 2009 9:16 pm

It is possibly possible to do it without lasers, by spawning circles, shooting them down and recording their position when they collide with ground.
Phundamentalist
User avatar
davidz40
 
Posts: 438
Joined: Sun Sep 06, 2009 10:30 am

Re: Calculate distance using laser

Postby KarateBrot » Tue Nov 10, 2009 10:15 pm

davidz40 wrote:It is possibly possible to do it without lasers, by spawning circles, shooting them down and recording their position when they collide with ground.


hmm yeah but then the height value won't be the actual real time height
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Calculate distance using laser

Postby algadoodle123 » Wed Nov 11, 2009 2:45 am

KarateBrot wrote:the scripting language in phun is the same in algodoo so every scripting command that's working in phun is working in algodoo, too.


i know they changed at least some codes... i've seen it on the forums before

KarateBrot wrote:Your altimeter only measures the height above sea level but not the height above the ground.


if he wants to measure how high he is, the lasers could instead give him how high he is above the "mountain" below him. if you want to have the ground set at a different level than sea level, than you change the code
Code: Select all
(e)=>{scene.my.height=((e.pos(1)-"whatever the difference is between the probe and the bottom of the aircraft")-"whatever the difference is between the ground and sea level")}
**/\ /\
>( ' ; ' )<***<---------- cat
*((")("))
i'm right-side-up
uʍop-ǝpısdn ɯ,ı
http://www.sherv.net/flip.html
User avatar
algadoodle123
 
Posts: 66
Joined: Tue Sep 08, 2009 6:04 pm

Re: Calculate distance using laser

Postby KarateBrot » Wed Nov 11, 2009 3:11 am

algadoodle123 wrote:i know they changed at least some codes... i've seen it on the forums before

yeah, they changed some codes and added new ones but the changed ones have nearly nothing to do with "normal" scripting. it's more concerned with the settings of the physics engine.


algadoodle123 wrote:if he wants to measure how high he is, the lasers could instead give him how high he is above the "mountain" below him. if you want to have the ground set at a different level than sea level, than you change the code

that's what i described above but with a little less circumstantial formula but it doesn't need onCollide to calculate the height.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Calculate distance using laser

Postby fox11trot » Wed Nov 11, 2009 4:53 am

use this

Rating: rated 5
Filesize: 9.99 kB
Comments: 2
Ratings: 1
download
fox11trot
 
Posts: 62
Joined: Tue Sep 01, 2009 7:25 am

Re: Calculate distance using laser

Postby rod_igo » Wed Nov 11, 2009 12:41 pm

if he wants to measure how high he is, the lasers could instead give him how high he is above the "mountain" below him. if you want to have the ground set at a different level than sea level, than you change the code
Code: Select all
(e)=>{scene.my.height=((e.pos(1)-"whatever the difference is between the probe and the bottom of the aircraft")-"whatever the difference is between the ground and sea level")}


Yeees, that's exactly what I want. Thanks guys, I actually already got it.

I'm making a Landspeeder that always stays hovering 1m above the ground.

Now I'll figure how to stabilize it and calculate the angle of the ground to stabilize it at the same angle. :D
Image
User avatar
rod_igo
 
Posts: 5
Joined: Tue Nov 10, 2009 7:04 am

Re: Calculate distance using laser

Postby KarateBrot » Wed Nov 11, 2009 6:04 pm

rod_igo wrote:Now I'll figure how to stabilize it and calculate the angle of the ground to stabilize it at the same angle. :D

yeah i did something similar but it's a car instead of a hovercraft. didn't upload it because it was just for fun when i was bored :D
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Calculate distance using laser

Postby izacque » Sun Nov 29, 2009 2:55 am

rod_igo wrote:
if he wants to measure how high he is, the lasers could instead give him how high he is above the "mountain" below him. if you want to have the ground set at a different level than sea level, than you change the code
Code: Select all
(e)=>{scene.my.height=((e.pos(1)-"whatever the difference is between the probe and the bottom of the aircraft")-"whatever the difference is between the ground and sea level")}


Yeees, that's exactly what I want. Thanks guys, I actually already got it.

I'm making a Landspeeder that always stays hovering 1m above the ground.

Now I'll figure how to stabilize it and calculate the angle of the ground to stabilize it at the same angle. :D


to calculate the angle of the ground, you could have a sensor in the front and the back to get the different heights, then use slope formula.
[/post]
Paradigm 29 wrote:I've been trying to figure out why people even buy hummers ever since I found out that they don't have machine guns.
User avatar
izacque
 
Posts: 483
Joined: Mon Sep 14, 2009 11:14 am

Re: Calculate distance using laser

Postby jessebax129 » Wed Apr 07, 2010 9:57 pm

well look:

if you only want to calculate the height of the plane you should make a laser and but it on the airplane and type in it's onlaserhit script:
Code: Select all
(e)=>{scene.my.hit1 = e.pos}

and than declear it with a box with text or so:
Code: Select all
{"" + scene.my.hit1}


OR: if you want to calculate te distance between 2 objects: make 2 lasers (1 on the airplane and onlaserhit (e)=>{scene.my.hit2 = e.pos})
IMPORTANT!!:: the other laser on the other object (like a car or so) and fill in that onlaserhit:
Code: Select all
(e)=>{scene.my.hit1 = e.pos; scene.my.distance1= (((scene.my.hit2(0) - scene.my.hit1(0)) ^2) + ((scene.my.hit2(1) - scene.my.hit1(1)) ^2))


that will calculate the full distance between the 2 objects :thumbup: :clap:
jessebax129
 
Posts: 34
Joined: Tue Jan 05, 2010 6:32 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 10 guests