Results 1 to 3 of 3
  1. #1
    roozis is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default help with the program

    im trying to program a lejos nxt robot and i want to make the robot move untill it senses a wall and when it senses the wall it stops and turns away from the wall.

    this is the code that i have done at the moment, can any one tell me what is wrong with it.


    PHP Code:
     public void jStart() {
    
            float fMaxSpeed = pilot.getMoveMaxSpeed();
            pilot.setMoveSpeed(fMaxSpeed);
            pilot.backward();
    
              int distance = UltrasonicSensor.getDistance();
              if (distance < 23) {  
    
            while (distance < 23)
        {
               
             try
             {
            pilot.backward();        
            Thread.sleep(200);
            pilot.rotate(-180);
            Thread.sleep(200);
    
            }
             catch (InterruptedException e)
             {
                return;
             }
        }
           }
    
        }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default

    If you want to do it this way (as opposed to an event driven approach), think about it the other way around- you want the robot to move while the distance is GREATER than 23, then you want it to do something else.

    By the way, what are you using to program the NXTs in Java? I've been experimenting with lejos myself.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    roozis is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default

    awww ok i will try it, and im using netbeans, i thought of trying using it to improve my skills.

    thank you for the tip

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  2. Replies: 13
    Last Post: 03-22-2011, 06:49 AM
  3. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •