Find the closest object
- Place a few objects at varying distances to the robot.
- Have the robot spin around in-place 360 degrees so that it can see all the objects.
- Have the robot locate the closest object.
- Then move forward towards to object.
- Stop near the object without knocking into it.
- You will need to use Loops, Switches to help design the flow of your program.
- You will need variables to do comparisons to compare the closest object found to the current object seen,
- First draw on paper a flow chart so you see the steps involved.
- Once you have the steps involved, now you can use the computer to write out your program.
- You may find things simpler, if you use My Blocks to organize your code.
- A variable is used to have the closest object found.
- You can initalize that to the current reading of the ultrasonic sensor before the robot moves. This will be the default of the closest object. You will need a loop to have the robot check the ultrasonic sensor and compare this with the closest object.
- Once the robot has made a 360 degree sweep of the room, you will have found the closest object. Now sweep the room again and locate an object of the appoximate distance to the closest object. This is because the sensor may not give the exact reading next time. So something within 5cm + or - the previous reading is fine. Just make sure the objects you place are of varing distnaces.
- Once you have located the object, now move forward towards the object and stop about 20cm it.