Radar Software

OlliHeath

New Member
Hello all.

I am new here and I am currently creating my own project for my second year of college.

I was just wondering if anyone had any idea of any software showing a radar display for use with an ultrasonic sensor. I am attempting to get it to map out the data found by the sensor onto a 180 Degrees radar screen. Has anyone heard of any ?

Thank you,
OlliHeath
 

eclectic

Moderator
Welcome to the Forum Olli.

First, go to the Advanced Search tool
(top right)

then type in the terms

Ultrasonic radar

I think there are eighteen threads.

After that, please tell us more about your project.

e
 

OlliHeath

New Member
I have searched the forum but there are no other threads asking about software to actually map out the data found by the sensor as a 180 Degree radar on a computer screen.

Also, i shall be using the standard CHI030A Project Board, as it uses a PICAXE-18M2 chip needed for my programming. I will also use the USB cable to connect the circuit to the computer.

I have found a program called 'PING))DAR' which is meant to map out the data found by the sensor as seen in this video:
http://www.youtube.com/watch?v=T65r-xo4p2k

It is based as a '.bs2' file, so I imported it into 'PICAXE Programming Editor' but whenever I try and simulate it, it gives a syntax error. I am not sure whether it is because it was written in basic stamp 2 which, I assume, is not supported by PICAXE, or whether it is a problem with the actual code.

Your input is thankfully recieved,
OlliHeath
 

manuka

Senior Member
Nifty display! That .bs2 extension almost certainly relates to a Basic Stamp 2 program. These are usually "almost" PICAXE compatible, but be the code tweaking can be tedious. How large is the bs2 file ? What commands is it based around? Can you give a URL or show it here (using 'code') ?

Stan (extensive BS user in the mid-late '90s)
 

hippy

Senior Member
I have found a program called 'PING))DAR' which is meant to map out the data found by the sensor as seen in this video:
http://www.youtube.com/watch?v=T65r-xo4p2k
Note that the PING))DAR BS2 software simply moves the sensor and takes a distance measurement, sends that to PC-side software which then draws the radar-style display.

For the actual radar display you will need to find ( or write ) PC software which can do that then write the PICAXE code to send the appropriate data in the format that PC software expects.

In the video the PC-side program is said to be written in Java and would likely be purpose-written for its task. Unfortunately, like many YouTube presented projects, it shows what can be achieved but seems to have little information on how it was achieved, what programs were used or where they can be found.
 

OlliHeath

New Member
Code:
' -----[ Main Routine ]-------------------------------------------------------

DO

  IF pingDir <= LimitRight THEN              ' Refresh display if far right
    DEBUG CLS, CRSRXY, 50, 25, "X"
  ENDIF

  GOSUB Sweep_Increment                      ' Move servo by sweepInc

  ' Calculate angle from far right in brads.
  angle = pingDir - LimitRight ** PingDirToAngle

  GOSUB Get_Ping_Cm                          ' Get cm measurement
  distance = distance MAX 100 / 4            ' Scale for Debug Terminal

  GOSUB Polar_To_Cartesian                   ' distnace @ angle -> (x, y)

  x = x * 2                                  ' 2 spaces for every 1 CR

  DEBUG CRSRXY, 50 + x, 25 - y, "*"          ' Display (x, y) coordinate

LOOP
This is the main part of the code, the parts before this are just explaining what each PIN is and such. The files size overall is 6kb.


For the actual radar display you will need to find ( or write ) PC software which can do that then write the PICAXE code to send the appropriate data in the format that PC software expects.
Does this mean that I will have to write the actualy display code myself ? Or is there some freeware already out there that I may be able to take advantage of ?

Once again, thank you.
OlliHeath
 

hippy

Senior Member
Does this mean that I will have to write the actualy display code myself ? Or is there some freeware already out there that I may be able to take advantage of ?
Yes, you'll have to write it yourself or find some existing version already written.

The DEBUG CRSRXY, 50 + x, 25 - y, "*" is BS2 code for sending the display data out and the receiving PC program displays it. The BS2 system seems to have a terminal mode which can draw the above as a text display and the video seems to use a self-written alternative to that. A PICAXE can send the same data in a similar way but the PICAXE system does not have such a capability to turn it into a display.
 

