Proximity Sensor Problem (I think)

This is where you talk about the RCX software itself, installation issues, and programming talk.

Moderator: roger

Proximity Sensor Problem (I think)

Postby Valastar » Sat May 31, 2008 12:36 am

It's a simple program that is supposed to have the robot rotate, and sense for an object, when it senses it, it simply moves toward it.

I'm having a number of problems, the first of them being that the robot, once it senses something, doesn't move, and remains still. Though it stops in the direction of the object, showing that the sensor indeed is working...

I'm baffled as to why it doesn't move towards the object though...

Here's my code:

Code: Select all
import josx.platform.rcx.Motor;
import josx.platform.rcx.LCD;
import josx.platform.rcx.Sensor;
import josx.platform.rcx.Button;
import josx.platform.rcx.Sound;
import josx.robotics.TimingNavigator;
import josx.platform.rcx.ProximitySensor;


public class Proximity
{
public static void main(String[] args) throws InterruptedException
    {
     
        ProximitySensor ps = new ProximitySensor(Sensor.S2, 30);
       
        Motor.A.setPower(4);
        Motor.C.setPower(4);
       
        Motor.A.forward();
        Motor.C.backward();
       
               
        ps.waitTillNear(0);//Wait for an object to enter range of proximity
       
       
        Sound.twoBeeps();
       
        Motor.C.forward();
        Thread.currentThread().sleep(1000);
     
       
       
}
} // class Proximity
Valastar
New User
 
Posts: 1
Joined: Sat May 31, 2008 12:31 am

Postby JavaMan » Mon Jun 16, 2008 10:55 am

Possibly because the design of your robot prohibits the movement of it using only one motor. I suggest this.
Code: Select all

import josx.platform.rcx.Motor;
import josx.platform.rcx.LCD;
import josx.platform.rcx.Sensor;
import josx.platform.rcx.Button;
import josx.platform.rcx.Sound;
import josx.robotics.TimingNavigator;
import josx.platform.rcx.ProximitySensor;


public class Proximity
{
public static void main(String[] args) throws InterruptedException
    {
     
        ProximitySensor ps = new ProximitySensor(Sensor.S2, 30);
       
        Motor.A.setPower(4);
        Motor.C.setPower(4);
       
        Motor.A.forward();
        Motor.C.backward();
       
               
        ps.waitTillNear(0);//Wait for an object to enter range of proximity
       
       
        Sound.twoBeeps();
       
        Motor.C.forward();
        Motor.A.forward();
        Thread.currentThread().sleep(1000);
       
     
       
       
}
} // class Proximity


Also, 1000 is a short time to sleep, so I suggest you use a touch sensor to tell the bot when to stop driving forward.

Jman
look up and see the chemtrails
www.carnicom.com
User avatar
JavaMan
Novice
 
Posts: 27
Joined: Tue Apr 01, 2008 1:47 pm
Location: United States


Return to RCX Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff