Get the distanz

Post your EV3 projects, project ideas, etc here!

Moderators: roger, gloomyandy, skoehler

Get the distanz

Postby Londi » Fri Mar 28, 2014 7:15 pm

Hello,
Is it possible to get the distanz from the IR Sensor to an object?



"If the distanz is to small, then stop motors..."
User avatar
Londi
New User
 
Posts: 16
Joined: Sun Mar 23, 2014 12:22 am

Re: Get the distanz

Postby lawrie » Fri Mar 28, 2014 8:25 pm

Yes, of course. The EV3BumperCar sample does it for example.

You do something like:

Code: Select all
 
float [] sample = new float[ir.sampleSize()];
ir.fetchSample(sample, 0);
float distance = sample[0];
if (distance < MIN_DISTANCE) {
   leftMotor.stop(true);
   rightMotor.stop(true);
}
lawrie
leJOS Team Member
 
Posts: 909
Joined: Mon Feb 05, 2007 1:27 pm

Re: Get the distanz

Postby Londi » Tue Apr 08, 2014 4:30 pm

thank you!
User avatar
Londi
New User
 
Posts: 16
Joined: Sun Mar 23, 2014 12:22 am


Return to EV3 Projects

Who is online

Users browsing this forum: No registered users and 0 guests

cron
more stuff