hippy

Senior Member
One option would be a VT100 Terminal Emulator and convert the BS2 DEBUG commands into SEROUT or SERTXD commands which sends ANSI Escape Codes to position the cursor and draw the "*", which is all the BS2 setup seems to be.

The BS2 program used for the video is probably modified to send data differently, in a more appropriate form for a graphics display than a text display.
 

OlliHeath

New Member
Hello everyone, I am just getting back to you all to tell you that I have completed the programming and circuit and it is know completely working! Now I have to work out a way of mapping out the data found and saved by the ultrasonic sensor, as a radar screen on the computer. Does anyone have any idea how to do this?

Thanks again,
OlliHeath

P.S: With the poke command, does it save the distance data found by the sensor that I could then use to map it out on the PC?
 

buntay

Senior Member
What are your PC programming abilities? windows? dos? programming software? This will be a good beginner serials project for visual basic just remember there are lots of fast serials going on if you want smooth operation.

This will help get the data into the PC.
Code:
Option Explicit
Dim rxFifo$
'"Thanks Hippy!!"




Private Sub Form_Load()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
MSComm1.PortOpen = True
End Sub

Private Sub MSComm1_OnComm()
Dim rxData$
Dim i&
  With MSComm1
    Select Case .CommEvent
      Case comEvReceive
        rxData$ = .Input
        If Len(rxData$) <> 0 Then
          rxFifo$ = rxFifo$ + rxData$
          i& = InStr(rxFifo$, vbCr)
          While i& <> 0
            Call ReceivedLineOfData(Left$(rxFifo$, i& - 1))
            rxFifo$ = Right$(rxFifo$, Len(rxFifo$) - i&)
            i& = InStr(rxFifo$, vbCr)
          Wend
        End If
    End Select
  End With
End Sub

Private Sub ReceivedLineOfData(ByVal s$)
  While Left$(s$, 1) = vbLf
    s$ = Right$(s$, Len(s$) - 1)
  Wend
  s$ = Trim$(s$)
  If Len(s$) <> 0 Then
    Text1.Text = s$
  End If

End Sub
This is for visual basic 6. You will need a comm control and and a textbox.
If you would like more help let me know
 

lewisg

Senior Member
Does anyone have any idea how to do this?
In many ways you need to figure out the display software first, then you can modify the PICAXE data output to fit. I'd imagine you'd have the PICAXE output a data pair of servo position (x axis) and distance (y axis). Any programming language capable of drawing to the screen and serial communications should be able create the screen display. If you want to stick with BASIC (the way to go IMHO) then there are quite a few to choose from. QBASIC which can be found online or on pre XP MS Install disks still runs on Win7 32 bit. An updated open source version QB64 can be found at qb64.net. A completely modern OOP cross platform implementation of BASIC can be found at realsoftware.com. Between those two extremes there are lots of choices.


Good luck with your school project!
 

KeithRB

Senior Member
One cool thing you could do is to put a string of LED's on a pointer and use a stepper motor (or servo if you want less than 360 degrees), as the pointer rotates light up a single (or string) of LED's to indicate the distance. This could be done pretty easily with another picAxe getting serial commands from your Sonar.

Much as I hate to say it, you might be able to use VBA and do this all in excel:
http://dev.emcelettronica.com/serial-port-communication-excel-vba
 

Bill.b

Senior Member
hi OlliHeath I quickly hooked up this on my axe091 simulator and downloaded PLX-DAQ serial to excel freeby. sorry i do not have the link
but google should locate the site.

I used only one servo to scan a SFR005 ultrasonic unit.

hope this may help

picaxe 18m2
servo connected to b.0 (pin 6)
SFR005 output connected to b.3 (pin 9)


Code:
#picaxe 18m2
#No_Data
pause 1000
setfreq m8

symbol servoCount		= b0
symbol counter1 		= b1			'counter
symbol asciihd		= b2
symbol asciiten		= b3
symbol asciiunit		= b4
Symbol range            = w10			'front range sensor register
Symbol trig 		= b.3			'front range sensor ADC input	
Symbol SERVO1           = b.0			'Pan servo output


