Σάββατο 7 Νοεμβρίου 2009

Ιδιοκατασκευή tracking controller. How to part 3.

Όσον αφορά τον κώδικα που τρέχει στον μικροελεγκτή έχει γραφτεί σε γλώσσα Bascom η οποία είναι βασικά ένα είδος Basic για χρήση σε μικροελεγκτές AVR. Η συγγραφή ενός προγράμματος είναι παιχνίδι! Ο γραφών χωρίς να έχει καμιά προηγούμενη εμπειρία σε προγραμματισμό μικροελεγκτών έγραψε την πρώτη έκδοση του κώδικα μέσα σε δύο απογεύματα.
Η δυνατότητες που μας δίνει ο κώδικας είναι :
1) Καλιμπράρισμα και ρυθμίσεις ανεξάρτητα για το αζιμούθιο και την ανύψωση.
2)Αυτόματη ιχνηλάτηση δορυφόρου από τον υπολογιστή.
3)Χειροκίνητη μετακίνηση των κεραιών.
Όσον αφορά το πρώτο έχουμε την δυνατότητα εκτός από το καλιμπράρισμα των ορίων περιστροφής του ρότορα (360 και 90 μοίρες για το αζιμούθιο και την ανύψωση αντίστοιχα) να ρυθμίσουμε το threshold (δηλ. όριο σε μοίρες του σφάλματος στόχευσης των κεραιών σε σχέση με τον δορυφόρο πέραν του οποίου θα αρχίσουν να κινούνται) και το overshot (δηλ. πόσες μοίρες κινείται το κεραιοσυστημα μετά την διακοπή τροφοδοσίας των ρότορων λόγω αδράνειας, συνήθως αμελητέο) του κεραιοσυστήματος μας έτσι ώστε να αποφύγουμε ταλαντώσεις και να βελτιώσουμε ταυτόχρονα την ακρίβεια στόχευσης των κεραιών.
Στην αυτόματη στόχευση ο υπολογιστής τα αναλαμβάνει όλα και εμείς χαζεύουμε τις κεραίες στην ταράτσα παρέα με ένα καφεδάκι.
Στην χειροκίνητη στόχευση μπορούμε μέσω του πληκτρολογίου να μετακινήσουμε τις κεραίες κρατώντας πατημένο το αντίστοιχο πλήκτρο ή να εισάγουμε μια τιμή σε μοίρες και οι κεραίες μας να γυρίσουν χωρίς να κουράζουμε το δάχτυλο μας.
Παρτε και ένα σεντόνι με τον πηγαίο κώδικα:

