Duration of activity: 3 hours Participants: Nick, Allan and Jens Chr.
The goal of this session is to explore how the Ultrasonic sensor works. This will be done by first measuring distances to a static point, e.g. a wall, to see how accurate the sensor is. After this experiment we will make a robot that is able to follow a wall.
The distance experiment (Ultrasonic sensor)
To setup this experiment we put a large ruler in front of a table that was tilted. This way we were able measure the distance to the table by placing the robot, or actually the ultrasonic sensor, at certain distances from the table.
The first set of measurements are made 15cm apart, meaning 15cm, 30cm, 45cm, etc. from the table. The result of these measurements can be seen of the graph as the red line. Almost all readings from this set where 1-3cm off, which in this first go seems fair*. But by looking at the experiment setup, we realized that the table wasn't totally vertical and was tilting a bit. This had the implication that the table wasn't orthogonal with the floor, but had an angle of 90+ degrees (seen from the robot's perspective), and hence the distance that ruler showed might not be correct.
This error was corrected by raising the bottom of the table legs. Then we measured the distances once more. This can be seen as the yellow line in the graph. The readings where quite accurate between 0 and 240cm from the table. After 240cm the sensor gave out readings that were a bit shorter than the actual, physical distance.
The theoretical max. distance that be measured is 254cm, as 255 should be interpreted as 255+ cm. This physical distance from the table was 257 cm when the sensor measured 254 as output value. We tried using a different surface, a pillow instead of imitated wood, but without luck – the readings where either the same as before or for some bizarre reason sometimes 255 even though the sensor was within the limit of 254cm (or in this environment 257cm!).
According to the documentation the ultrasonic sensor waits approximately 20 milliseconds in continuous mode for return of the sound-wave. This means that the sensor has a reach of approximately 6.80 meters when taking the speed of sound into account.
* as the documentation for the ultrasonic sensor states that the accuracy of the sensor is +/-3cm[Lego].
The wall following robot
To build a wall following robot we used the standart Lego robot/car that we used for following a black line on the floor, but instead of the light sensor we placed an ultrasonic sensor on the side of the robot/car. The ultrasonic sensor was placed orthogonally to the driving direction. The main idea of this placement of the sensor was to detect whether the robot of getting too close or too far from the desired distance to the wall.
The software is designed after an sequential principal, as the Tracker Beam project, given in the exercise.
For the program to work, the robot must have the wall on the right side compared to the driving direction. Then, at specific intervals, the robot measured the distance to the wall. If the distance is too close it lowers the speed on the motor driving the left wheel, making the robot turn left and hence away from the wall, and vice versa if the robot is too far from the wall.
The above mentioned program was too aggresive, and made the robot sometimes turn too much and therefore drove into the wall. To help this problem we made the turns less aggresive, so the turns were more smooth. Besides this, we also introduced a clause that made robot not turn if the distance from the wall was close to the desired distance. This setup gave slightly faster and much more gracefully moving robot.
public class FollowWall{public static void main (String[] aArg)throws Exception{UltrasonicSensor us = new UltrasonicSensor(SensorPort.S1);final int noObject = 255;int distance,desiredDistance = 25, // cmpower = 80,minPower = 70;float error, gain = 0.5f;LCD.drawString("Distance: ", 0, 1);LCD.drawString("Power: ", 0, 2);while (! Button.ESCAPE.isPressed()){distance = us.getDistance();if ( distance != noObject ){error = distance - desiredDistance;if ( Math.abs(error) <>
Car.forward(power, power);}else if ( error > 0 ) //Right - to high{Car.forward(power,minPower);LCD.drawString("right ", 0, 3);}else //Left - to low{Car.forward(minPower, power);LCD.drawString("left ", 0, 3);}LCD.drawInt(distance,4,10,1);LCD.drawInt(power, 4,10,2);}elseCar.forward(power, 0); //turn around one selfThread.sleep(100);}Car.stop();LCD.clear();LCD.drawString("Program stopped", 0, 0);Thread.sleep(2000);}}
Ingen kommentarer:
Send en kommentar