Symbol SERVO1_MIDDLE    = 145 
servo servo1,SERVO1_MIDDLE 
main:
	gosub scan1
goto main
scan1:
for counter1 = 1 to 80
	servoCount = counter1+40
	ServoPos SERVO1,servoCount
	pulsout trig,2        		' produces about 20uS pulse (must be minimum of 10uS)
 	pulsin trig,1,range  		' measures the range in 10uS steps
   	pause 10               		' SRF005 mandatory 10mS recharge period after ranging completes
    	let range = range * 10 /29 	' multiply by 10 then divide by 29  (8meg) 
    	bintoascii range,asciihd,asciiten,asciiunit
	sertxd ("DATA,",asciihd,asciiten,asciiunit,13,10)
	pause 200
next counter1
sertxd ("CLEARDATA,",13,10)
return
this is the excel screen

excel.jpg

regards Bill
 
Last edited:

lanternfish

Senior Member
Hello everyone, I am just getting back to you all to tell you that I have completed the programming and circuit and it is know completely working! Now I have to work out a way of mapping out the data found and saved by the ultrasonic sensor, as a radar screen on the computer. Does anyone have any idea how to do this?

Thanks again,
OlliHeath

P.S: With the poke command, does it save the distance data found by the sensor that I could then use to map it out on the PC?
You could try the program at the top of this page at Lets Make Robots. It is a Python script. You will need a copy of Python 2.4 (or better) available here and the other modules listed in the article.

Cheers
 
Last edited:

OlliHeath

New Member
Hello all.

Thanks for all the help! Just letting you know that i am attempting the Phython code that lantern linked as it comes with a pre-made radar code aswell! Great find lantern, thank you!

I will update you all on how it goes, and thanks again for your help.

OlliHeath
 
Last edited:

hippy

Senior Member
It should be entirely possible for Java ( or almost any programming language ) to read in serial data from the PICAXE via the AXE027 cable and display it. The video you linked to in post #3 seems to be of a program doing precisely that.

The bigger question is how to do it and that's where having PC-side programming skills comes into it. In overview it's just open the serial port, tell the PICAXE to send the data, read that, process it and display the results.
 

lewisg

Senior Member
It is a Python script.
Geez Louise!

Did any of you all read that pile'o'confusion?

If I had to program like that I wouldn't.

This is dead easy.

On the PICAXE side it spits a serial string like this: *23/200(cr)(lf) which would mean 23 degrees of servo rotation, distance 200 with a cr lf termination.

On the PC side just start receiving strings, no need to ask for them. Once you receive a string check and see if the degree portion exists in a clear previous point array and if it doesn't (first sweep) plot the coordinates on the screen. If the degree portion does exist in the clear previous point array first clear the existing coordinate on the screen and plot the new one.

There is likely less than 100 lines of code required to get a basic version up and running. If you want to add fancier screen graphics (sweep line, grid...) then that would take more code. I'm not a math whiz but there might need to be some math to correct the coordinates for polar display. If so do that on the PC since the math abilities are stronger than on the PICAXE, still not a lot of code...
 

OlliHeath

New Member
Hello everyone,

I downloaded the python program (2.7.2) and the code that the person provided. I don't suppose any of you are Python users are you? As I keep getting an error saying "ImportError: No Module Named wx". I have looked online for solutions and found the solution of installing the 'wxPython' script package, then I get another error, listing about 3 different problems. I can't remember them off the top of my head as the program is on my laptop at home and I am currently in college. When I get home, I will call up the program and paste it into here.

Thanks again guys!
OlliHeath
 

hippy

Senior Member
I keep getting an error saying "ImportError: No Module Named wx". I have looked online for solutions and found the solution of installing the 'wxPython' script package, then I get another error, listing about 3 different problems.
Welcome to the wonderful world of third-party window managers.

AIUI wxPython is just a bridge between Python and the wxWidget toolkit and hopefully includes everything needed to make it all work but you may have to install wxWidgets separately, and that may have some prerequisite which you also have to install, and so on until it eventually works ... or you give up ;-)