'sat controller
$regfile = "m16def.dat"
$crystal = 1000000
$baud = 1200
Config Adc = Single , Prescaler = Auto , Reference = Internal
Config Lcdpin = Pin , Db4 = Portb.3 , Db5 = Portb.4 , Db6 = Portb.5 , Db7 = Portb.6 , E = Portb.2 , Rs = Portb.1
Config Lcd = 20 * 4
Config Pina.2 = Output
Config Pina.3 = Output
Config Pina.4 = Output
Config Pina.5 = Output
Config Pina.0 = Input
Config Pina.1 = Input
Config Pinc.0 = Input
Config Pinc.1 = Input
Config Pinc.2 = Input
Config Pinc.3 = Input
Config Pinc.4 = Input
Config Pinc.5 = Input
Config Pinc.6 = Input
Config Pinc.7 = Input
Config Pind.2 = Input
Config Pind.3 = Input
Config Pind.4 = Input
Config Pind.5 = Input
Config Pind.6 = Input
Config Pind.7 = Input
Dim Az_min As Eram Integer At 14 , Az_max As Eram Integer At 16 , El_min As Eram Integer At 18 , El_max As Eram Integer At 20
Dim Az_threshold As Eram Integer At 22 , El_threshold As Eram Integer At 24
Dim Az_overshot As Eram Integer At 26 , El_overshot As Eram Integer At 28
Dim Az As Integer
Dim El As Integer
Dim Null As Integer
Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim D As Integer
Dim I As Integer
Dim Flag As Integer
Dim Adc_az As Integer
Dim Adc_el As Integer
Dim Temp_integer_1 As Integer
Dim Temp_integer_2 As Integer
Dim Temp_integer_3 As Integer
Dim Byte_received(10) As Integer 'ok
Dim New_azimouth As Integer 'ok
Dim New_elevation As Integer 'ok
Dim Az_range As Integer 'ok
Dim El_range As Integer 'ok
Dim Azimouth_full_single As Single 'ok
Dim Elevation_full_single As Single 'ok
Dim Azimouth_integer As Integer 'ok
Dim Elevation_integer As Integer 'ok
Dim Az_threshold_half As Single 'ok
Dim El_threshold_half As Single 'ok
Dim Azimouth_threshold_integer As Integer 'ok
Dim Elevation_threshold_integer As Integer 'ok
Dim Azimouth_pointing_error As Single 'ok
Dim Elevation_pointing_error As Single 'ok
Dim Azimouth_overshot As Integer 'ok
Dim Elevation_overshot As Integer 'ok
Dim Azimouth_direction_movement As Integer 'ok
Dim Elevation_direction_movement As Integer 'ok
Dim Serial_az As Integer
Dim Serial_el As Integer
Dim Az_step As Single
Dim El_step As Single
Dim Temp_single_1 As Single
Dim Temp_single_2 As Single
Dim Keyboard_azimouth As Integer
Dim Keyboard_elevation As Integer
Dim Key_pressed As Integer
Dim Temp As Integer
Dim Rs As Integer
Declare Sub Kbd_read
Declare Sub Clockwise_turn
Declare Sub Counterclockwise_turn
Declare Sub Elevation_stop
Declare Sub Azimouth_stop
Declare Sub Up
Declare Sub Down
Declare Sub Azimouth_correction
Declare Sub Elevation_correction
Declare Function Get_current_azimouth(i As Integer) As Integer
Declare Function Get_current_elevation(i As Integer) As Integer





Portb.5 = 0
Portc.7 = 0
Waitms 250
Cursor On
Cls
Lcd " SW1IXP"
Locate 4 , 1
Lcd "Firmware Version 2.0"
Wait 1
Cls
Do
Cls
Lcd " SELECT OPTION"
Locate 2 , 1
Lcd "1:SETUP CONTROLLER"
Locate 3 , 1
Lcd "2:AUTO TRACKING"
Locate 4 , 1
Lcd "3:MANUAL TRACKING"
Do
Call Kbd_read
Loop Until Key_pressed > 0 And Key_pressed <> 0 And Key_pressed <> 3

Select Case Key_pressed

Case 1 : Cls
Lcd " AZ SETUP"
Locate 2 , 1
Lcd "1:CALIBRATION"
Locate 3 , 1
Lcd "2:THRESHOLD"
Locate 4 , 1
Lcd "3:OVERSHOT 4:EXIT"
Do
Call Kbd_read
Loop Until Key_pressed > 0 And Key_pressed < key_pressed =" 10" key_pressed =" 4"> 4 Then
Locate 2 , 1
Lcd "CALIBRATING AZ NOW "
Locate 4 , 1
Lcd "POSITION:"
Flag = 0
Temp_integer_1 = 2000
Do
Call Clockwise_turn
Wait 5
Start Adc
Adc_az = Getadc(0)
Stop Adc
Locate 4 , 10
Lcd " "
Locate 4 , 10
Lcd Adc_az
I = Adc_az - Temp_integer_1
Temp_integer_1 = Adc_az
I = Abs(i)
If I < flag =" 1" flag =" 1" az_max =" Adc_az" flag =" 0" temp_integer_1 =" 2000" adc_az =" Getadc(0)" i =" Adc_az" temp_integer_1 =" Adc_az" i =" Abs(i)" flag =" 1" flag =" 1" az_min =" Adc_az" b =" Key_pressed" b =" B" az_threshold =" B" b =" Key_pressed" b =" B" az_overshot =" B"> 0 And Key_pressed < key_pressed =" 10" key_pressed =" 4"> 4 Then
Locate 2 , 1
Lcd "CALIBRATING EL NOW "
Locate 4 , 1
Lcd "POSITION:"
Flag = 0
Temp_integer_1 = 2000
Do
Call Up
Wait 5
Start Adc
Adc_el = Getadc(1)
Stop Adc
Locate 4 , 10
Lcd " "
Locate 4 , 10
Lcd Adc_el
I = Adc_el - Temp_integer_1
Temp_integer_1 = Adc_el
I = Abs(i)
If I < flag =" 1" flag =" 1" el_max =" Adc_el" flag =" 0" temp_integer_1 =" 2000" adc_el =" Getadc(1)" i =" Adc_el" temp_integer_1 =" Adc_el" i =" Abs(i)" flag =" 1" flag =" 1" el_min =" Adc_el" b =" Key_pressed" b =" B" el_threshold =" B" i =" El_threshold" b =" Key_pressed" b =" B" el_overshot =" B" az =" Get_current_azimouth(null)" el =" Get_current_elevation(null)" i =" 0" i =" I" i =" 10" temp =" Inkey()" temp =" 87" i =" 0" i =" I" i =" 8"> 32 Then
Goto Then
End If
I = 0
Do
I = I + 1
Byte_received(i) = Byte_received(i) - 48
Loop Until I = 8
Byte_received(1) = Byte_received(1) * 100
Byte_received(2) = Byte_received(2) * 10
Byte_received(6) = Byte_received(6) * 10
New_azimouth = Byte_received(1) + Byte_received(2)
New_azimouth = New_azimouth + Byte_received(3)
Locate 2 , 10
Lcd " "
Locate 2 , 10
Lcd New_azimouth
Call Azimouth_correction
Wait 1
New_elevation = Byte_received(6) + Byte_received(7)
Locate 2 , 19
Lcd " "
Locate 2 , 19
Lcd New_elevation
Call Elevation_correction
Wait 3
End If
Loop


