Ultrasonic Sensor Not Working?
Ultrasonic Sensor Not Working?
I'm trying to make a simple robot that drives around a room without running in to obstacles by using its ultrasonic sensor but the sensor is giving me completely random readings. When I have it only print out its readings on the LCD screen it seems to work well but when I use it in my program the robot will do anything from run straight into a wall to stop 4ft in front of it. Is there anything wrong with my sensor and if so, what can I do?
Re: Ultrasonic Sensor Not Working?
Hi there,
It might help if you gave us a look at your program. Maybe it's something unrelated to the sensor that is causing this erratic behaviour
- Xander
It might help if you gave us a look at your program. Maybe it's something unrelated to the sensor that is causing this erratic behaviour
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
Re: Ultrasonic Sensor Not Working?
I thought of that but my code seemed pretty straight forward. Here it is though, maybe I missed something...
Code: Select all
package rover;
import lejos.nxt.*;
import lejos.robotics.navigation.*;
public class Rover {
static UltrasonicSensor us = new UltrasonicSensor(SensorPort.S4);
static DifferentialPilot sc = new DifferentialPilot(5.6F, 13F, Motor.C, Motor.A, true);
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
sc.setTravelSpeed(700);
sc.backward();
while(!Button.ESCAPE.isPressed()){
if (us.getDistance() < 45){
sc.stop();
}
}
}
}
Re: Ultrasonic Sensor Not Working?
I wrapped your code in some code tags like this:
[/code]
You should do that next time you paste it into a post, makes a lot more readable
As for your code, I am not all that familiar with Lejos, but you're right, there doesn't seem to be anything really weird there. What are you bouncing the US off? Is it a hard or soft surface?
- Xander
Code: Select all
[code]
your code
You should do that next time you paste it into a post, makes a lot more readable
As for your code, I am not all that familiar with Lejos, but you're right, there doesn't seem to be anything really weird there. What are you bouncing the US off? Is it a hard or soft surface?
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
Re: Ultrasonic Sensor Not Working?
Ok I'll try that with the code from now on, thanks.
At first I was just testing using my hand in front of the sensor but I also tried running it up to some hard wood furniture and they both would give the same random results.
At first I was just testing using my hand in front of the sensor but I also tried running it up to some hard wood furniture and they both would give the same random results.
Who is online
Users browsing this forum: No registered users and 0 guests