What the error messages are will hopefully give a better idea of the problem .
 

lanternfish

Senior Member
I have struck these error messages too! Unfortunately I am still learning Python scripting so haven't quite found out what the errors are. If I find a solution I will post it here.
 

hippy

Senior Member
I have struck these error messages too! Unfortunately I am still learning Python scripting so haven't quite found out what the errors are. If I find a solution I will post it here.
Perhaps post what the error messages say then someone may be able to offer some guidance. Even if not familiar with Python or wxPython they may be able to provide a pointer in the right direction of a solution.
 

lanternfish

Senior Member
Hello everyone,

I downloaded the python program (2.7.2) and the code that the person provided. I don't suppose any of you are Python users are you? As I keep getting an error saying "ImportError: No Module Named wx". I have looked online for solutions and found the solution of installing the 'wxPython' script package, then I get another error, listing about 3 different problems. I can't remember them off the top of my head as the program is on my laptop at home and I am currently in college. When I get home, I will call up the program and paste it into here.

Thanks again guys!
OlliHeath
Yes you do have to install wxPython seperately. You can download it from here. You can get the pySerial from here.
 

OlliHeath

New Member
The error i get is:
ImportError: DLL load failed: %1 is not a valid Win32 application.

I believe that this may be due to the download of incompatible wxPython and Python module. I am re-downloading both 32-bit versions of Python and wxPython, I will update you on how it goes.

Kind regards,
Olli Heath
 

OlliHeath

New Member
Okay update time. I re-downloaded Python 2.7 and wxPython 2.7 (both 32-bit versions) and I have overcome the previous error codes. Now I am receiving an error code saying:

ImportError: No module named serial

I am guessing that this is due to me having not downloaded the pySerial application.

Now downloading the pySerial application and will, again, update you all.

Thanks again,
OlliHeath
 

OlliHeath

New Member
Okay new problem. I installed everything, Python, wxPython, pySerial and AXE027 drivers. I am now getting an error message explaining that COM1 cannot be used and so i am trying to find all of the parts of code that refer to COM1 in the code and change them to use COM3 (The COM port in which I am using the AXE027 Cable to connect to my Sensor). Are any of you Python savvy people? If so, could you please help, here is the full code:

Code:
import math, datetime
import wx
import ConfigParser, serial
import threading, thread

rate = 4800
id_SPACE = 11000
id_TEST = 11001
gverbose = True
toolBtns = [
            (True, id_TEST, "test", "Test", "Test Mode" ),
            (False, id_SPACE, 10),
 ]

class Radar():
    def __init__(self):
        # position set
        self.pos = 0
        self.max_queue = 100
        self.endpos = 0
        self.queue = []

    def add_obj(self, iangle, angle, poslist):
        self.queue.append((iangle,angle,poslist))
        if len(self.queue) > self.max_queue:
            del self.queue[0:(self.max_queue/2)]
            print len(self.queue)


def batchread():
    global gr
    gr = Radar()
    comm = 1
    ser = serial.Serial("COM%d" % comm, rate)
    # temperature
    c = 25
    # speed of sound
    sp = 331.5 * math.sqrt(1 + ((c) / 275.15))
    while (1):
        e = True
        angle1 = ord(ser.read(1))
        angle2 = ord(ser.read(1))
        angle = (angle1 << 8)  + angle2
        if angle < 400:
            samples = ord(ser.read(1))
            if (samples <= 5):
                poslist = []
                for i in range(0, samples):
                    x1 = ord(ser.read(1))
                    x2 = ord(ser.read(1))
                    x = (x1 << 8) + x2
                    d = float(x) * sp / 20000.0
                    poslist.append(d)
                x = ord(ser.read(1))
                if x == 0xff:
                    x = ord(ser.read(1))
                    if x == 0xff:
                        e = False
                        if samples > 0:
                            a = float(angle) / 400.0 * math.pi
                            gr.add_obj(angle, a,poslist)
                            print "Add", len(gr.queue), angle, poslist
                        else:
                            print "."

        if e:
            print "Error, Skip to next record"
            while (1):
               x = ord(ser.read(1))
               if x == 0xff:
                    x = ord(ser.read(1))
                    if x == 0xff:
                        break
        if len(gr.queue) >= 500:
            break

    GuiStart()




#############################################################################
##########################################################################
*continued*
 

OlliHeath

New Member
*continued*

Code:
class radarWin(wx.Window):
    def __init__(self, parent, log, id, size):
        wx.Window.__init__(self,parent,id,size=size)

        self.log = log
        self.parent = parent

        #self.FitInside()
        self.SetBackgroundColour(wx.BLACK)
        self.size = self.GetClientSize()
        self.pen = wx.Pen(wx.Color(255,0,0), 2, wx.SOLID)
        self.penline = wx.Pen(wx.Color(0,255,0), 2)
        self.penradarline = wx.Pen(wx.Color(255,255,0), 2)
        self.pens= []
        for i in range(0,255):
            self.pens.append(wx.Pen(wx.Color(i+1,i+1,i+1), 2, wx.SOLID))
        self.posdict = {}
        self.maxdist = 160.0
        self.ilastangle = -1
        self.timer = wx.Timer(self)
        self.timer.Start(100)

        self.Bind(wx.EVT_SIZE, self.onSizeEvent)
##        self.Bind(wx.EVT_LEFT_DOWN, self.onLeftDown)
##        self.Bind(wx.EVT_LEFT_DCLICK, self.onLeftDoubleClickEvent)
##        self.Bind(wx.EVT_RIGHT_DOWN, self.onRightClick)
##        self.Bind(wx.EVT_MOTION, self.onMotionEvent)
##        self.Bind(wx.EVT_LEFT_UP, self.onLeftUp)
        self.Bind(wx.EVT_PAINT, self.onPaintEvent)
##        #self.Bind(wx.EVT_SCROLL_ENDSCROLL, self.onEndScrollEvent)
##        self.Bind(wx.EVT_SCROLLWIN_THUMBRELEASE, self.onEndScrollEvent)
##        self.Bind(wx.EVT_SCROLL_THUMBTRACK, self.onEndScrollEvent)
##        self.Bind(wx.EVT_SCROLL_THUMBTRACK, self.onEndScrollEvent)
        #self.Bind(wx.EVT_IDLE, self.onIdleEvent)
        self.Bind(wx.EVT_TIMER, self.onIdleEvent)

    def onSizeEvent(self, event):
        self.size = self.GetClientSize()
        #self.Recalculate()
        event.Skip()

    def onIdleEvent(self, event):
        event.Skip()
        dc = wx.ClientDC(self)
        self.paint(dc)
        #self.Refresh()

    def onPaintEvent(self, event):
        dc = wx.PaintDC(self)
        self.paint(dc)

    def paint(self,dc):
        global gr
        global glock
        #dc = wx.PaintDC(self)
        self.PrepareDC(dc)
        dc.BeginDrawing()