Case 3 : Cls
Lcd " MANUAL TRACKING"
Locate 3 , 1
Lcd "ANT AZ: EL: "
Az = Get_current_azimouth(null)
El = Get_current_elevation(null)
Locate 3 , 10
Lcd Az
Locate 3 , 19
Lcd El
Do
Do
Call Kbd_read
B = Key_pressed
Loop Until B <> 1 And B <> 3 And B <> 7 And B <> 9 And B <> 0


Select Case Key_pressed

Case 2 :
Do
El = Get_current_elevation(null)
If El <> 0 Then
Call Up
End If
Locate 3 , 19
Lcd " "
Locate 3 , 19
Lcd El
Waitms 500
Loop Until Pinc.3 = 1 Or El >= 90
Call Elevation_stop
Waitms 500

Case 4:

Do
Az = Get_current_azimouth(null)
If Az > 0 Then
Call Counterclockwise_turn
End If
Locate 3 , 10
Lcd " "
Locate 3 , 10
Lcd Az
Waitms 500
Loop Until Pind.5 = 1 Or Az <= 0 Call Azimouth_stop Waitms 500 Case 6: Do Az = Get_current_azimouth(null) If Az < 0 =" 1">= 360
Call Azimouth_stop
Waitms 500


Case 8:
Do
El = Get_current_elevation(null)
If El > 0 Then
Call Down
End If
Locate 3 , 19
Lcd " "
Locate 3 , 19
Lcd El
Waitms 500
Loop Until Pinc.5 = 1 Or El <= 0 Call Elevation_stop Waitms 500 Case 10: B = 0 Locate 4 , 1 Lcd " " Locate 4 , 1 Lcd "INPUT NEW AZ:" Do Call Kbd_read Loop Until Key_pressed < b =" Key_pressed" i =" Key_pressed" b =" B" b =" B"> 360 Then
B = 360
End If
New_azimouth = B
Call Azimouth_correction
Waitms 500
Locate 4 , 1
Lcd " "


Case 11:
Locate 4 , 1
Lcd " "
Locate 4 , 1
Lcd "INPUT NEW EL:"
Do
Call Kbd_read
Loop Until Key_pressed < b =" Key_pressed" i =" Key_pressed" b =" B"> 90 Then
B = 90
End If
New_elevation = B
Call Elevation_correction


Waitms 500
Locate 4 , 1
Lcd " "

End Select
Loop
Wait 10
End Select
Loop
End

