If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[RESOLVED] Displaying data graphically (Ultrasonic radar)

Hi all, a beginner here
I'm working on an ultrasonic sonar and I would like to use the computer to display a standard green radar system detecting the objects.
I'm using a micro controller with the software written in C to send out the sensor's angle and position and it works fine.
On the computer side, I'm using Visual Basic 2010 to read the COM port which then contains the sensor's data in numbers (sensor's angle and distance between sensor and object) which is a constant stream. On the debug screen (Textbox) I can already see all the data coming through.
Now my question is: How do I convert those numbers into graphics?

More explanations about these numbers I want to convert:
I have a step motor to rotate the ultrasonic sensor, and it works that way:
The motor advances 1 step forward, then measure distance between sensor and object, then send these 2 values out.

So, if you see the attached file, those numbers on the text box mean:
000032 -> 000: step number & 032: 32cm between sensor and object
001031 -> 001: step number & 031: 31cm between sensor and object
002032 -> 002: step number & 032: 32cm between sensor and object
003007 -> 003: step number & 007: 7cm between sensor and object
and so on...

So those are the numbers I wish to convert into graphics. The scan line would need to rotate clockwise at same speed of the step motor. And then I would like to display dots when an object is detected.

First we know that we working from the center, so we get our center X and Y cords... (which normally is 1/2 width and 1/2 Height)..
Now we take your data and split it into Direction and Range and plug them into the above calculations...

But what is happening is: It draws the step 0 every time just before drawing the new step/angle. For example:
on step 1: it draws steps 0 and 1
on step 2: it draws steps 0 and 2
on step 3: it draws steps 0 and 3
on step 4: it draws steps 0 and 4
and so on... All the way to step 249.

Do you guys know how to fix this? By the way, I'm drawing on the top of the PictureBox which contains my background image.
Thanks!

Re: Displaying data graphically (Ultrasonic radar)

dglienna: Thanks for your reply! I figured out what was wrong.
I have done some progress since my last post but now I have another problem.
The Visual Basic program is not fast enough to display the real-time data. My motor takes about 4.5 seconds to complete a full rotation (which is 250 steps) but in my Visual Basic display it takes about 10 seconds to complete the full rotation.
I have already changed the Baud rate from my microcontroller but it doesn't improve a lot.
I am planning to do the sweep and display the data at same time (is that possible?) Because I aiming to build a real-time data 'radar'.

And this is how I am receiving the data, splitting it into angle and distance, and plotting the angle (snapshots):

***EDIT: I am using If data = " " Then Temp = "" and If Temp.Length = 6 because every string has 6 numbers (3: step angle + 3: distance of object detected) and the strings are separated by a " " (space) as I explained in my first post.

Last edited by Alex83UK; March 26th, 2012 at 04:23 AM.
Reason: Code explanations

Re: Displaying data graphically (Ultrasonic radar)

A few things you'll need to to ...

#1: Double buffer the image.. Work's a load faster this way.. (check the article again for sample code)

#2 : PictureBox1.Invalidate() Is not the best method to use here.. it forces the Picturebox to completely redraw itself( not just update the bit you want..) and this is where your code is now slowing down..

Is also slower than the code sample i posted... WHY ??? well the Red highlighted bits are doing calculations and memory allocations that only need be done once (at the beginning), and not for every iteration ....

Time now to optimise your code properly.. Go back to the projects in the article and check how I'm able to LINEDRAW up to 30 objects on to a picture box with upto 60 frames per second, without even a little flicker..

The Framerate your project is looking for is 55 frames per second, Very Very doable with the right code.. but even if we do a frame after every second point, we get a comfortable 27 frames per second, which is easier on the hardware...

Re: Displaying data graphically (Ultrasonic radar)

Hi GremlinSA, I have done all the changes you suggested and the program is still slow.
#1: Done - (Set DoubleBuffered = True in the System.Windows.Forms.Form properties)
#2: I am now using PictureBox1.Invalidate(New Region(New Rectangle(167, 141, 251, 251))) which redraws only the area that my scan line is being draw.
#3: Now I have:

Re: Displaying data graphically (Ultrasonic radar)

Originally Posted by Alex83UK

Hi GremlinSA, I have done all the changes you suggested and the program is still slow.
#1: Done - (Set DoubleBuffered = True in the System.Windows.Forms.Form properties)
#2: I am now using PictureBox1.Invalidate(New Region(New Rectangle(167, 141, 251, 251))) which redraws only the area that my scan line is being draw.
#3: Now I have:

#1 : Double Buffering : Setting a form's double buffering DOES NOT speed up the rendering of a form. It's used to prevent the artifacts that occur when a big form with many objects and a long rendering time starts to render.. (Ever had a proggy run where you can actually sit and watch it render each control one at a time and 'build' the form while you watch), So the DblBuffer was introduced that allowed the form painter to render the forms image in-memory, and when done, transfer the final form image to screen.. (Experience has shown that a form with DBL buffering set runs slower)

For Proper DBLBuffering, you need to set up a secondary in-memory image, render your bitmap on it, then for each frame simply transfer it to the picturebox...

#2 : PictureBox1.Invalidate is not the method to use, Even with specifying the region to 'invalidate' there are many underlying events and subs that are called that slow the whole thing down...

Setting up the correct method of dbl buffering will allow you to use 'PictureBox1.Image = Buffer.image'