Hi@all!
Hänge am Problem fest wo ich auf eure Hilfe hoffe![]()
Ziel ist es beim unterschreiten einer bestimmten Entfernung,gemessen durch SRF10, einen Servo in eine bestimmte Position zu bringen...
Als Beispiel mal die Entfernung 30cm....
Hier der Quellcode aus dem Wissensbereich+meiner Ergänzung...
Hat jemand einen Tipp??Code:Declare Function Srf10_entfernung(byval Srf10_slaveid As Byte) As Integer Declare Sub Srf10_reichweite(byval Srf10_slaveid As Byte , Byval Reichweite As Word) Declare Sub Srf10_verstaerkung(byval Srf10_slaveid As Byte , Byval Srf10_verstaerkung As Byte) Declare Function Srf10_firmware(byval Srf10_slaveid As Byte) As Byte $regfile = "m32def.dat" $framesize = 42 $swstack = 42 $hwstack = 42 $crystal = 16000000 'Quarzfrequenz $baud = 9600 Config Scl = Portc.0 'Ports fuer IIC-Bus Config Sda = Portc.1 Dim Entfernung As Integer Wait 3 'Warte 3 Sekunden I2cinit Print "SRF10 Testprogramm " Print "SRF 10 Firmware Version:" ; Srf10_firmware(&He0) Srf10_reichweite &HE0 , 1000 'Reichweite in Zentimetern festlegen Srf10_verstaerkung &HE0 , 10 'Verstärkungsfaktor Do Entfernung = Srf10_entfernung(&He0) Print "Entfernung:" ; Entfernung ; "cm" Wait 1 Loop End Function Srf10_entfernung(byval Srf10_slaveid As Byte) As Integer Local LoB As Byte Local Hib As Byte Local Firmware As Byte Local Temp As Byte Local Srf10_slaveid_read As Byte Srf10_slaveid_read = Srf10_slaveid + 1 'Messvorgang in starten I2cstart I2cwbyte Srf10_slaveid I2cwbyte 0 I2cwbyte 81 in Zentimetern messen I2cstop Warteaufmessung: Waitms 1 Firmware = Srf10_firmware(&He0) If Firmware = 255 Then Goto Warteaufmessung I2cstart I2cwbyte Srf10_slaveid I2cwbyte 2 'Leseregister festlegen I2cstop I2cstart I2cwbyte Srf10_slaveid_read I2crbyte Hib , Ack I2crbyte Lob , Nack I2cstop Srf10_entfernung = Makeint(lob , Hib) End Function 'Messreichweite in cm festlegen Sub Srf10_reichweite(byval Srf10_slaveid As Byte , Byval Reichweite As Word) Local Wert As Word Local Temp As Byte Wert = Reichweite / 4 'Ungefähre Registerberechnung Temp = Low(wert) I2cstart I2cwbyte Srf10_slaveid I2cwbyte 2 'Register I2cwbyte Temp I2cstop End Sub 'Verstärung festlegen Sub Srf10_verstaerkung(byval Srf10_slaveid As Byte , Byval Srf10_verstaerkung As Byte) I2cstart I2cwbyte Srf10_slaveid I2cwbyte 1 'Register I2cwbyte Srf10_verstaerkung I2cstop End Sub Function Srf10_firmware(byval Srf10_slaveid As Byte) As Byte Local Firmware As Byte Local Srf10_slaveid_read As Byte Srf10_slaveid_read = Srf10_slaveid + 1 I2cstart I2cwbyte Srf10_slaveid I2cwbyte 0 'Leseregister festlegen I2cstop I2cstart I2cwbyte Srf10_slaveid_read I2crbyte Firmware , Nack I2cstop Srf10_firmware = Firmware End Function ####denke nun müsste folgendes kommen#### Config Servos = 1 , Servo1 = PortA.0 , Reload 10 Config PortA = Output Enable Interrupts ###hier jetzt ein Befehl der die Distanz <30cm vorm nächsten Schritt abfragt??### waitms 1000 Servo(1) = 100 loop
Gruß,Easy







Zitieren


Lesezeichen