projects:ukhas_glider_project:slave
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
projects:ukhas_glider_project:slave [2007/09/04 22:10] – created laurenceb | projects:ukhas_glider_project:slave [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 = 64 |
- | $swstack = 40 | + | $swstack = 64 |
- | $framesize = 40 | + | $framesize = 64 |
- | Open "comc.4: | + | Const Servogain = 10 |
- | Open "comc.3: | + | Const Pterm = -0.25 ' |
- | Open "comd.2:4800,8,n,1" For Input As #3 | + | Const Iterm = -0.0003 |
- | Config Adc = Single , Prescaler | + | Const Dterm = -0.35 |
- | Config Portd.7 = Output | + | Const Kalmangpsweight = 0.5 |
- | Config | + | Const Kalmangyroweight = 0.5 |
- | Config | + | Const Propogation = 0.98 *(1 -kalmangyroweight) |
+ | Const Servocontrolinput = 0.0015 *(1 -kalmangyroweight) | ||
+ | Const Center | ||
+ | Const Conversionfactor | ||
+ | Const Lowerpwm | ||
+ | Const Upperpwm = Center + 300 | ||
+ | Baud = 125000 | ||
+ | Config Portd.4 = Output | ||
+ | Config | ||
+ | Config | ||
Config Portb.1 = Output | Config Portb.1 = Output | ||
- | Config Portd.2 = Input 'rx from pc | ||
- | Config Portd.6 = Output | ||
Config Portd.3 = Input | Config Portd.3 = Input | ||
- | Config | + | Config |
- | Config Portd.4 = Input | + | Config Portd.7 = Input |
- | Config | + | Config |
- | Config Portc.0 = Input | + | Config Portc.4 = Input |
- | Config Portc.5 = Input | + | Config Portc.5 = Output |
- | 'Config Portc.4 = Output | + | Config Portc.2 = Output |
- | 'Config Portc.3 = Input | + | Config Portc.3 = Output |
- | Ledone Alias Portd.7 | + | Config Watchdog = 1024 |
- | Ledtwo Alias Portb.0 | + | 'Config Spi = Soft , Din = Pinc.4 , Dout = Portc.5 , Ss = None , Clock = Portc.2 |
- | Radiocts Alias Pind.3 | + | ' |
- | 'Cts Alias Portd.2 | + | Config Timer1 = Timer , Prescale |
- | Groundcontrol Alias Pind.4 | + | Config Timer0 |
- | Statusled Alias Portd.6 | + | Dim Rate As Integer , Temperature As Integer , Lsb As Byte , Msb As Byte ' |
- | Requestsecond Alias Portc.1 | + | Dim Rateread |
- | Clearsecond Alias Pinc.2 | + | Dim Firstupdate |
- | Cutdownpinone Alias Portb.1 | + | Dim S As Single , R As Single , Gpfloatone As Single , Gpfloattwo |
- | Cutdownpintwo Alias Portb.2 | + | Dim Gpbyteone |
- | Cutdownpinone | + | Dim U As Integer |
- | Cutdownpintwo | + | Dim Gpwordone |
- | Baud = 4800 | + | Rateread = & |
- | Declare Sub Checkvoltage() | + | Tempread = & |
- | Declare Sub Cutdown(byval Channel | + | Readmelexis = & |
- | Echo Off | + | Maskword = & |
- | Start Adc | + | Pcmsk2 = & |
- | Dim S As String * 100 | + | Pcmsk0 = & |
- | Dim T As String * 15 | + | Groundcontrol Alias Portd.4 |
- | Dim K As Single | + | Rts Alias Pind.3 |
- | Dim Iterations | + | Cts Alias Portd.2 |
- | Dim Windxs(256) | + | Servoone Alias Portd.5 |
- | Dim Windys(256) | + | Servotwo Alias Portb.1 |
- | Dim Lock As Bit | + | Pulsesdetect Alias Pind.6 |
- | Dim Gpfloatone As Single , Gpsheading | + | Inputone Alias Pinb.0 |
- | Dim R As String * 90 | + | Inputtwo Alias Pind.7 |
- | Dim B As String * 6 | + | Slave Alias Portc.3 |
- | Dim Contents(17) | + | Din Alias Pinc.4 |
- | Dim Transfer | + | Dout Alias Portc.5 |
- | Dim N As Byte | + | Clock Alias Portc.2 |
- | Dim I As Byte | + | Slave = 1 |
- | Dim Heightupto | + | ' |
- | Dim Gpbyteone | + | Declare Sub Talktomelexis() |
- | Dim Gpintegerone | + | ' |
- | Dim Intcount | + | On Pcint0 Edge |
- | Dim Store As Integer | + | On Pcint2 Copy |
- | Dim Test As Integer | + | Set Pcifr.pcif2 |
- | Dim L As Integer | + | Set Pcifr.pcif0 |
- | Dim Arrayat As Integer | + | Enable Pcint2 |
- | Dim Rudder As Single | + | Enable Pcint0 |
- | Dim Integral As Single | + | Groundcontrol |
- | Dim Derivative As Single | + | Servotwo |
- | Dim Target As Single | + | Servoone |
- | Dim Offset As Single | + | S = 0 |
- | Dim Windy_total As Single | + | Integral |
- | Dim Windx_total As Single | + | For Gpbyteone = 0 To 200 'to let us check servo alignment |
- | Dim Wind_speed As Single | + | Waitms 15 |
- | Dim Airspeed As Single | + | Pulseout |
- | Dim X As Single | + | |
- | Dim Y As Single | + | |
- | Dim V As Single , Altitude As Single | + | |
- | Dim Wind_x As Single | + | |
- | Dim Wind_y As Single | + | |
- | Dim North As Single | + | |
- | Dim East As Single | + | |
- | Dim Target_e As Single | + | |
- | Dim Target_n As Single | + | |
- | Dim Store_east As Single | + | |
- | Dim Store_north As Single | + | |
- | Dim V_x As Single | + | |
- | Dim V_y As Single | + | |
- | Dim Minutes As String * 7 | + | |
- | Dim Degrees As String * 3 | + | |
- | Dim Command As String * 10 | + | |
- | Lock = 0 | + | |
- | Iterations | + | |
- | Timeelapsed | + | |
- | Wind_x | + | |
- | Wind_y | + | |
- | Waitms 500 | + | |
- | Call Checkvoltage() | + | |
- | Waitms 500 | + | |
- | 'Call Cutdown(1 , 4) | + | |
- | Print "wind records:" | + | |
- | For Gpbyteone = 1 To 255 | + | |
- | Gpbytetwo = Windxs(gpbyteone) | + | |
- | Print Gpbyteone ; "," ; Gpbytetwo ; "," | + | |
- | | + | |
- | Print Gpbytetwo | + | |
Next | Next | ||
- | Print Version() | + | Start Timer1 |
- | Print "Demo flight: 4km/20 minute" | + | Start Timer0 |
- | Print "Now check gps" | + | Enable Interrupts |
+ | Start Watchdog | ||
Do | Do | ||
- | Input S | + | Reset Watchdog |
- | B = Mid(s , 2 , 6) | + | Waitms 15 |
- | | + | |
- | | + | Incr Pulses |
- | | + | |
- | | + | Pulses |
- | | + | Groundcontrol = 0 |
- | If K <> 0 Then ' | + | End If |
- | | + | If Pulses > 10 Then |
+ | | ||
+ | | ||
+ | End If | ||
+ | If Groundcontrol = 0 Then | ||
+ | Servoone | ||
+ | Pulseout | ||
+ | End If | ||
+ | Call Talktomelexis() 'check gyro | ||
+ | If Rts = 1 Then 'check for comms | ||
+ | | ||
+ | Cts = 1 | ||
+ | | ||
+ | Cts = 0 | ||
+ | If Gpbyteone = 1 Then | ||
+ | Firstupdate = 2 'means we treat the first gps update correctly | ||
+ | | ||
+ | Printbin Rate ; Temperature ; Error ; Heading ; Filteredrate ; Pulselenght ; Pulses | ||
+ | | ||
+ | End If | ||
+ | Waitus 300 | ||
+ | Printbin Rate ; Temperature ; Error | ||
+ | Servoone = 1 | ||
+ | Incr Servoexcitecount | ||
+ | If Servoexcitecount > 10 Then | ||
+ | | ||
+ | For Gpbyteone = 0 To 10 | ||
+ | Pulseout , Portd , 5 , Lowerpwm | ||
+ | Waitms 15 | ||
+ | | ||
+ | For Gpbyteone = 0 To 10 | ||
+ | Pulseout , Portd , 5 , Upperpwm | ||
+ | Waitms 15 | ||
+ | Next | ||
End If | End If | ||
End If | End If | ||
- | Loop | ||
- | Gotlock: | ||
- | Print "Okay we have GPS" | ||
- | Print "Enter target north and east" | ||
- | Input #3 , Target_n | ||
- | Print Target_n | ||
- | Input #3 , Target_e | ||
- | Print Target_e | ||
- | Print " | ||
- | Do | ||
- | While B <> " | ||
- | Input R | ||
- | B = Mid(r , 2 , 6) | ||
- | Wend | ||
- | While B <> " | ||
- | Input S | ||
- | B = Mid(s , 2 , 6) | ||
- | Wend | ||
- | I = Split(s , Contents(1) , "," | ||
- | K = Val(contents(9)) | ||
- | V = Val(contents(8)) | ||
- | K = Deg2rad(k) | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | Incr L ' | ||
- | Incr Timeelapsed | ||
- | I = Split(r , Contents(1) , "," | ||
- | K = Val(contents(10)) | ||
- | K = K / 100 | ||
- | | ||
- | If Arrayat > Heightupto Then | ||
- | Incr Heightupto | ||
- | Windx_total = Windx_total / L | ||
- | Gpbyteone = Windx_total + 127 | ||
- | Windxs(arrayat) = Gpbyteone | ||
- | Windy_total = Windy_total / L | ||
- | Gpbyteone = Windy_total + 127 ' | ||
- | Windys(arrayat) = Gpbyteone | ||
- | L = 0 ' | ||
- | End If | ||
- | If Arrayat > 40 Then | ||
- | Goto Cutdownlbl | ||
- | End If | ||
- | If Timeelapsed > 900 Then | ||
- | Goto Cutdownlbl | ||
- | End If | ||
- | | ||
- | While Clearsecond = 0 | ||
- | Waitus 100 | ||
- | Wend | ||
- | | ||
- | Print #1 , "#, | ||
- | | ||
- | Input #2 , S | ||
- | Incr Telcounter | ||
- | If Telcounter > 10 Then Call Checkvoltage() | ||
- | ' | ||
- | If Radiocts = 1 Then ' | ||
- | Print " | ||
- | End If | ||
Loop | Loop | ||
- | Cutdownlbl: | + | Descent: |
- | Call Cutdown(1 , 12) | + | |
- | + | ||
- | + | ||
Do | Do | ||
- | ' | + | Reset Watchdog |
- | | + | |
- | Input R | + | |
- | B = Mid(r , 2 , 6) | + | |
- | | + | |
- | While B <> " | + | |
- | Input S | + | |
- | B = Mid(s , 2 , 6) | + | |
Wend | Wend | ||
- | I = Split(s , Contents(1) , "," | + | Reset Timer0 |
- | | + | |
- | | + | |
- | North = 0 | + | |
- | North = Val(minutes) | + | |
- | North = North / 60 | + | |
- | K = 0 | + | |
- | K = Val(degrees) | + | |
- | North = K + North | + | |
- | | + | |
- | | + | |
- | East = 0 | + | |
- | East = Val(minutes) | + | |
- | East = East / 60 | + | |
- | K = 0 | + | |
- | K = Val(degrees) | + | |
- | East = K + East | + | |
- | If Contents(7) = " | + | |
- | East = -east | + | |
- | End If | + | |
- | East = Target_e - East | + | |
- | K = Deg2rad(north) | + | |
- | K = Cos(k) | + | |
- | East = East * K ' | + | |
- | North = Target_n - North | + | |
- | K = East / North | + | |
- | | + | |
- | | + | |
- | If North < 0 Then ' | + | |
- | Target = Target - 180 | + | |
- | End If | + | |
- | If Target < -180 Then | + | |
- | Target = Target + 360 ' | + | |
- | End If | + | |
- | K = 0 | + | |
- | K = Val(contents(9)) | + | |
- | V = 0 | + | |
- | V = Val(contents(8)) | + | |
- | If V < 0.5 Then 'off if we crashed | + | |
- | If V = 0 Then | + | |
- | V = 0.01 | + | |
- | End If | + | |
- | Statusled = 0 | + | |
- | | + | |
- | 'Incr Timeelapsed | + | |
- | Toggle Statusled | + | |
- | End If | + | |
- | K = Deg2rad(k) | + | |
- | X = Sin(k) | + | |
- | X = X * V | + | |
- | Y = Cos(k) | + | |
- | Y = Y * V | + | |
- | X = X - Wind_x | + | |
- | Y = Y - Wind_y | + | |
- | | + | |
- | K = Y * Y | + | |
- | | + | |
- | | + | |
- | If Y = 0 Then | + | |
- | X = 0 | + | |
- | Else | + | |
- | X = X / Y ' | + | |
- | End If | + | |
- | K = Atn(x) | + | |
- | K = Rad2deg(k) | + | |
- | If Y < 0 Then | + | |
- | K = K - 180 | + | |
- | End If ' | + | |
- | If K < -180 Then | + | |
- | K = K + 360 'K is now our air vector heading | + | |
- | End If | + | |
- | | + | |
- | K = K - Target | + | |
- | If K < -180 Then ' | + | |
- | K = K + 360 | + | |
- | End If | + | |
- | If K > 180 Then | + | |
- | K = K - 360 | + | |
- | End If | + | |
- | If K > 0 Then | + | |
- | Ledone = 0 ' | + | |
- | Ledtwo = 1 | + | |
- | | + | |
- | Ledone = 1 | + | |
- | Ledtwo = 0 | + | |
- | End If | + | |
- | ' | + | |
- | | + | |
- | K = Val(contents(10)) | + | |
- | Altitude = K | + | |
- | If V = 0 And Altitude < 200 Then ' | + | |
- | | + | |
Else | Else | ||
- | | + | |
- | End If ' | + | |
- | If Altitude < 200 Then | + | |
- | | + | |
- | Else | + | |
- | | + | |
End If | End If | ||
- | Requestsecond = 1 | + | |
- | While Clearsecond = 0 | + | |
- | Waitus 100 | + | |
- | | + | |
- | | + | |
- | Print #1 , "#," | + | |
- | | + | |
- | Input #2 , S | + | |
- | K = K / 100 | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | Incr Telcounter | + | |
- | If Telcounter | + | |
- | If Radiocts | + | |
- | | + | |
End If | End If | ||
+ | If Rts = 1 Then ' | ||
+ | Cts = 1 | ||
+ | | ||
+ | Cts = 0 | ||
+ | If Firstupdate = 0 Or Firstupdate = 1 Then ' | ||
+ | Gpfloatone = Gpsheading - Oldheading | ||
+ | If Gpfloatone < -180 Then ' | ||
+ | | ||
+ | End If | ||
+ | If Gpfloatone > 180 Then | ||
+ | | ||
+ | End If | ||
+ | If Firstupdate = 0 Then | ||
+ | | ||
+ | Else 'if firstupdate=1, | ||
+ | | ||
+ | End If | ||
+ | Heading = Heading + Gpfloatone | ||
+ | If Heading > 180 Then ' | ||
+ | | ||
+ | End If | ||
+ | If Heading < -180 Then | ||
+ | | ||
+ | End If | ||
+ | | ||
+ | Targetheading = 0 ' | ||
+ | Firstupdate = 1 ' | ||
+ | End If | ||
+ | | ||
+ | If Enablegroundcontrol = 1 Then ' | ||
+ | Enable Interrupts | ||
+ | Else | ||
+ | Disable Interrupts | ||
+ | End If | ||
+ | | ||
+ | | ||
+ | End If | ||
+ | Call Talktomelexis() | ||
+ | Gpintegerone = Rate | ||
+ | Gpintegerone = Gpintegerone - 1009 ' | ||
+ | Gpfloatone = Gpintegerone | ||
+ | Gpfloatone = Gpfloatone / 6.8265 | ||
+ | Realrate = Gpfloatone | ||
+ | Gpfloatone = Gpfloatone * Kalmangyroweight | ||
+ | Filteredrate = Propogation * Filteredrate | ||
+ | Filteredrate = Filteredrate + Gpfloatone | ||
+ | Gpfloatone = Servo * Servocontrolinput | ||
+ | Filteredrate = Filteredrate + Gpfloatone | ||
+ | Gpfloatone = Filteredrate / 62.5 ' | ||
+ | Heading = Heading + Gpfloatone | ||
+ | If Heading > 180 Then ' | ||
+ | | ||
+ | End If | ||
+ | If Heading < -180 Then | ||
+ | | ||
+ | End If | ||
+ | Gpfloatone = Heading - Targetheading | ||
+ | If Gpfloatone < -180 Then ' | ||
+ | | ||
+ | End If | ||
+ | If Gpfloatone > 180 Then | ||
+ | | ||
+ | End If | ||
+ | Integral = Integral + Gpfloatone | ||
+ | Gpfloattwo = Gpfloatone * Pterm ' | ||
+ | Gpfloatone = Dterm * Filteredrate | ||
+ | Gpfloatone = Gpfloatone + Gpfloattwo | ||
+ | If Gpfloatone > 30 Then Gpfloatone = 30 ' | ||
+ | If Gpfloatone < -30 Then Gpfloatone = -30 | ||
+ | Gpfloattwo = Integral * Iterm ' | ||
+ | If Gpfloattwo > 25 Then Integral = 25 / Iterm ' | ||
+ | If Gpfloattwo < -25 Then Integral = -25 / Iterm | ||
+ | Gpfloatone = Gpfloatone + Gpfloattwo | ||
+ | Gpfloatone = Servogain * Gpfloatone | ||
+ | Servo = Gpfloatone | ||
+ | Gpintegerone = Gpfloatone | ||
+ | If Groundcontrol = 1 Then | ||
+ | | ||
+ | Servo = Gpfloatone - Center | ||
+ | End If | ||
+ | Gpintegerone = Gpintegerone + Center | ||
+ | If Groundcontrol = 0 And Servoenable = 1 Then | ||
+ | | ||
+ | | ||
+ | End If | ||
Loop | Loop | ||
- | Sub Checkvoltage() | + | Edge: |
- | Gpintegerone = Getadc(5) | + | If Groundcontrol |
- | Gpfloatone = Gpintegerone | + | If Inputone |
- | Gpfloatone = Gpfloatone * 9.503 | + | Pulselenght |
- | Gpfloatone = Gpfloatone / 1000 | + | End If |
- | If Radiocts | + | Timer1 |
- | Gpintegerone | + | Return |
- | Print Gpintegerone | + | |
- | Gpfloatone | + | |
- | Gpfloatone = Gpfloatone * 4.250 | + | |
- | Gpfloatone = Gpfloatone / 1000 | + | |
- | If Radiocts = 1 Then Print " | + | |
- | Telcounter | + | |
- | End Sub | + | |
+ | Copy: | ||
+ | If Groundcontrol = 1 Then Servotwo = Not Inputtwo | ||
+ | Return | ||
- | Sub Cutdown(byval Channel As Byte , Byval Duration As Byte) | + | Sub Talktomelexis() |
- | Gpbyteone = 0 | + | Clock = 0 |
- | While Radiocts | + | Dout = 0 |
- | Waitms 500 | + | Slave = 0 |
- | Incr Gpbyteone | + | Error = 0 |
- | Wend | + | |
- | Print " | + | |
- | If Channel | + | Dout = Rateread.gpbyteone |
- | If Channel | + | Waitus 1 |
- | Wait Duration | + | Clock = 1 |
- | Cutdownpinone | + | Waitus 1 |
- | Cutdownpintwo | + | Clock = 0 |
+ | | ||
+ | | ||
+ | | ||
+ | Clock = 1 | ||
+ | Waitus 1 | ||
+ | Clock = 0 | ||
+ | | ||
+ | | ||
+ | Slave = 1 | ||
+ | | ||
+ | Slave = 0 | ||
+ | | ||
+ | Dout = Readmelexis.gpbyteone | ||
+ | | ||
+ | Clock = 1 | ||
+ | Waitus 1 | ||
+ | Clock = 0 | ||
+ | Next | ||
+ | For Gpbyteone | ||
+ | Waitus 1 | ||
+ | Clock = 1 | ||
+ | Msb.gpbyteone = Din | ||
+ | Waitus 1 | ||
+ | Clock = 0 | ||
+ | | ||
+ | For Gpbyteone = 7 To 0 Step -1 ' | ||
+ | Waitus 1 | ||
+ | Clock = 1 | ||
+ | Lsb.gpbyteone = Din | ||
+ | Waitus 1 | ||
+ | Clock = 0 | ||
+ | | ||
+ | | ||
+ | Slave = 1 | ||
+ | Rate = Makeint(lsb , Msb) ' | ||
+ | Rate = Rate And Maskword | ||
+ | Shift Rate , Right , 1 ' | ||
+ | | ||
+ | Slave = 0 | ||
+ | Waitus 1 | ||
+ | For Gpbyteone | ||
+ | Dout = Tempread.gpbyteone | ||
+ | Waitus 1 | ||
+ | Clock = 1 | ||
+ | Waitus 1 | ||
+ | Clock = 0 | ||
+ | | ||
+ | For Gpbyteone = 15 To 0 Step -1 | ||
+ | Waitus 1 | ||
+ | Clock = 1 | ||
+ | Waitus 1 | ||
+ | Clock = 0 | ||
+ | | ||
+ | | ||
+ | Slave = 1 | ||
+ | | ||
+ | Slave = 0 | ||
+ | For Gpbyteone = 7 To 0 Step -1 | ||
+ | Dout = Readmelexis.gpbyteone | ||
+ | Waitus 1 | ||
+ | Clock = 1 | ||
+ | Waitus 1 | ||
+ | Clock = 0 | ||
+ | | ||
+ | For Gpbyteone = 7 To 0 Step -1 | ||
+ | Waitus 1 | ||
+ | Clock = 1 | ||
+ | Msb.gpbyteone = Din | ||
+ | Waitus 1 | ||
+ | Clock = 0 | ||
+ | | ||
+ | For Gpbyteone = 7 To 0 Step -1 | ||
+ | Waitus 1 | ||
+ | Clock = 1 | ||
+ | Lsb.gpbyteone = Din | ||
+ | Waitus 1 | ||
+ | Clock = 0 | ||
+ | | ||
+ | | ||
+ | Slave = 1 | ||
+ | | ||
+ | If Msb.6 = 1 Then Error = 1 | ||
+ | | ||
+ | Shift Temperature , Right , 1 | ||
End Sub | End Sub | ||
</ | </ | ||
+ |
projects/ukhas_glider_project/slave.1188943852.txt.gz · Last modified: 2008/07/19 23:32 (external edit)