Distance Sensor Issues

We are having issues with our distance sensor. We want to turn until we see an object less and 15 inches away. Frequently, the robot stops at 30 inches… reading objects farther away.

1 Like

Sorry to hear that you and your students are having issues. In order to help you better, I do have a couple questions.

  • What is the intention of the project here? (I know we talked about Castle Crasher in our previous 1 on 1 Session, so is this still what you are working towards?)
  • Can you please send me a picture of the build so I can see the placement of the sensor? That can frequently impact the project.

Thanks!

1 Like

I students are searching for “radioactive” elements in a cave and recoding the type and number on their Brain console. They are searching for colored cubes and recording findings on their robots brain. The recording data on the brain console is working fine. Using the distance sensor to search for an object and then approach it within 4 inches and then to use the optical sensor to detect color. Sometimes the distance sensor finds an object less than 15 inches away (using wait/until) and most of the time it detects objects 72 inches away… I did use the castle crasher program. The distance sensor does not work right… even thought when I have it write the distance of an object on the console it is right.

1 Like

Thanks for that explanation.

As I read through your code, I think I see where there may be issues. Now this may need adjustments to better work in your classroom but I want to try and talk through each behavior intended to explain.

Searching for colored cubes

Currently, the project seems to have the robot turn for a specific distance based on its initial sensor reading. I don’t think that is necessary, and you can instead instruct the robot to turn right until the object is detected, or a particular distance away. Like this

Something else to consider is that the 2nd generation Distance Sensor’s Field of View is narrow but extends fairly far, so be sure that the space in front of the sensor is clear of any other objects that could be interfering (like a Field Wall, or even a student or a bookshelf in the classroom)

Driving to the colored cube

I think this part of the project will work well. The “Turn right for 15 degrees” might be something that you can remove because of the removal of that first “turn right for distance degrees” block. Then the Distance Sensor will remain head on to the object detected (the cubes) and can print the color to the Brain screen.

If you remove those two blocks, I am guessing this will be closer to the final goal of the project. Please let me know if this helps or it still isnt working as intended.

1 Like

Thanks, for some reason the distance sensor was magically working the next day and we have had not issues… even the code you gave me we tried when the sensor was not working… all is now well

3 Likes

I’m glad it’s working now @Maria_Brinza! Please let us know if you need any additional help :slight_smile:

1 Like