PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : entfernungsmessung klapt nicht...



[IN]Crusher
12.04.2006, 00:27
Hallo!

Ich bin mit meinem roboter nun soweit, dass ich die entfernungsmessung in angriff nehme...


ich habe einen srf08 an meine rn.control 1.4 angeschlossen.

ich habe folgendes programm geschrieben:


'################################################# ##############################
'# #
'# entfernung_1.bas #
'# #
'# Aufgabe: Messen von Entfernungen via SRF08 #
'# #
'################################################# ##############################



$regfile = "m32def.dat"
$crystal = 16000000
$baud = 9600


Const Sf08_adr_0 = &HE0 ' I2C Adresse
Const Sf08_c_range = 100 ' Reichweite
Const Sf08_c_gain = 1 'Empfindlichkeit
Const Sf08_adr_0_read = &HE1

Dim Lsb As Byte
Dim Msb As Byte
Dim Ival As Word


Declare Sub Entfernung()
Declare Function Tastenabfrage() As Byte

Config Scl = Portc.0 'Ports fuer IIC-Bus
Config Sda = Portc.1

Do

I2cinit

'################################################# ##############################
'# Setzten des Range Wertes #
'################################################# ##############################

I2cstart
I2cwbyte Sf08_adr_0
I2cwbyte 2
I2cwbyte Sf08_c_range
I2cstop



'################################################# ##############################
'# Setzten des Gain Wertes #
'################################################# ##############################

I2cstart
I2cwbyte Sf08_adr_0
I2cwbyte 1
I2cwbyte Sf08_c_gain
I2cstop


'################################################# ##############################
'# Messung auslösen #
'################################################# ##############################

I2cstart
I2cwbyte Sf08_adr_0
I2cwbyte 0
I2cwbyte 81
Waitms 70


'################################################# ##############################
'# Ergebnis abholen #
'################################################# ##############################

I2cstart
I2cwbyte Sf08_adr_0
I2cwbyte 2



I2cstart
I2cwbyte Sf08_adr_0_read
I2crbyte Msb , Ack
I2crbyte Lsb , Nack
I2cstop

Ival = Makeint(lsb , Msb)


'################################################# ##############################
'# Ergebnis abholen #
'################################################# ##############################

Print "Die Entfernung beträgt" ; Ival ; "Meter."

Loop

End


jedoch gibt es mir immer nur 65535 Meter als Entfernung und so groß is mein zimmer nun wirklich nich...

;-)

außerdem blinkt die ganze zeit led2. ist das normal?!?

P.S.: Habe grade festgestellt: 1mal wird mir eine entfernung zurückgegeben. direkt nach einem reset und dann kommt die 65535...


MfG JÜrgen

[IN]Crusher
12.04.2006, 20:58
So... ich hab jetzt versucht ein anderes Programm aufzuziehen.

Es ist stark angelehnt an dieses hier https://www.roboternetz.de/wissen/index.php/Ultraschall_SRF10_an_RN-Control

meins sieht wie folgt aus:


'################################################# ##############################
'# #
'# entfernung_1.bas #
'# #
'# Aufgabe: Messen von Entfernungen via SRF08 #
'# #
'################################################# ##############################

Declare Function Srf08_firmware(byval Srf08_adr_0 As Byte) As Byte
Declare Sub Srf08_reichweite(byval Srf08_adr_0 As Byte , Byval Reichweite As Word)
Declare Sub Srf08_verstaerkung(byval Srf08_adr_0 As Byte , Byval Verstaerkung As Byte)
Declare Function Srf08_entfernung(byval Srf_adr_0 As Byte) As Byte

$regfile = "m32def.dat"

$crystal = 16000000
$baud = 9600

Config Scl = Portc.0 'Port fuer IIC-Bus
Config Sda = Portc.1 'Port fuer IIC-Bus

Dim Entfernung As Integer


'################################################# ##############################
'# Main #
'################################################# ##############################
Wait 3

I2cinit

Print "**********************************"
Print "*US Messuns via SRF08 by stiffler*"
Print "**********************************"
Print "\n"
Print "SRF 08 Firmware Version: " ; Srf08_firmware(&He0)

Srf08_reichweite &HE0 , 100 'Reichweite für die Messung festlegen
Srf08_verstaerkung &HE0 , 1 'Lichtverstärkungsfaktor


Do
Entfernung = Srf08_entfernung(&He0)
Print "Entfernung: " ; Entfernung ; "cm"
Wait 1
Loop

End


'################################################# ##############################
'# Reichweite setzen #
'################################################# ##############################
Sub Srf08_reichweite(byval Srf08_adr_0 As Byte , Byval Reichweite As Word)

I2cstart
I2cwbyte Srf08_adr_0
I2cwbyte 2
I2cwbyte Reichweite
I2cstop

End Sub


'################################################# ##############################
'# Verstärkung setzten #
'################################################# ##############################

Sub Srf08_verstaerkung(byval Srf08_adr_0 As Byte , Byval Verstaerkung As Word)

I2cstart
I2cwbyte Srf08_adr_0
I2cwbyte 1
I2cwbyte Verstaerkung
I2cstop

End Sub


'################################################# ##############################
'# Firmware-Vers. prüfen (wenn Byte 255 anzeigt wird noch gemessen)#
'################################################# ##############################

Function Srf08_firmware(byval Srf08_adr_0 As Byte)

Local Srf08_adr_read As Byte
Local Firmware As Byte

Srf08_adr_read = Srf08_adr_0 + 1

I2cstart
I2cwbyte Srf08_adr_0
I2cwbyte 0
I2cstop

I2cstart
I2cwbyte Srf08_adr_read
I2crbyte Firmware , Nack
I2cstop

Srf08_firmware = Firmware

End Function

'################################################# ##############################
'# Entfernung bestimmen #
'################################################# ##############################

Function Srf08_entfernung(byval Srf08_adr_0 As Byte)

Local Firmware As Byte
Local Srf08_adr_read As Byte
Local Hib As Byte
Local Lob As Byte

Srf08_adr_read = &HE1


'Messung starten:
I2cstart
I2cwbyte Srf_adr_0
I2cwbyte 0
I2cwbyte 81
I2cstop

Warteaufmessung:
Waitms 1
Firmware = Srf08_firmware(&He0)
If Firmware = 255 Then Goto Warteaufmessung

I2cstart
I2cwbyte Srf08_adr_0
I2cwbyte 2
I2cstop

I2cstart
I2cwbyte Srf08_adr_read
I2crbyte Hib , Ack
I2crbyte Lob , Nack
I2cstop

Srf08_entfernung = Makeint(lob , Hib)

End Function






ich bekomme hierbei nun 3 errors nicht weg und zwar in dieser zeile:


I2cwbyte Srf08_adr_0

an der Stelle von Funktion "Srf08_entfernung(byval Srf08_adr_0 As Byte)"

Als error sagt er mir "invalid datatype" und als 2. "variable not dimensioned"

das habe ich aber doch schon im funktionsaufruf gemacht, oder nicht?!?

und der 3. fehler ist in dieser zeile im hauptprogramm:


Entfernung = Srf08_entfernung(&He0)

da sagt bascom mir: "different parameter type passed then declared"