projects:ukhas_glider_project:slave
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
projects:ukhas_glider_project:slave [2007/09/05 10:45] – laurenceb | projects:ukhas_glider_project:slave [2008/07/19 23:33] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 7: | Line 7: | ||
$framesize = 64 | $framesize = 64 | ||
Const Servogain = 10 | Const Servogain = 10 | ||
- | Const Pterm = 1 'needs to be -1 here? as gyro will be chip facing up, not down | + | Const Pterm = -0.25 'all -ive as a +ive pulse lenght causes +ive turn |
- | Const Iterm = 0.001 | + | Const Iterm = -0.0003 |
- | Const Dterm = 0 | + | Const Dterm = -0.35 |
- | Const Kalmangpsweight = 1 | + | Const Kalmangpsweight = 0.5 |
- | const kalmangyroweight=0.05 | + | Const Kalmangyroweight |
- | const propogation=0.98*(1-kalmangyroweight) | + | Const Propogation |
- | const servogain=-0.007*(1-kalmangyroweight) | + | Const Servocontrolinput |
- | Const Center = 6000 'needs to be checked with servo | + | Const Center = 6200 'needs to be checked with servo |
+ | Const Conversionfactor = 16 ' | ||
+ | Const Lowerpwm = Center - 300 | ||
+ | Const Upperpwm = Center + 300 | ||
Baud = 125000 | Baud = 125000 | ||
Config Portd.4 = Output | Config Portd.4 = Output | ||
Line 28: | Line 31: | ||
Config Portc.2 = Output | Config Portc.2 = Output | ||
Config Portc.3 = Output | Config Portc.3 = Output | ||
+ | Config Watchdog = 1024 | ||
' | ' | ||
' | ' | ||
Line 34: | Line 38: | ||
Dim Rate As Integer , Temperature As Integer , Lsb As Byte , Msb As Byte ' | Dim Rate As Integer , Temperature As Integer , Lsb As Byte , Msb As Byte ' | ||
Dim Rateread As Byte , Tempread As Byte , Readmelexis As Byte , Mask As Word , Maskword As Word , Servoenable As Byte | Dim Rateread As Byte , Tempread As Byte , Readmelexis As Byte , Mask As Word , Maskword As Word , Servoenable As Byte | ||
- | Dim T As String * 30 | + | Dim Firstupdate |
- | Dim Contents(5) As String * 20 | + | Dim S As Single , R As Single , Gpfloatone As Single , Gpfloattwo As Single , Oldheading As Single , Realrate As Single , Integral As Single , Filteredrate As Single |
- | Dim S As Single , R As Single , Gpfloatone As Single , Gpfloattwo As Single , Oldheading As Single , Realrate As Single , Integral As Single,filteredrate as single, servo as single | + | Dim Gpbyteone As Byte , Pulses As Byte , Error As Byte , Enablegroundcontrol |
- | Dim Gpbyteone As Byte , Pulses As Byte , Timeout | + | |
Dim U As Integer , Gpintegerone As Integer , Targetheading As Single , Gpsheading As Single , Heading As Single | Dim U As Integer , Gpintegerone As Integer , Targetheading As Single , Gpsheading As Single , Heading As Single | ||
Dim Gpwordone As Word , Pulselenght As Word | Dim Gpwordone As Word , Pulselenght As Word | ||
Line 61: | Line 64: | ||
' | ' | ||
Declare Sub Talktomelexis() | Declare Sub Talktomelexis() | ||
- | Declare Sub Ascent() | + | 'Declare Sub Ascent() |
- | On Pcint2 | + | On Pcint0 |
- | On Pcint0 | + | On Pcint2 |
Set Pcifr.pcif2 | Set Pcifr.pcif2 | ||
Set Pcifr.pcif0 | Set Pcifr.pcif0 | ||
Enable Pcint2 | Enable Pcint2 | ||
Enable Pcint0 | Enable Pcint0 | ||
+ | Groundcontrol = 0 | ||
Servotwo = 1 | Servotwo = 1 | ||
Servoone = 1 | Servoone = 1 | ||
S = 0 | S = 0 | ||
+ | Integral = 0 | ||
+ | For Gpbyteone = 0 To 200 'to let us check servo alignment | ||
+ | | ||
+ | | ||
+ | Next | ||
Start Timer1 | Start Timer1 | ||
Start Timer0 | Start Timer0 | ||
Enable Interrupts | Enable Interrupts | ||
- | Wait 2 | + | Start Watchdog |
Do | Do | ||
- | | + | Reset Watchdog |
- | | + | |
- | While Timer0 < 250 | + | If Pulselenght > 200 And Pulselenght < 600 And Timer1 < 20000 Then ' |
+ | | ||
+ | Else | ||
+ | Pulses = 0 | ||
+ | Groundcontrol = 0 | ||
+ | | ||
+ | If Pulses | ||
+ | Groundcontrol | ||
+ | Pulses = 10 | ||
+ | End If | ||
+ | If Groundcontrol = 0 Then | ||
+ | Servoone = 1 | ||
+ | Pulseout , Portd , 5 , Center | ||
+ | End If | ||
+ | Call Talktomelexis() | ||
+ | If Rts = 1 Then 'check for comms | ||
+ | Disable Interrupts | ||
+ | Cts = 1 | ||
+ | Inputbin Gpbyteone | ||
+ | Cts = 0 | ||
+ | If Gpbyteone = 1 Then ' | ||
+ | Firstupdate = 2 ' | ||
+ | Waitus 300 | ||
+ | Printbin Rate ; Temperature ; Error ; Heading ; Filteredrate ; Pulselenght ; Pulses | ||
+ | Goto Descent | ||
+ | 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 | ||
+ | | ||
+ | End If | ||
+ | End If | ||
+ | Loop | ||
+ | |||
+ | Descent: | ||
+ | Do | ||
+ | Reset Watchdog | ||
+ | While Timer0 < 250 'wait for 16ms to elapse | ||
Wend | Wend | ||
Reset Timer0 | Reset Timer0 | ||
- | If Pulselenght > 250 And Pulselenght < 500 And Timer1 < 20000 Then | + | If Pulselenght > 200 And Pulselenght < 600 And Timer1 < 20000 Then 'a valid and recent pulse |
Incr Pulses | Incr Pulses | ||
Else | Else | ||
Line 95: | Line 150: | ||
If Rts = 1 Then ' | If Rts = 1 Then ' | ||
Cts = 1 | Cts = 1 | ||
- | Input T | + | Inputbin Gpbyteone , Gpsheading , Targetheading , Servoenable , Enablegroundcontrol |
Cts = 0 | Cts = 0 | ||
- | Gpbyteone = Split(t , Contents(1) , "," | + | |
- | If Gpbyteone | + | Gpfloatone = Gpsheading - Oldheading |
- | | + | If Gpfloatone < -180 Then ' |
- | If Timeout < 80 Then | + | |
- | Gpsheading = Val(t) | + | |
- | Gpfloatone = Gpsheading - Oldheading | + | |
- | If Gpfloatone < -180 Then | + | |
- | | + | |
End If | End If | ||
If Gpfloatone > 180 Then | If Gpfloatone > 180 Then | ||
- | | + | |
+ | End If | ||
+ | If Firstupdate = 0 Then | ||
+ | | ||
+ | Else 'if firstupdate=1, | ||
+ | | ||
End If | End If | ||
- | Gpfloatone = Kalmangpsweight * Gpfloatone | ||
Heading = Heading + Gpfloatone | Heading = Heading + Gpfloatone | ||
+ | If Heading > 180 Then ' | ||
+ | | ||
+ | End If | ||
+ | If Heading < -180 Then | ||
+ | | ||
+ | End If | ||
+ | | ||
+ | Targetheading = 0 ' | ||
+ | Firstupdate = 1 ' | ||
End If | End If | ||
- | | + | |
- | | + | |
- | T = Contents(3) | + | |
- | | + | |
- | T = Contents(4) | + | |
- | | + | |
- | T = Contents(5) | + | |
- | | + | |
- | | + | |
Enable Interrupts | Enable Interrupts | ||
Else | Else | ||
Line 126: | Line 183: | ||
End If | End If | ||
| | ||
- | Print "#," | + | Printbin |
End If | End If | ||
Call Talktomelexis() | Call Talktomelexis() | ||
Gpintegerone = Rate | Gpintegerone = Rate | ||
- | Gpintegerone = Gpintegerone - 1018 | + | Gpintegerone = Gpintegerone - 1009 ' |
Gpfloatone = Gpintegerone | Gpfloatone = Gpintegerone | ||
- | Gpfloatone = Gpfloatone / 13.653 | + | Gpfloatone = Gpfloatone / 6.8265 |
Realrate = Gpfloatone | Realrate = Gpfloatone | ||
- | gpfloatone=gpfloatone*kalmangyroweight | + | Gpfloatone |
- | filteredrate=propogation*filteredrate | + | Filteredrate |
- | filteredrate=filteredrate+gpfloatone | + | Filteredrate |
- | gpfloatone=servo*servogain | + | Gpfloatone |
- | filteredrate=filteredrate+gpfloatone | + | Filteredrate |
- | gpfloatone=filteredrate/62.5 | + | Gpfloatone |
- | Heading = Heading + gpfloatone | + | Heading = Heading + Gpfloatone |
- | If Heading > 360 Then | + | If Heading > 180 Then 'get heading in correct range |
| | ||
End If | End If | ||
- | If Heading < 0 Then | + | If Heading < -180 Then |
| | ||
End If | End If | ||
- | Gpfloatone = Targetheading - Heading | + | Gpfloatone = Heading |
- | If Gpfloatone < -180 Then | + | If Gpfloatone < -180 Then 'get it in the right range |
| | ||
End If | End If | ||
Line 154: | Line 211: | ||
| | ||
End If | End If | ||
- | Gpfloattwo = Gpfloatone * Pterm | + | Integral = Integral + Gpfloatone |
- | Realrate | + | Gpfloattwo = Gpfloatone * Pterm 'P |
- | Integral | + | Gpfloatone |
- | Gpfloatone = Integral * Iterm | + | Gpfloatone |
- | If Gpfloatone | + | If Gpfloatone > 30 Then Gpfloatone |
- | If Gpfloatone | + | If Gpfloatone < -30 Then Gpfloatone = -30 |
- | Gpfloatone = Gpfloatone + Realrate | + | Gpfloattwo |
- | Gpfloatone = Gpfloatone + Gpfloattwo | + | If Gpfloattwo |
- | Gpfloatone = Servogain * Gpfloatone | + | If Gpfloattwo |
- | If Gpfloatone > 500 Then Gpfloatone = 500 'limits | + | Gpfloatone = Gpfloatone + Gpfloattwo |
- | If Gpfloatone | + | Gpfloatone = Servogain * Gpfloatone |
- | servo=gpfloatone | + | Servo = Gpfloatone |
Gpintegerone = Gpfloatone | Gpintegerone = Gpfloatone | ||
- | Gpintegerone = Gpintegerone + Center | + | If Groundcontrol = 1 Then |
- | Portd.5 = 1 | + | |
- | If Groundcontrol = 0 And Servoenable = 1 Then Pulseout , Portd , 5 , Gpintegerone | + | Servo = Gpfloatone - Center |
+ | End If | ||
+ | Gpintegerone = Gpintegerone + Center | ||
+ | If Groundcontrol = 0 And Servoenable = 1 Then | ||
+ | | ||
+ | Pulseout , Portd , 5 , Gpintegerone | ||
+ | End If | ||
Loop | Loop | ||
Edge: | Edge: | ||
- | If Groundcontrol = 1 Then Servotwo | + | If Groundcontrol = 1 Then Servoone |
- | If Inputtwo | + | If Inputone |
- | | + | |
End If | End If | ||
Timer1 = 0 | Timer1 = 0 | ||
Line 181: | Line 244: | ||
Copy: | Copy: | ||
- | If Groundcontrol = 1 Then Servoone | + | If Groundcontrol = 1 Then Servotwo |
Return | Return | ||
- | |||
- | Sub Ascent() | ||
- | Integral = 0 'reset integral | ||
- | Waitus 250 | ||
- | Print "#," | ||
- | Do | ||
- | | ||
- | | ||
- | Call Talktomelexis() | ||
- | If Rts = 1 Then 'check for comms | ||
- | Cts = 1 | ||
- | Input T | ||
- | Cts = 0 | ||
- | Gpbyteone = Split(t , Contents(1) , "," | ||
- | If Gpbyteone > 2 Then Exit Sub | ||
- | Waitus 250 | ||
- | Print "#," | ||
- | Portd.5 = 1 | ||
- | For Gpbyteone = 0 To 10 | ||
- | | ||
- | | ||
- | Next | ||
- | For Gpbyteone = 0 To 10 | ||
- | | ||
- | | ||
- | Next | ||
- | End If | ||
- | Loop | ||
- | End Sub | ||
- | |||
- | |||
- | 'Sub Ground() | ||
- | ' | ||
- | 'While Timer1 < 20000 And Pulselenght > 200 And Pulselenght < 600 | ||
- | ' | ||
- | ' | ||
- | 'Wend | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | 'End Sub | ||
- | |||
- | |||
Sub Talktomelexis() | Sub Talktomelexis() | ||
Line 233: | Line 253: | ||
Error = 0 | Error = 0 | ||
| | ||
- | For Gpbyteone = 7 To 0 Step -1 | + | For Gpbyteone = 7 To 0 Step -1 'spi out |
Dout = Rateread.gpbyteone | Dout = Rateread.gpbyteone | ||
Waitus 1 | Waitus 1 | ||
Line 240: | Line 260: | ||
Clock = 0 | Clock = 0 | ||
Next | Next | ||
- | For Gpbyteone = 15 To 0 Step -1 | + | For Gpbyteone = 15 To 0 Step -1 ' |
Waitus 1 | Waitus 1 | ||
Clock = 1 | Clock = 1 | ||
Line 250: | Line 270: | ||
| | ||
Slave = 0 | Slave = 0 | ||
- | For Gpbyteone = 7 To 0 Step -1 | + | For Gpbyteone = 7 To 0 Step -1 'spi out |
Dout = Readmelexis.gpbyteone | Dout = Readmelexis.gpbyteone | ||
Waitus 1 | Waitus 1 | ||
Line 257: | Line 277: | ||
Clock = 0 | Clock = 0 | ||
Next | Next | ||
- | For Gpbyteone = 7 To 0 Step -1 | + | For Gpbyteone = 7 To 0 Step -1 'data in |
Waitus 1 | Waitus 1 | ||
Clock = 1 | Clock = 1 | ||
Line 264: | Line 284: | ||
Clock = 0 | Clock = 0 | ||
Next | Next | ||
- | For Gpbyteone = 7 To 0 Step -1 | + | For Gpbyteone = 7 To 0 Step -1 ' |
Waitus 1 | Waitus 1 | ||
Clock = 1 | Clock = 1 | ||
Line 273: | Line 293: | ||
| | ||
Slave = 1 | Slave = 1 | ||
- | Rate = Makeint(lsb , Msb) | + | Rate = Makeint(lsb , Msb) ' |
- | Rate = Rate And Maskword | + | Rate = Rate And Maskword |
- | Shift Rate , Right , 1 | + | Shift Rate , Right , 1 'shift it |
- | If Msb.6 = 1 Then Error = 1 | + | If Msb.6 = 1 Then Error = 1 ' |
Slave = 0 | Slave = 0 | ||
| | ||
- | For Gpbyteone = 7 To 0 Step -1 | + | For Gpbyteone = 7 To 0 Step -1 'do the same sort of thing for temp |
Dout = Tempread.gpbyteone | Dout = Tempread.gpbyteone | ||
Waitus 1 | Waitus 1 |
projects/ukhas_glider_project/slave.1188989134.txt.gz · Last modified: 2008/07/19 23:32 (external edit)