Ultrasonic sensor problem

This is where you talk about the NXJ hardware related topics such as the brick, sensors, LEGO pieces, etc.

Moderators: 99jonathan, roger, imaqine

Ultrasonic sensor problem

Postby fjux » Tue Dec 22, 2009 11:29 pm

hello everyone,

for a school project we recieved the NXT robot, and i was trying some stuff. so i put on LeJos since with the NXT software it is harder/ weird way.

though i got the motors + touch sensor working, it moves around correctly,

though now i added the ultrasonic sensor. and i just cant get it to work.
it keeps stuck at 255. it isnt changing.

i tryed the following things:

- tryed al ports (i know 4 doesnt work for this)

- downloaded a new classes.jar from a earlyer post (more aimed @ the light sensor)

- checked if it was not the screen wich was showing wrong values

- tryed the older firmware (8.0) got 8.5

though this all didnt have any effect.
does anyone know what i am doing wrong? it worked fine with the NXT firmware.

thanks in advance[/list]
fjux
New User
 
Posts: 2
Joined: Tue Dec 22, 2009 11:18 pm

Postby gloomyandy » Wed Dec 23, 2009 9:15 am

What code are you using to test the sensor?

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3643
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby fjux » Wed Dec 23, 2009 4:46 pm

i've tryed serveral,
all with same result:

Code: Select all
public class SonicTest {
   
   public static void main(String[] args) throws Exception {
      UltrasonicSensor sonic = new UltrasonicSensor(SensorPort.S1);
      
      while(!Button.ESCAPE.isPressed()) {
         LCD.clear();
         LCD.drawString(sonic.getVersion(), 0, 0);
         LCD.drawString(sonic.getProductID(), 0, 1);
         LCD.drawString(sonic.getSensorType(), 0, 2);
         Thread.sleep(200);
         LCD.drawInt(sonic.getDistance(), 0, 3);
         LCD.refresh();
         Thread.sleep(500);
      }
   }   
}


Code: Select all

public void Gedrukt(){
      while(!Button.ESCAPE.isPressed()){
                     
         
         if(sonic.getDistance() < 5){
            
            try {
               Thread.sleep(1000);
            } catch (InterruptedException e) {
               // TODO Auto-generated catch block
               
            }
         
         }
         LCD.clear();
         LCD.drawInt(sonic.getDistance(), 0, 3);
         LCD.refresh();
         try {
            Thread.sleep(100);
         } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            
         }
         
      }
      
   }



and from the view.java:

Code: Select all
if (sensor == 6) // Ultrasonic
            {
               UltrasonicSensor sonar = new UltrasonicSensor(SensorPort.PORTS[portId]);
               
               while (!Button.ESCAPE.isPressed())
               {
                  LCD.drawInt(sonar.getDistance(), 3, 7, 4);
                  
                  LCD.refresh();
                  Thread.sleep(100);
               }
            }
            Button.ESCAPE.waitForPressAndRelease();


all of these returned 255.

i also tryed to let it wait for 5 sec befor showing but still 255.
fjux
New User
 
Posts: 2
Joined: Tue Dec 22, 2009 11:18 pm

Postby gloomyandy » Wed Dec 23, 2009 5:14 pm

Hi,
Well the code looks fine. So a few more questions and things for you to try...
1. How are you building your test code? I would suggest that you use the command line tools nxjc and nxj (or nxjlink) to do this rather then Eclipse or some other IDE. That way we can be sure you are using the correct classes.jar.
2. When you went back to 0.8, did you remove 0.85 and then install 0.8 and rebuild your test program (if you used Eclipse to build it, please try again with the command line tools).
3. When you tried the updated classes.jar, are you sure your replaced all copies of that file (there is more than one). Again please use the command line tools to build things

The only things I can suggest are that you try...
1. Use a different cable.
2. Try new batteries.
3. Re-install the Lego firmware and try it again... (using the same cable and port), if this works try switching back to leJOS and test it again...

I'm pretty sure that if there was something generally wrong with leJOS and the ultrasonic sensor we would be seeing a lot more posts about it. I know that it works fine with the four sensors I have...
Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3643
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby gloomyandy » Sun Dec 27, 2009 10:59 am

You may also ant to take a look at the following thread:
viewtopic.php?t=1883

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3643
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to NXJ Hardware

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff