[ODE] Laser range finder
Shamyl Zakariya
shamyl at zakariya.net
Mon Sep 20 10:03:31 MST 2004
Also, depending on how "real world" you want your laser range finder to
behave you might want to take into account the angle which the ray hits
whatever it hits.
What I mean is, real range finders tend to get less accurate as the
intersection angle goes away from perpendicular.
In my simulator, I use this angle to add a random error quotient, so
the reported distance gets noisier the farther from perpendicular the
intersection becomes.
dContactGeom contact;
if ( dCollide( _rayGeom, geom, 1, &contact, sizeof(dContactGeom)) > 0 )
{
if ( contact.depth < _distance )
{
_contactPos[0] = contact.pos[0];
_contactPos[1] = contact.pos[1];
_contactPos[2] = contact.pos[2];
_contactPos[3] = contact.pos[3];
_distance = contact.depth;
/*
now calculate dot product of ray to intersection against
the normal of the surface ray intersects. This will be
used to influence the error calculations.
*/
dVector3 start, dir;
dGeomRayGet( _rayGeom, start, dir );
dVector3 toStart = { start[0] - _contactPos[0],
start[1] - _contactPos[1],
start[2] - _contactPos[2] };
normalize( toStart );
_contactDotProduct = dDOT( toStart, contact.normal );
}
}
Then, later on when I query the distance,
/*
otherwise, we need to calculate a psuedorandom error
First, generate an error quotient from -1 to 1, influenced
by incidence of ray intersection to target. Where the error
increases as the ray intersection deviates from perpendicular.
*/
dReal error = (( 1.0 - _contactDotProduct ) * 2 *
( ((dReal) (random() % 1000)) / 1000.0 )) - 0.5;
/*
Now scale the error up based on how far away the intersection is.
*/
dist += error * ( dist / max ) * _error;
if ( dist >= max ) dist = max;
Also, since the range finders I'm emulating have a max range, I cap it
if it's too far.
Anyhow, I hope this helps...
On Sep 19, 2004, at 6:34 PM, John Miles wrote:
>
>> To paraphrase the documentation (did you search for "ray" ?)
>>
>> 1) create a dRay geom
>> 2) set the position and direction appropriately using the dRay
>> functions
>> 3) set the length to be the total size of your world
>> 4) run dSpaceCollide2() to collide your ray against the world
>> 5) the contact you get back from within dCollide has a "depth"
>> value which is the length of the ray to the contact -- remember,
>> and use, the smallest depth returned
>
> FYI, be careful using really-long rays with the dTerrainY/Z
> contributions.
> If you fire a ray at an angle that the terrain collider doesn't
> trivially
> reject (e.g., 45 degrees from just above the center of a world to a
> point
> beneath one of its corners) , performance suffers greatly compared to
> an
> orthogonal ray, or a shorter one.
>
> Or, that may be a general property of the quadtree space, for all I
> know. I
> didn't investigate.
>
> The other thing about rays is that they "miss" trimeshes if they
> happen to
> strike an edge.
>
> -- jm
>
> _______________________________________________
> ODE mailing list
> ODE at q12.org
> http://q12.org/mailman/listinfo/ode
>
More information about the ODE
mailing list