PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : benötige Hilfe bei meinem Code



Reeper
08.12.2005, 19:05
Hallo,

Ich habe mein Bot jetzt schon sehr weit vorangebracht, kann ich alles einzeln per Programm sehr gut steuern. Nun will ich einiges zusammenbringen, aber ich erhalte immer versch. Errors (46, 60, ).
Das komische: Schon beim config der Servos erhalte ich eine Fehlermeldung (sehr merkwürdig), welche beim programmieren des servo subs durch den Error 46 ersetzt wird ;-(

Bis jetzt habe ich schon sehr viel im Forum darüber gelesen, aber weder stacks noch framesize konnten es bei mir beheben (habe versch. Werte getestet und auch komplett weggenommen).

Hier der Code:


$regfile = "m32def.dat"
$framesize = 32
$swstack = 256
$hwstack = 128
$crystal = 16000000
$baud = 9600
$lib "mcsbyte.lbx"

Config Pind.6 = Input
Config Rc5 = Pind.6
Portd.6 = 1
Config Pinc.2 = Output

Config Pinc.4 = Output
Config Pinc.3 = Input

'Ports für linken Motor
Config Pinb.0 = Output
Config Pinb.4 = Output
Config Pind.5 = Output
'Ports für rechten Motor
Config Pinb.1 = Output
Config Pinb.2 = Output
Config Pind.4 = Output

Config Servos = 2 , Servo1 = Portd.7 , Servo2 = Portb.3 , Reload = 10
Config Pinb.3 = Output
Config Pind.7 = Output

Enable Interrupts

Dim Address As Byte , Command As Byte
Dim Pulses As Word , Periods As Word
Pulses = 65535 : Periods = 10000
Speaker Alias Portc.2
Dim I As Integer

Declare Sub Vorwaerts
Declare Sub Rueckwaerts
Declare Sub Halt
Declare Sub Links
Declare Sub Rechts
Declare Sub These
Declare Sub Servo

Do

Portc.4 = 1
Gosub Servo
Gosub Vorwaerts

Loop

Sub Servo
Servo(2) = 95
Print "Mittelstellung"
Wait 1
Servo(1) = 95
Print "Mittelstellung"
Wait 1
End Sub
Return

Sub Vorwaerts
Do
Portb.1 = 1
Portb.2 = 0
Portb.4 = 0
Portb.0 = 1
Portd.4 = 1
Portd.5 = 1
Getrc5(address , Command)
Loop Until Pinc.3 = 0 Or Command = 11 Or Command = 12 Or Command = 13 Or Command = 14 Or Command = 15
Gosub Halt
End Sub
Return

Sub Halt
Portb.1 = 1
Portb.2 = 1
Portb.4 = 1
Portb.0 = 1
Portd.4 = 1
Portd.5 = 1
Wait 1
Getrc5(address , Command)
Waitms 150
If Command = 11 And Command = 12 And Command = 13 And Command = 14 And Command = 15 Or Command = 12 And Command = 13 And Command = 14 Then
Gosub Rueckwaerts
Elseif Command = 11 Or Command = 12 Then
Gosub Rechts
Elseif Command = 13 Or Command = 14 Or Command = 15 Then
Gosub Links
Elseif Command = 255 Then
Gosub These
End If
End Sub
Return

Sub Rueckwaerts
Portb.1 = 0
Portb.2 = 1
Portb.4 = 1
Portb.0 = 0
Portd.4 = 1
Portd.5 = 1
Waitms 500
Portb.1 = 1
Portb.2 = 1
Portb.4 = 1
Portb.0 = 1
Portd.4 = 1
Portd.5 = 1
Waitms 500
Gosub Rechts
End Sub
Return

Sub Rechts
Portb.1 = 1
Portb.2 = 0
Portb.4 = 1
Portb.0 = 0
Portd.4 = 1
Portd.5 = 1
Waitms 500
Gosub Vorwaerts
End Sub
Return

Sub Links
Portb.1 = 0
Portb.2 = 1
Portb.4 = 0
Portb.0 = 1
Portd.4 = 1
Portd.5 = 1
Waitms 500
Gosub Vorwaerts
End Sub
Return

Sub These
Portb.1 = 1
Portb.2 = 0
Portb.4 = 1
Portb.0 = 0
Portd.4 = 1
Portd.5 = 1
Waitms 500
Gosub Vorwaerts
End Sub
Return

End

Torsten_G
08.12.2005, 19:55
Hi,

schau mal hier:
"Declare Sub Servo"

"Servo" ist ein Steuerwort, versuch doch mal, Deine eigene Subroutine anders zu benennen... :-k

Viele Grüße

Torsten

Reeper
08.12.2005, 21:18
Guter Einwurf, war ein Fehler.
Doch nun erhalte ich den vorherigen Fehler (Error 60 , 60 und 221) mit dem Code:


$regfile = "m32def.dat"
$framesize = 32
$swstack = 256
$hwstack = 128
$crystal = 16000000
$baud = 9600
$lib "mcsbyte.lbx"

Config Pind.6 = Input
Config Rc5 = Pind.6
Portd.6 = 1
Config Pinc.2 = Output

Config Pinc.4 = Output
Config Pinc.3 = Input

'Ports für linken Motor
Config Pinb.0 = Output
Config Pinb.4 = Output
Config Pind.5 = Output
'Ports für rechten Motor
Config Pinb.1 = Output
Config Pinb.2 = Output
Config Pind.4 = Output

Config Servos = 2 , Servo1 = Portd.7 , Servo2 = Portb.3 , Reload = 10
Config Pinb.3 = Output
Config Pind.7 = Output

Enable Interrupts

Dim Address As Byte , Command As Byte
Dim Pulses As Word , Periods As Word
Pulses = 65535 : Periods = 10000
Speaker Alias Portc.2
Dim I As Integer

Declare Sub Vorwaerts
Declare Sub Rueckwaerts
Declare Sub Halt
Declare Sub Links
Declare Sub Rechts
Declare Sub These
Declare Sub Camera

Do

Portc.4 = 1
Gosub Camera
Gosub Vorwaerts

Loop

Sub Camera
Servo(2) = 95
Print "Mittelstellung"
Wait 1
Servo(1) = 95
Print "Mittelstellung"
Wait 1
End Sub
Return

Sub Vorwaerts
Do
Portb.1 = 1
Portb.2 = 0
Portb.4 = 0
Portb.0 = 1
Portd.4 = 1
Portd.5 = 1
Getrc5(address , Command)
Loop Until Pinc.3 = 0 Or Command = 11 Or Command = 12 Or Command = 13 Or Command = 14 Or Command = 15
Gosub Halt
End Sub
Return

Sub Halt
Portb.1 = 1
Portb.2 = 1
Portb.4 = 1
Portb.0 = 1
Portd.4 = 1
Portd.5 = 1
Wait 1
Getrc5(address , Command)
Waitms 150
If Command = 11 And Command = 12 And Command = 13 And Command = 14 And Command = 15 Or Command = 12 And Command = 13 And Command = 14 Then
Gosub Rueckwaerts
Elseif Command = 11 Or Command = 12 Then
Gosub Rechts
Elseif Command = 13 Or Command = 14 Or Command = 15 Then
Gosub Links
Elseif Command = 255 Then
Gosub These
End If
End Sub
Return

Sub Rueckwaerts
Portb.1 = 0
Portb.2 = 1
Portb.4 = 1
Portb.0 = 0
Portd.4 = 1
Portd.5 = 1
Waitms 500
Portb.1 = 1
Portb.2 = 1
Portb.4 = 1
Portb.0 = 1
Portd.4 = 1
Portd.5 = 1
Waitms 500
Gosub Rechts
End Sub
Return

Sub Rechts
Portb.1 = 1
Portb.2 = 0
Portb.4 = 1
Portb.0 = 0
Portd.4 = 1
Portd.5 = 1
Waitms 500
Gosub Vorwaerts
End Sub
Return

Sub Links
Portb.1 = 0
Portb.2 = 1
Portb.4 = 0
Portb.0 = 1
Portd.4 = 1
Portd.5 = 1
Waitms 500
Gosub Vorwaerts
End Sub
Return

Sub These
Portb.1 = 1
Portb.2 = 0
Portb.4 = 1
Portb.0 = 0
Portd.4 = 1
Portd.5 = 1
Waitms 500
Gosub Vorwaerts
End Sub
Return

End

Veränderung der Stack Werte bzw. framesize beheben leider nicht den Fehler.

linux_80
08.12.2005, 22:55
Hallo,
ist es nicht bei Verwendung von Gosub so, das man da keine Sub's definiert sondern nur Labels !?

Return steht auch immer nach dem End sub,
schaut meiner Meinung nach auch komisch aus !

oe9vfj
09.12.2005, 07:19
Hallo,

Das Problem ist, dass SERVO und RC5 beide den Timer0 benötigen.
Bei RC5 hast Du aber die Möglichkeit mit dem Zusatz Timer = 2 auszuweichen. Schau mal in Hilfe unter CONFIG RC5 nach.

Generell sollte man bei Routinen welcher Timer/Counter verwenden in der Hilfe nachsehen, welche HW-Ressourcen benötigt werden, damit hier keine Konflikte entstehen.

SUB werden mit END SUB beendet. Das RETURN hinter Deinen END SUB ist nicht notwendig (macht hier aber auch kein Problem).

Reeper
09.12.2005, 15:36
Danke euch allen vielmals, mit Timer 2 für rc5 funktioniert es jetzt, danke wirklich :lol: