Pattern recognition using the VEX ultrasonic sensor for autonomous robot operation.

Original Title (which was too long):
Pattern recognition using the VEX ultrasonic sensor for autonomous robot operation.

Hello everyone, here are some ideas on pattern recognition that I hope you’ll enjoy.

As I’m sure you know, the VEX ultrasonic sensor returns a number between 0 and 99 depending on the distance to the object. However, there are a lot of things that can impact the accuracy of any ultrasonic sensor, including the size of the object being detected, the hardness and shape of its surface, and even the temperature of the air. Having worked with others in the past, I can say the VEX product is as good as any for the price and probably better than most.

Given that all ultrasonic sensors do not really give accurate, reliable or consistent measurements, how can you use them to help a robot navigate its surroundings?

Turns out it’s not that hard to do.

So the purpose here is to answer that question and hopefully start some interest in building autonomous or semi-autonomous robots.

Hardware description.
I mounted the VEX ultrasonic sensor on a large 84-tooth gear using gussets. This is then mounted on a servo allowing the sensor to be rotated about 180 degrees. The idea is to be able to take a series of measurements as the servo moves from the left to the right and then back again. The chassis is the really just a larger, two motor squarebot with 4” wheels. The robot operates by: take a reading, calculate a direction, move, stop, and then repeat. I’ll post some photos – look for the title ‘echo_auto_botx’.

Software Overview
The code saves the ultrasonic measurements in an array called echodata[2][16]. It saves the first 16 measurements (left to right) in row 0 of the array and the last 16 measurements (right to left) in row 1. We end up with a total of 32 measurements, and the sensor is positioned in the correct location to start again next time. The code offsets the measurements about 5 units on the 0-255 range of the servo so it gets 2 measurements for about the same location during the rotation, but not exactly.

Data Analysis
Now we use some simple math to analyze the data for patterns. At this point, it would be helpful to download the spreadsheet called ‘Vex Ultrasonic Pattern Recognition’. Its in the zip file called autov9.zip a couple of posts down below.

On the first tab of the spreadsheet, you’ll see some diagrams that correspond to the readings you would expect to see if you took ultrasonic readings in specific situations. The names of each pattern correspond to the shape of the resulting graph on the right. For example, an m-curve represents the kind of data you would expect to see if the robot was in a room with an object in its path. The graph is shaped like the letter M. The others are also easy to understand.

Okay, we got this far. So now what? Well if you click on the second tab in the spreadsheet, you’ll see some simple formulas that compute mean averages and then compare these means in groups of 4 or 8 to determine if the data is mesa, m-curve or skewed. Once you have these averages, it’s really just a matter of comparing the computed values to each other to arrive at a conclusion.

For example to identify the m curve use:

If ( ( means[0] < means[1]) && (means[3] < means[2]) && (means[6] < means[1]) && (means[6] <means[2]) )
{
mcurve = 1
}

I know it looks confusing, but its very simple logic. It’s basically saying: if the middle is less than the outside, and the ends drop down again, then this pattern is true. Paste the various mockup data sets on sheet 1 into the green area on sheet 2. Follow the logic and you’ll start to see how simple this really is.

From this point you can start to combine things. For example if you get a mesa pattern and a skew left, you know you can go forward with a slight jog to the left.

It’s also a good idea to screen the data for any low numbers. If you get a reading less than 15, then you should probably add some logic to move in the opposite direction.

The only other thing I like to keep track of is an encoder. In a short, just reset the encoder before each move and then check it after the motors stop. If the encoder did not increment much, then you know it ran into something – so its time to go the other way. It’s just that easy!

I hope you’ll enjoy this and please share your ideas in this thread. There is a lot more you can add to this basic code to increase the robot’s abilities. But then again, you can only do so much with no ALU and only 32K of space.

(I think I included links to the spreadsheet and the code in this post. If not, well, I may need to go read the instructions again or ask for help.)

KHall.

wow, good job, you’ve obviously spent some time working on this

the spreadsheet did not attach please click manage attachments under the “Additional Options” when posting → i believe that should work

BTW: I suggest editing the title of your post as with the added Re: it is too long (past 87 characters)

Can’t get the attachment to work at the moment. I zipped the speadsheet and the code into a single .zip file that is 38K. I know zip is an allowed file type and its not over any size limits.

Might be due to the long title. It uploads just fine, then I get “Attachment in Progress. Can be deleted here.” When I click on that its says “Thread: Post: «N/A»”. When I click on the <<N/A>> I get: “No Thread specified. If you followed a valid link, please notify the administrator”.

So I guess its not a valid link.

hmm id just host it externally, or email/PM anyone that wants it

Attachments include the spreadsheet and the EasyC code. Enjoy.
autoV9.zip (37.3 KB)