##        for i in range(0,255):
##            dc.SetPen(self.pens[i])
##            dc.DrawCircle(self.size[0] * i / 255,100,2)
        midx = self.size[0] / 2
        ratio = float(midx * 2) / self.maxdist
        bottom = self.size[1]
        dc.SetPen(self.pen)
        dc.SetBrush(wx.TRANSPARENT_BRUSH)
        dc.DrawCircle(midx,bottom,20)

        dc.SetPen(self.pens[254])
        glock.acquire()

        #clean up the previous radar line
        if self.ilastangle >= 0:
            dc.SetPen(self.pens[0])
            d = self.maxdist * ratio
            y = bottom - int(math.sin(self.lastangle) * d)
            x = midx + int(math.cos(self.lastangle) * d)
            dc.DrawLine(midx,bottom,x,y)
            # redraw the affected dots
            for iangle in range(self.ilastangle - 5, self.ilastangle + 5):
                if iangle in self.posdict:
                    angle, oldplist = self.posdict[iangle]
                    dc.SetPen(self.pens[254])
                    for i in oldplist:
                        d = i * ratio
                        y = bottom - int(math.sin(angle) * d)
                        x = midx + int(math.cos(angle) * d)
                        dc.DrawCircle(x,y,2)

        for info in gr.queue:
            iangle, angle, poslist = info
            if iangle in self.posdict:
                a, oldplist = self.posdict[iangle]
                dc.SetPen(self.pens[0])
                for i in oldplist:
                    d = i * ratio
                    y = bottom - int(math.sin(angle) * d)
                    x = midx + int(math.cos(angle) * d)
                    dc.DrawCircle(x,y,2)

            dc.SetPen(self.pens[254])
            for i in poslist:
                d = i * ratio
                y = bottom - int(math.sin(angle) * d)
                x = midx + int(math.cos(angle) * d)
                dc.DrawCircle(x,y,2)
            self.posdict[iangle] = (angle, poslist)

        if len(gr.queue) > 0:
            iangle, angle, poslist = gr.queue[-1]
            self.ilastangle = iangle
            self.lastangle = angle
            dc.SetPen(self.penradarline)
            d = self.maxdist * ratio
            y = bottom - int(math.sin(self.lastangle) * d)
            x = midx + int(math.cos(self.lastangle) * d)
            dc.DrawLine(midx,bottom,x,y)

        dc.SetPen(self.penline)
        d = self.maxdist/8
        while d < self.maxdist:
            dc.DrawCircle(midx,bottom,int(d * ratio))
            d = d + self.maxdist/8
        angles = [ math.pi, math.pi*3/4.0, 0, math.pi/4.0, math.pi/2]
        d = self.maxdist * ratio
        for angle in angles:
            y = bottom - int(math.sin(angle) * d)
            x = midx + int(math.cos(angle) * d)
            dc.DrawLine(midx,bottom,x,y)
        glock.release()
        dc.EndDrawing()


# croChartPanel contains the
# radarWin          optional toolBtns window
class radarPanel(wx.Panel):
    def __init__(self, parent, id, log, style, sizehint, sidebtn=True, loadbtn=False, cancelbtn=True):
        wx.Panel.__init__(self, parent, id, style=style)

        self.log = log
        self.sidebtn = sidebtn

        self.radarWin = radarWin(self, log, -1,sizehint)
        if sidebtn or cancelbtn or loadbtn:
            toolSizer = wx.BoxSizer(wx.VERTICAL)
        else:
            toolSizer = None

        if sidebtn:
            self.toolBtns = []
            for tp in toolBtns:
    ##            if tp[0]:
    ##                btn = stCommon.BitmapToggleButton(self, tp[1], tp[2], tp[4])
    ##            else:
    ##                btn = stCommon.BitmapButton(self, tp[1], tp[2], tp[4])
                if tp[1] == id_SPACE:
                    toolSizer.AddSpacer((1,tp[2]))
                    continue

                if tp[0]:
                    btn = wx.ToggleButton(self, tp[1], tp[3])
                    btn.Bind(wx.EVT_TOGGLEBUTTON, self.onToolIconClick)
                else:
                    btn = wx.Button(self, tp[1], tp[3])
                    btn.Bind(wx.EVT_BUTTON, self.onToolIconClick)
                btn.SetToolTipString(tp[4])

                toolSizer.Add(btn,1,wx.LEFT | wx.RIGHT)
                self.toolBtns.append(btn)

            toolSizer.AddSpacer((1,10))

        if loadbtn:
            btn = wx.Button(self, -1, "Load Default")
            #self.Bind(wx.EVT_BUTTON, self.OnLoadDefault, btn)
            toolSizer.Add(btn,1,wx.LEFT | wx.RIGHT)
            btn = wx.Button(self, -1, "Load File")
            #self.Bind(wx.EVT_BUTTON, self.OnLoad, btn)
            toolSizer.Add(btn,1,wx.LEFT | wx.RIGHT)

        if cancelbtn:
            btn = wx.Button(self, wx.ID_CANCEL, "Cancel")
            toolSizer.Add(btn,1,wx.LEFT | wx.RIGHT)

        if sidebtn:
            statusSizer = wx.BoxSizer(wx.VERTICAL)
            self.lblStatus1 = wx.StaticText(self)
            statusSizer.Add(self.lblStatus1,1,wx.LEFT)
            #self.toolBtns.append(self.lblStatus1)
            statusSizer.AddSpacer((1,10))
            self.lblStatusMark = wx.StaticText(self)
            statusSizer.Add(self.lblStatusMark,1,wx.LEFT)
            #self.toolBtns.append(self.lblStatusMark)
            statusSizer.AddSpacer((1,20))
            self.lblStatus2 = wx.StaticText(self)
            statusSizer.Add(self.lblStatus2,1,wx.LEFT)
            #self.toolBtns.append(self.lblStatus2)
            toolSizer.AddSpacer((1,10))
            toolSizer.Add(statusSizer, 0)

        vSizer = wx.BoxSizer(wx.VERTICAL)
        vSizer.Add(self.radarWin, 1, wx.EXPAND)

        topSizer = wx.BoxSizer(wx.HORIZONTAL)
        topSizer.Add(vSizer, 0)
        if toolSizer != None:
            topSizer.Add(toolSizer, 0)

        self.SetAutoLayout(True)
        self.SetSizer(topSizer)

    def SetStatusMessage(self, text):
        self.lblStatus2.SetLabel(text)

    def onToolIconClick(self, event):
        global g_invert
        """ Respond to the user clicking on one of our tool icons.
        """
        id = event.GetEventObject().GetId()
        event.Skip()


