Turn when obstacles are present?

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Turn when obstacles are present?

Postby pjn » Mon May 31, 2010 11:54 am

How is this done? Presumably using the Ultrasoinc Sensor. Anyone got an example of any code?
pjn
New User
 
Posts: 5
Joined: Tue May 25, 2010 11:57 am

Postby xpansive » Mon May 31, 2010 11:26 pm

Its pretty easy, first you need to create a UltrasonicSensor instance:
Code: Select all
UltrasonicSensor US = new UltrasonicSensor(SensorPort.S4); // Sensor port 4

then do
Code: Select all
somevariable = US.getDistance();

to get the distance.

From there you can make the motors move differently depending on the distance. If you need help with motors, a good tutorial is here: http://lejos.sourceforge.net/nxt/nxj/tu ... Motors.htm

Hope it helps!
xpansive
New User
 
Posts: 7
Joined: Wed May 19, 2010 11:23 pm

Postby pjn » Tue Jun 01, 2010 1:51 pm

Many thanks for that.

The first part of that works, but then when I goto use the second part, it simply gives an error saying "Cannot Find Symbol". Do I also need to declare the variable somewhere else or?
pjn
New User
 
Posts: 5
Joined: Tue May 25, 2010 11:57 am

Postby pjn » Tue Jun 01, 2010 2:13 pm

Ignore my last post, was me being stupid.

Thanks again for your help.
pjn
New User
 
Posts: 5
Joined: Tue May 25, 2010 11:57 am


Return to NXJ Projects

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

more stuff