Sub Kbd_read
Key_pressed = 12
Do
If Pinc.1 = 0 Then
Key_pressed = 9
End If
If Pinc.6 = 0 Then
Key_pressed = 0
End If
If Pind.6 = 0 Then
Key_pressed = 1
End If
If Pinc.3 = 0 Then
Key_pressed = 2
End If
If Pind.7 = 0 Then
Key_pressed = 3
End If
If Pind.3 = 0 Then
Key_pressed = 10
End If
If Pinc.2 = 0 Then
Key_pressed = 11
End If
If Pinc.4 = 0 Then
Key_pressed = 5
End If
If Pinc.0 = 0 Then
Key_pressed = 6
End If
If Pind.4 = 0 Then
Key_pressed = 7
End If
If Pinc.5 = 0 Then
Key_pressed = 8
End If
If Pind.5 = 0 Then
Key_pressed = 4
End If
Loop Until Key_pressed <> 12
Waitms 250
End Sub

Function Get_current_azimouth(i As Integer) As Integer
Start Adc
Adc_az = Getadc(0)
Stop Adc
Adc_az = Adc_az - Az_min
Az_range = Az_max - Az_min
Az_step = 360 / Az_range
Azimouth_full_single = Adc_az * Az_step
Azimouth_integer = Azimouth_full_single
Get_current_azimouth = Azimouth_integer
End Function

Function Get_current_elevation(i As Integer) As Integer
Start Adc
Adc_el = Getadc(1)
Stop Adc
Adc_el = Adc_el - El_min
El_range = El_max - El_min
El_step = 90 / El_range
Elevation_full_single = Adc_el * El_step
Elevation_integer = Elevation_full_single
Get_current_elevation = Elevation_integer
End Function

Sub Azimouth_correction
Azimouth_threshold_integer = Az_threshold
Az_threshold_half = Azimouth_threshold_integer / 2
Azimouth_overshot = Az_overshot
Az = Get_current_azimouth(null)
If New_azimouth > Az Then
New_azimouth = New_azimouth - Azimouth_overshot
Azimouth_direction_movement = 1
End If
If New_azimouth <= Az Then New_azimouth = New_azimouth + Azimouth_overshot Azimouth_direction_movement = 2 End If Azimouth_pointing_error = New_azimouth - Az Azimouth_pointing_error = Abs(azimouth_pointing_error) If Azimouth_pointing_error > Az_threshold_half Then
Flag = 0
Do
Az = Get_current_azimouth(null)
Locate 3 , 10
Lcd " "
Locate 3 , 10
Lcd Az
If Azimouth_direction_movement = 1 And New_azimouth <= Az Then Flag = 1 End If If Azimouth_direction_movement = 2 And New_azimouth >= Az Then
Flag = 1
End If
If New_azimouth > Az And Flag = 0 Then
Call Clockwise_turn
End If
If New_azimouth < flag =" 0" flag =" 1" flag =" 1" elevation_threshold_integer =" El_threshold" el_threshold_half =" Elevation_threshold_integer" elevation_overshot =" El_overshot" el =" Get_current_elevation(null)"> El Then
New_elevation = New_elevation - Elevation_overshot
Elevation_direction_movement = 1
End If
If New_elevation <= El Then New_elevation = New_elevation + Elevation_overshot Elevation_direction_movement = 2 End If Elevation_pointing_error = New_elevation - El Elevation_pointing_error = Abs(elevation_pointing_error) If Elevation_pointing_error > El_threshold_half Then
Flag = 0
Do
El = Get_current_elevation(null)
Locate 3 , 19
Lcd " "
Locate 3 , 19
Lcd El
If Elevation_direction_movement = 1 And New_elevation <= El Then Flag = 1 End If If Elevation_direction_movement = 2 And New_elevation >= El Then
Flag = 1
End If
If New_elevation > El And Flag = 0 Then
Call Up
End If
If New_elevation < El And Flag = 0 Then
Call Down
End If
If Flag = 1 Then
Call Elevation_stop
End If
Waitms 250
Loop Until Flag = 1
End If
End Sub

Sub Up
Porta.4 = 1
Porta.5 = 0
End Sub

Sub Down
Porta.4 = 0
Porta.5 = 1
End Sub

Sub Clockwise_turn
Porta.2 = 1
Porta.3 = 0
End Sub

Sub Counterclockwise_turn
Porta.2 = 0
Porta.3 = 1
End Sub

Sub Elevation_stop
Porta.4 = 0
Porta.5 = 0
End Sub

Sub Azimouth_stop
Porta.2 = 0
Porta.3 = 0
End Sub

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου