UKHAS Wiki

UK High Altitude Society

User Tools

Site Tools


projects:ukhas_glider_project:master

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
projects:ukhas_glider_project:master [2007/09/05 10:37] laurencebprojects:ukhas_glider_project:master [2008/07/19 23:33] (current) – external edit 127.0.0.1
Line 3: Line 3:
 $crystal = 16000000 $crystal = 16000000
 $baud = 16000 $baud = 16000
-$hwstack = 40 +$hwstack = 32 
-$swstack = 40 +$swstack = 64 
-$framesize = 40+$framesize = 96
 Open "comc.4:125000,8,N,1" For Output As #1 Open "comc.4:125000,8,N,1" For Output As #1
 Open "comc.3:125000,8,N,1" For Input As #2 Open "comc.3:125000,8,N,1" For Input As #2
 Open "comd.2:4800,8,n,1" For Input As #3                    'rx from pc Open "comd.2:4800,8,n,1" For Input As #3                    'rx from pc
 +Open "comb.4:19200,8,n,1" For Output As #4                  'Logger
 Config Adc = Single , Prescaler = Auto , Reference = Internal Config Adc = Single , Prescaler = Auto , Reference = Internal
 Config Portd.7 = Output Config Portd.7 = Output
Line 22: Line 23:
 Config Portc.0 = Input Config Portc.0 = Input
 Config Portc.5 = Input Config Portc.5 = Input
 +Config Watchdog = 4096
 'Config Portc.4 = Output 'Config Portc.4 = Output
 'Config Portc.3 = Input 'Config Portc.3 = Input
Line 39: Line 41:
 Declare Sub Checkvoltage() Declare Sub Checkvoltage()
 Declare Sub Cutdown(byval Channel As Byte , Byval Duration As Byte) Declare Sub Cutdown(byval Channel As Byte , Byval Duration As Byte)
 +Declare Sub Radiocomms()
 Echo Off Echo Off
 Start Adc Start Adc
 +Dim Rate As Integer
 +Dim Temperature As Integer , Error As Byte , Heading As Single , Filteredrate As Single , Pulselenght As Word
 +Dim Pulses As Byte
 Dim S As String * 100 Dim S As String * 100
 Dim T As String * 15 Dim T As String * 15
 +Dim Printstring As String * 20
 Dim K As Single Dim K As Single
-Dim Iterations As Byte +Dim Iterations As Byte , Flashcount As Byte 
-Dim Windxs(256) As Eram Byte +Dim Windxs(251) As Eram Byte 
-Dim Windys(256) As Eram Byte+Dim Windys(251) As Eram Byte , Placemark As Eram Byte 
 +Dim Target_es As Eram Single 
 +Dim Target_ns As Eram Single
 Dim Lock As Bit Dim Lock As Bit
 Dim Gpfloatone As Single , Gpsheading As Single Dim Gpfloatone As Single , Gpsheading As Single
-Dim As String * 90+Dim As String * 100
 Dim B As String * 6 Dim B As String * 6
 Dim Contents(17) As String * 15 Dim Contents(17) As String * 15
Line 55: Line 64:
 Dim N As Byte Dim N As Byte
 Dim I As Byte Dim I As Byte
 +Dim Statuscode As Byte
 Dim Heightupto As Byte , Rxenable As Byte , Servoenable As Byte Dim Heightupto As Byte , Rxenable As Byte , Servoenable As Byte
-Dim Gpbyteone As Byte , Gpbytetwo As Byte , Telcounter As Byte+Dim Gpbyteone As Byte , Gpbytetwo As Byte , Telcounter As Byte , Landcount As Byte
 Dim Gpintegerone As Integer Dim Gpintegerone As Integer
 Dim Intcount As Integer , Timeelapsed As Integer Dim Intcount As Integer , Timeelapsed As Integer
Line 67: Line 77:
 Dim Derivative As Single Dim Derivative As Single
 Dim Target As Single Dim Target As Single
 +Dim Target_e As Single
 +Dim Target_n As Single
 Dim Offset As Single Dim Offset As Single
 Dim Windy_total As Single Dim Windy_total As Single
Line 79: Line 91:
 Dim North As Single Dim North As Single
 Dim East As Single Dim East As Single
-Dim Target_e As Single 
-Dim Target_n As Single 
 Dim Store_east As Single Dim Store_east As Single
 Dim Store_north As Single Dim Store_north As Single
Line 88: Line 98:
 Dim Degrees As String * 3 Dim Degrees As String * 3
 Dim Command As String * 10 Dim Command As String * 10
 +Statuscode = 0
 Lock = 0 Lock = 0
 Iterations = 0 Iterations = 0
Line 93: Line 104:
 Wind_x = 0 Wind_x = 0
 Wind_y = 0 Wind_y = 0
-Waitms 500+Landcount = 0 
 +Telcounter = 0 
 +Portd.3 = 1 
 +Waitms 100 
 +Gpintegerone = Getadc(5) 
 +Gpfloatone = Gpintegerone 
 +Gpintegerone = Getadc(0) 
 +Gpfloatone = Gpfloatone / Gpintegerone 
 +If Gpfloatone < 0.5 And Gpfloatone > 0.4 Then 
 + Print "Button pressed" 
 +Else 
 + Print "Watchdog reset" 
 + Start Watchdog 
 + Target_n = Target_ns 
 + Target_e = Target_es 
 + Select Case Placemark 
 + Case 1: 
 + Goto Cutdownlbl                                            'cutdown if error during ascent 
 + Case 2: 
 + Goto Descentloop 
 + Case Else: 
 + Goto Cutdownlbl 
 + End Select 
 +End If 
 +Waitms 50
 Call Checkvoltage() Call Checkvoltage()
-Waitms 500 
 'Call Cutdown(1 , 4) 'Call Cutdown(1 , 4)
 Print "wind records:" Print "wind records:"
-For Gpbyteone = 1 To 255+For Gpbyteone = 1 To 251
  Gpbytetwo = Windxs(gpbyteone)  Gpbytetwo = Windxs(gpbyteone)
- Print Gpbyteone ; "," ; Gpbytetwo ; ","+ Print Gpbyteone ; "," ; Gpbytetwo ; "," ;
  Gpbytetwo = Windys(gpbyteone)  Gpbytetwo = Windys(gpbyteone)
  Print Gpbytetwo  Print Gpbytetwo
Line 122: Line 156:
 Gotlock: Gotlock:
 Print "Okay we have GPS" Print "Okay we have GPS"
 +Print "check rc ground control, then"
 Print "Enter target north and east" Print "Enter target north and east"
 Input #3 , Target_n Input #3 , Target_n
Line 127: Line 162:
 Input #3 , Target_e Input #3 , Target_e
 Print Target_e Print Target_e
-Print "Launch!"+Gpfloatone = Target_ns 
 +If Target_n <> Gpfloatone Then Target_ns = Target_n         'store in eeprom 
 +Gpfloatone = Target_es 
 +If Target_e <> Gpfloatone Then Target_es = Target_e 
 +Portd.3 = 1 
 +Print "Launch!"                                             'radiocts pullup 
 +Start Watchdog 
 +Placemark = 1                                               'write eeprom to say in ascent
 Do Do
- While B <> "$GPGGA" + Reset Watchdog 
-  Input R + Do 
-  B = Mid(, 2 , 6) +  Input U 
- Wend +  B = Mid(, 2 , 6) 
- While <> "$GPRMC"+ Loop Until "$GPGGA" 
 + Do
   Input S   Input S
   B = Mid(s , 2 , 6)   B = Mid(s , 2 , 6)