# Dlg contains radarPanel
class radarDlg(wx.Dialog):
    def __init__(
            self, parent, log, ID=-1, title="Radar", sizehint=(800, 600), size=(800, 600), pos=wx.DefaultPosition,
            style=wx.DEFAULT_DIALOG_STYLE
            ):
        wx.Dialog.__init__(self, parent, ID, title, pos, size, style)
        self.log = log
        self.topPanel = radarPanel(self, -1, self.log, sizehint=sizehint, style=wx.SIMPLE_BORDER)

        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.topPanel, 1)

##        btnCancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
##        box.Add(btnCancel, 0)
##        btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)


        box.SetSizeHints(self)
        self.SetSizer(box)
        #parent.Fit()
        box.Fit(self)
        #self.Fit()

##    def OnCancel(self, evt):
##        self.EndModal(0)

class RadarApp(wx.App):
    def OnInit(self, loadfile=None):
        if False:
            frame = radarFrame(None, self, sizehint=(800, 600))
            frame.Centre()
            frame.Show(True)
            return True
        else:
            dlg = radarDlg(None, self, sizehint=(800, 600))
            dlg.CenterOnParent()
            dlg.ShowModal()
            dlg.Destroy()
            return False

    def write(self, s):
        print s

def GuiStart():
    _app = RadarApp(0)
    _app.MainLoop()
*continued*
 

OlliHeath

New Member
*continued*

Code:
################################################################################
class JobThreadBase():
    def __init__(self, parent, log):
        self.parent = parent
        self.log = log
        self.keepGoing = self.running = False

    def Start(self):
        self.keepGoing = self.running = True
        thread.start_new_thread(self.Run, ())

    def Stop(self):
        self.keepGoing = False

    def IsRunning(self):
        return self.running

    def IsKeepGoing(self):
        return self.keepGoing

class SerJobThread(JobThreadBase):
    def __init__(self, log, port, rate):
        global gr
        global glock
        self.ser = serial.Serial("COM%d" % port, rate)
        #self.ser.setTimeout(timeout)
        self.port = port
        self.log = log
        self.lock = threading.Semaphore()

        gr = Radar()
        glock = threading.Semaphore()


    def Run(self):
        global glock
        global gverbose
        try:
            # temperature
            c = 25
            # speed of sound
            sp = 331.5 * math.sqrt(1 + ((c) / 275.15))
            while (self.keepGoing):
                e = True
                angle1 = ord(self.ser.read(1))
                angle2 = ord(self.ser.read(1))
                angle = (angle1 << 8)  + angle2
                if angle < 400:
                    samples = ord(self.ser.read(1))
                    if (samples <= 5):
                        poslist = []
                        for i in range(0, samples):
                            x1 = ord(self.ser.read(1))
                            x2 = ord(self.ser.read(1))
                            x = (x1 << 8) + x2
                            d = float(x) * sp / 20000.0
                            poslist.append(d)
                        x = ord(self.ser.read(1))
                        if x == 0xff:
                            x = ord(self.ser.read(1))
                            if x == 0xff:
                                e = False
                                if samples >= 0:
                                    a = float(angle) / 400.0 * math.pi
                                    glock.acquire()
                                    gr.add_obj(angle,a,poslist)
                                    glock.release()
                                    if gverbose:
                                        print "Add", len(gr.queue), angle, poslist
                                else:
                                    if gverbose:
                                        print "."

                if e:
                    self.log.write("Error, Skip to next record\n")
                    while (self.keepGoing):
                       x = ord(self.ser.read(1))
                       if x == 0xff:
                            x = ord(self.ser.read(1))
                            if x == 0xff:
                                break

        except Exception, e:
            self.log.write("SerJobThread Exception %s" % (e))

        self.running = False

class mylog():
    def write(self, s):
        print s

if __name__ == '__main__':
    log = mylog()
    st1 = SerJobThread(log, 1, rate)
    st1.Start()
    GuiStart()
Okay so that's the code. sorry I had to spread it out, it would only allow me to write 10,000 characters and it totalled out at 15,794!
Again, thank you if any of you can help me.

Kind Regards,
OlliHeath
 

OlliHeath

New Member
People....I NOW HAVE A RADAR SCREEN!

Unfortunately the picture is too large to be uploaded but trust me, it looks good!

If anyone was wondering how I changed the serial port, this is how I went about it...

1) Find ser = serial.Serial()

2) Change the value between the () to the COM port you are using -1

example: I want "COM3" so I write "ser = serial.Serial(2)"

3) There should be two of these pieces of code, one to send, one to recieve so you must change both if you are using a single port.


Thanks everyone! Now just trying to figure out how to save the range data found by the sensor and send it over to the radar screen!
Fingers crossed!

Kind Ragrds,
OlliHeath
 

Goeytex

Senior Member
Another option for a radar screen that does not depend on PC side software is to use one of these with a small
dedicated flat screen VGA monitor. The Picaxe draws the screen with serial commands. Circles, rectangles, lines,
animated graphics, etc ...... all with simple serial command sequences.

http://www.4dsystems.com.au/prod.php?id=131
 

OlliHeath

New Member
Okay so i now have:
- A radar screen which reads data from serial port 3 (COM3)
- A working electronic circuit, using a servo, SRF005, Picaxe 18-M2 chip, 2x batteries

The last thing I need to find out is, how to save the range data found by the sensor so that the Python radar screen can read this data and produce a radar screen showing these objects. Does anyone know how to do this?

Kind Regards,
Olli Heath
 

OlliHeath

New Member
I am using the 'Poke' Command to save the range data found to the 18-M2s RAM. I am now stumped, as I begin the circuit and the python radar screen program, but no white circles show up and no orange line to depict the servo position show up, which I assume means that the program is not reading the data from the sensor. Someone help me!?

Kind regards,
OlliHeath
 

SolidWorksMagi

Senior Member
People....I NOW HAVE A RADAR SCREEN!

Unfortunately the picture is too large to be uploaded but trust me, it looks good!

If anyone was wondering how I changed the serial port, this is how I went about it...

1) Find ser = serial.Serial()

2) Change the value between the () to the COM port you are using -1

example: I want "COM3" so I write "ser = serial.Serial(2)"

3)
There should be two of these pieces of code, one to send, one to recieve so you must change both if you are using a single port.


Thanks everyone! Now just trying to figure out how to save the range data found by the sensor and send it over to the radar screen!
Fingers crossed!

Kind Ragrds,
OlliHeath

Hi, There is no such thing as a picture too big to add to your posts. In fact, the larger the better since we can resize it to fit our own PC screens.
 

hippy

Senior Member
Hi, There is no such thing as a picture too big to add to your posts. In fact, the larger the better since we can resize it to fit our own PC screens.
There are forum limitations to the size of what can be posted so I guess that was what was being referred to. I doubt we will ever know for sure or see what would have been posted as this was all 8 years ago.
 
Top