robot and object

Post your NXJ projects, project ideas, etc here!

Moderators: imaqine, 99jonathan, roger

New User
Posts: 15
Joined: Sun Apr 17, 2011 2:43 pm

robot and object

Postby roozis » Fri May 13, 2011 2:47 pm

he there, i need some help with the program, this is my code below that i have so far

Code: Select all

float fMaxSpeed = motor.getMoveMaxSpeed();
     //   motor.backward();

            if(sonic.getDistance() < 30)
                for (int i=0; i< 1; i++)
        catch(Exception e)

what my robot is doing is if the robot is near an object it will turn away from the object and move 30cm away from the object fire at the object, now what i wanted to know is that if the robot was more than 30cm away from the object to move towards the object until it reaches 30 cm from the object and then stop.

can any one just give me a little help cuz im really stuck

leJOS Team Member
Posts: 965
Joined: Mon Feb 05, 2007 1:27 pm

Re: robot and object

Postby lawrie » Sat May 14, 2011 10:38 pm

If you want to find an object, you must search for it.

One way might be to rotate the robot in a complete circle, taking ultrasonic readings until you get a value less than 255, and then move towards the object that gave the reading. If no object is in range, you could move in a random direction, and try again.

Of course, you might not find the object you are looking for. You might find a wall or another object, you are not interested in.

To find a specific object, you need some way to identify it. One way is to look for objects that transmit infared, with a sensor like the HiTechnic IRSeeker. Another way, might be to get close to an object and see what color it is. A camera decice like the Mindsensors NXTCam could be used to detect a colored object.

Return to “NXJ Projects”

Who is online

Users browsing this forum: No registered users and 0 guests