- Wend+ Loop Until B = "$GPRMC"
    I = Split(s , Contents(1) , ","                        'process rmc    I = Split(s , Contents(1) , ","                        'process rmc
    K = Val(contents(9))    K = Val(contents(9))
Line 149: Line 192:
    Incr L                                                   'incrament the denominator for our averaging    Incr L                                                   'incrament the denominator for our averaging
    Incr Timeelapsed    Incr Timeelapsed
-   I = Split(, Contents(1) , ","                        'now process gga+   I = Split(, Contents(1) , ","                        'now process gga
    K = Val(contents(10))    K = Val(contents(10))
    K = K / 100    K = K / 100
Line 157: Line 200:
     Windx_total = Windx_total / L     Windx_total = Windx_total / L
     Gpbyteone = Windx_total + 127     Gpbyteone = Windx_total + 127
-    Windxs(arrayat) = Gpbyteone                             'we are storing as a signed byte+    Windxs(heightupto) = Gpbyteone                          'we are storing as a signed byte
     Windy_total = Windy_total / L     Windy_total = Windy_total / L
     Gpbyteone = Windy_total + 127                           'we find the average and shove it in the eeprom     Gpbyteone = Windy_total + 127                           'we find the average and shove it in the eeprom
-    Windys(arrayat) = Gpbyteone+    Windys(heightupto) = Gpbyteone
     L = 0                                                   'this was forgotten in the flight code doh     L = 0                                                   'this was forgotten in the flight code doh
    End If    End If
    If Arrayat > 40 Then    If Arrayat > 40 Then
 +    Print "Altitude cutdown" ; Arrayat
     Goto Cutdownlbl                                         '4Km/20 minute cutdown     Goto Cutdownlbl                                         '4Km/20 minute cutdown
    End If    End If
-   If Timeelapsed > 900 Then+   If Timeelapsed > 1200 Then 
 +    Print "Time cutdown"
     Goto Cutdownlbl     Goto Cutdownlbl
    End If    End If
    Requestsecond = 1    Requestsecond = 1
    While Clearsecond = 0    While Clearsecond = 0
-    Waitus 100+    Waitus 10
    Wend    Wend
    Requestsecond = 0    Requestsecond = 0
-   Print #1 , "#,ascent" +   Waitus 50 
-   Waitus 200 +   Printbin #1 , Statuscode 
-   Input #2 , S+   Waitus 150                                               'tells slave we are going up 
 +   Inputbin #2 , Rate , Temperature , Error
    Incr Telcounter    Incr Telcounter
-   If Telcounter > 10 Then Call Checkvoltage() +   If Telcounter > 10 Then Call Checkvoltage()              ' our callsign is UKHAS
-                                                             ' our callsign is UKHAS+
    If Radiocts = 1 Then                                     'is CTS=1 from the radio modem?    If Radiocts = 1 Then                                     'is CTS=1 from the radio modem?
-    Print "UKHAS" ; Contents(3; Contents(4) ; Contents(5) ; Contents(6) ; Contents(10) ; S+    Call Radiocomms()
    End If    End If
 Loop Loop
  
 Cutdownlbl: Cutdownlbl:
 +If L > 0 Then                                               'set a valid wind for cutdown altitude
 + Wind_x = Windx_total / L
 + Wind_y = Windy_total / L
 +End If
 Call Cutdown(1 , 12) Call Cutdown(1 , 12)
 +Placemark = 2                                               'write eeprom 
 +Descentloop: 
 +Statuscode = 1 
 +Requestsecond = 1 
 +While Clearsecond = 0 
 + Waitus 10                                                  'I did commented this out as we should give the slave a message 1 second before the first valid gps 
 +Wend                                                        'but that was a stupid idea as in the slave code, when if first enters the decent loop 
 +Requestsecond = 0                                           'it waits for a new gps before doing anything other than running off the gyro 
 +Waitus 50                                                   ' the first update after this then goes into the gps lag compensation stage, but NOT YET !!!! 
 +Printbin #1 , Statuscode                                    'we are going down so let the slave know
  
  
 Do Do
 + Reset Watchdog
  'insert  'insert
- While B <> "$GPGGA" +    Do 
-  Input R +     Input U 
-  B = Mid(, 2 , 6) +     B = Mid(, 2 , 6) 
- Wend +    Loop Until "$GPGGA
- While <> "$GPRMC+    Do 
-  Input S +     Input S 
-  B = Mid(s , 2 , 6) +     B = Mid(s , 2 , 6) 
- Wend+    Loop Until B = "$GPRMC"
    I = Split(s , Contents(1) , ","                        'process rmc    I = Split(s , Contents(1) , ","                        'process rmc
    Degrees = Left(contents(4) , 2)    Degrees = Left(contents(4) , 2)
Line 287: Line 346:
    End If    End If
  'end insert  'end insert
-  I = Split(, Contents(1) , ","                        'now we do the gga+  I = Split(, Contents(1) , ","                         'now we do the gga
   K = Val(contents(10))   K = Val(contents(10))
   Altitude = K   Altitude = K
- If V 0 And Altitude < 200 Then                           'turn servo off on landing + If V 0.5 And Altitude < 250 Then                         'we have landed ? 
-   Servoenable = 0+  Incr Landcount
  Else  Else
-   Servoenable 1 +  Landcount 0 
- End If                                                     'enable ground control near the ground + End If 
- If Altitude < 200 Then + If Landcount > 4 Then 
-   Rxenable = 1+   Landcount = 5                                            'ie we had 5 stationary gps updates 
 +   Incr Flashcount                                          'flashes leds 
 +   If Flashcount > 9 Then 
 +    Cutdownpintwo = 1 
 +    Flashcount = 0 
 +   Else 
 +    Cutdownpintwo = 0                                       'turn off landing lights 
 +   End If 
 +   Servoenable = 0                                          'turn servo off on landing
  Else  Else
-   Rxenable = 0+  If Altitude < 300 Then                                    'so we are moving but low 
 +    Cutdownpintwo = 1                                       'turn on landing lights 
 +    Rxenable = 1                                            'enable ground control near the ground 
 +  Else 
 +    Cutdownpintwo = 0 
 +    Rxenable = 0 
 +  End If 
 +  Flashcount = 0 
 +  Servoenable = 1                                           'always enable servo
  End If  End If
  Requestsecond = 1  Requestsecond = 1
  While Clearsecond = 0  While Clearsecond = 0
-  Waitus 100+  Waitus 10
  Wend  Wend
  Requestsecond = 0  Requestsecond = 0
- Print #1 , "#," ; Gpsheading ; "," ; Target ; "," ; Servoenable ; "," ; Rxenable+ Waitus 50                                                  'make sure slave is ready 
 + Printbin #1 , Statuscode ; Gpsheading ; Target ; Servoenable ; Rxenable
  Waitus 200  Waitus 200
- Input #2 , S+ Inputbin #2 , Rate , Temperature , Error , Heading , Filteredrate , Pulselenght , Pulses
  K = K / 100  K = K / 100
  Arrayat = Int(k)  Arrayat = Int(k)
- Gpbyteone = Windxs(arrayat) - 127 + Incr Arrayat                                               'as minimum altitude incrament=0 but array starts at 1 
- Wind_x = Gpbyteone                                         'gives us the correct wind for our altitude + Gpbyteone = Windxs(arrayat)                                'gives us the correct wind for our altitude 
- Gpbyteone = Windys(arrayat) - 127 + If Gpbyteone <> 255 Then Wind_x = Gpbyteone - 127          'handles an unrecorded eeprom byte 
- Wind_y = Gpbyteone+ Gpbyteone = Windys(arrayat) 
 + If Gpbyteone <> 255 Then Wind_y = Gpbyteone - 127          'handles unrecorded
  Incr Telcounter  Incr Telcounter
  If Telcounter > 10 Then Call Checkvoltage()  If Telcounter > 10 Then Call Checkvoltage()
  If Radiocts = 1 Then                                       'is CTS=1 from the radio modem?  If Radiocts = 1 Then                                       'is CTS=1 from the radio modem?
-  Print "UKHAS" ; Contents(3; Contents(4) ; Contents(5) ; Contents(6) ; Contents(10) ; S+  Call Radiocomms()
  End If  End If
 Loop Loop
  
 Sub Checkvoltage() Sub Checkvoltage()
 +S = "UKHASD,"
 Gpintegerone = Getadc(5) Gpintegerone = Getadc(5)
 Gpfloatone = Gpintegerone Gpfloatone = Gpintegerone
 Gpfloatone = Gpfloatone * 9.503 Gpfloatone = Gpfloatone * 9.503
 Gpfloatone = Gpfloatone / 1000 Gpfloatone = Gpfloatone / 1000
-If Radiocts 1 Then Print "Servo voltage=" ; Gpfloatone ; ",";+Printstring Str(gpfloatone )                              'servo 
 +S + Printstring 
 +S = S + ","
 Gpintegerone = Getadc(0) Gpintegerone = Getadc(0)
-Print Gpintegerone 
 Gpfloatone = Gpintegerone Gpfloatone = Gpintegerone
 Gpfloatone = Gpfloatone * 4.250 Gpfloatone = Gpfloatone * 4.250
 Gpfloatone = Gpfloatone / 1000 Gpfloatone = Gpfloatone / 1000
-If Radiocts 1 Then Print "Supply voltage=" ; Gpfloatone+Printstring Str(gpfloatone ) 
 +S = S + Printstring 
 +S = S + "," 
 +Printstring Str(pulselenght) 
 +S = S + Printstring 
 +S = S + "," 
 +Printstring = Str(pulses) 
 +S = S + Printstring 
 +Print S 
 +Print #4 , S
 Telcounter = 0 Telcounter = 0
 End Sub End Sub
Line 341: Line 429:
 While Radiocts = 0 And Gpbyteone < 30                       'wait for radio with timeout While Radiocts = 0 And Gpbyteone < 30                       'wait for radio with timeout
  Waitms 500  Waitms 500
 + Reset Watchdog
  Incr Gpbyteone  Incr Gpbyteone
 Wend Wend
-Print "Cutdown channel=" ; Channel ; " Time=" ; Duration+Print "UKHASC,Cutdown channel=" ; Channel ; " Time=" ; Duration
 If Channel = 1 Then Cutdownpinone = 1 If Channel = 1 Then Cutdownpinone = 1
 If Channel = 2 Then Cutdownpintwo = 1 If Channel = 2 Then Cutdownpintwo = 1
-Wait Duration+For Gpbyteone = 0 To Duration 
 + Wait 1 
 + Reset Watchdog 
 +Next
 Cutdownpinone = 0 Cutdownpinone = 0
 Cutdownpintwo = 0 Cutdownpintwo = 0
 End Sub End Sub
-</code> 
  
 +Sub Radiocomms()
 + If Statuscode = 0 Then
 +  S = "UKHAS>"
 + Else
 +  S = "UKHAS<"
 + End If
 + S = S + Contents(3)
 + S = S + Contents(4)
 + S = S + Contents(5)
 + S = S + Contents(6)
 + S = S + Contents(10)                                       'nmea data
 + Printstring = Fusing(gpsheading , "#.#")
 + Printstring = "," + Printstring
 + S = S + Printstring
 + Printstring = Fusing(target , "#.#")
 + Printstring = "," + Printstring
 + S = S + Printstring
 + Printstring = Str(rate)
 + Printstring = "," + Printstring
 + S = S + Printstring
 + Printstring = Str(temperature)
 + Printstring = "," + Printstring
 + S = S + Printstring
 + Printstring = Str(error)
 + Printstring = "," + Printstring
 + S = S + Printstring
 + Printstring = Fusing(heading , "#.#")
 + Printstring = "," + Printstring
 + S = S + Printstring
 + Printstring = Fusing(filteredrate , "#.#")
 + Printstring = "," + Printstring
 + S = S + Printstring
 + Gpbyteone = Checksum(s)
 + S = S + "*"
 + Printstring = Hex(gpbyteone)
 + S = S + Printstring
 + Print S
 + Print #4 , S
 +End Sub
 +</code>
projects/ukhas_glider_project/master.1188988640.txt.gz · Last modified: 2008/07/19 23:32 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki