Ich hab 2 247Ncm Servos direkt angeschlossen um's zu testen. Kann es sein, dass irgendwie durch Überbelastung was kaputt gegangen ist? Obwohl es ja eigentlich nicht so sein dürfte, da wie oben schon gesagt der Servo 3 in der ersten For-Schleife funktioniert. Nur in der 2. nicht.
hier nochmal der komplette Code:
Code:
$crystal = 8000000
$baud = 9600
Declare Sub Stepper_move(byval Stepper_goto_pos As Word)
Declare Sub Elbow_move(byval Servo_goto_pos As Integer)
Declare Sub Shoulder_move(byval Servo_goto_pos As Integer)
Const Writepowerport_adr = &H72 'I2C Adr PCF 2
Const Readpowerport_adr = &H73 'I2C Adr PCF 2
Dim I2cdaten As Byte 'Datenbyte aus PCF8574
Dim I As Integer
$crystal = 8000000 'Quarzfrequenz
Config Scl = Portc.0 'Ports fuer IIC-Bus
Config Sda = Portc.1
I2cinit
Config Pind.6 = Output 'Schrittmotoren Ein/Aus
Config Pinc.5 = Output 'Schrittmotor Links Richtung
Config Pinc.3 = Output 'Schrittmotor Links Step
Config Pinc.4 = Output 'Schrittmotor Rechts Richtung
Config Pinc.2 = Output 'Schrittmotor Rechts Step
Portd.6 = 0 'Schrittmotoren einschalten
Dim Stepper_curr_pos As Integer
Stepper_curr_pos = 0
Dim Shoulder_curr_pos As Integer
Shoulder_curr_pos = 127
Dim Elbow_curr_pos As Integer
Elbow_curr_pos = 127
Dim Temp as Byte
Hauptschleife:
'Call Stepper_move(100)
'Wait 2
'Call Stepper_move(0)
'Wait 2
Wait 2
Call Elbow_move(255)
Wait 2
Call Elbow_move(0)
Goto Hauptschleife
Sub Shoulder_move(byval Servo_goto_pos As Integer)
Local Schritt As Integer
If Shoulder_curr_pos < Servo_goto_pos Then
Schritt = 1
Elseif Shoulder_curr_pos > Servo_goto_pos Then
Schritt = -1
Elseif Shoulder_curr_pos = Servo_goto_pos Then
Exit Sub
End If
Open "comd.7:9600,8,n,1" For Output As #2
For Shoulder_curr_pos = Shoulder_curr_pos To Servo_goto_pos Step Schritt
Print #2 , "#s" ; Chr(1) ; Chr(shoulder_curr_pos)
Print #2 , "#s" ; Chr(2) ; Chr(shoulder_curr_pos)
Next Shoulder_curr_pos
Close #2
Shoulder_curr_pos = Servo_goto_pos
End Sub
Sub Elbow_move(byval Servo_goto_pos As Integer)
Local Schritt As Integer
Print "elbow_move called"
If Elbow_curr_pos < Servo_goto_pos Then
Schritt = 1
Elseif Elbow_curr_pos > Servo_goto_pos Then
Schritt = -1
Elseif Shoulder_curr_pos = Servo_goto_pos Then
Exit Sub
End If
Open "comd.7:9600,8,n,1" For Output As #2
For Elbow_curr_pos = Elbow_curr_pos To Servo_goto_pos Step Schritt
Temp = Elbow_curr_pos
Print #2 , "#s" ; Chr(3) ; Chr(temp)
Print "Schritt: " ; Schritt ; " CURR: " ; Temp ; " GOTO: " ; Servo_goto_pos
Next Elbow_curr_pos
Close #2
Elbow_curr_pos = Servo_goto_pos
End Sub
Sub Stepper_move(byval Stepper_goto_pos As Intgeger)
Local Betrag As Integer
If Stepper_goto_pos > Stepper_curr_pos Then
Betrag = Stepper_goto_pos - Stepper_curr_pos
Portc.5 = 0 'Richtung
Portc.3 = 0
For I = 0 To Betrag Step 1
Portc.3 = 0
Waitms 5
Portc.3 = 1
Waitms 20
Next I
Stepper_curr_pos = Stepper_goto_pos
Print Stepper_curr_pos
Elseif Stepper_goto_pos < Stepper_curr_pos Then
Betrag = Stepper_curr_pos - Stepper_goto_pos
Portc.5 = 1 'Richtung
Portc.3 = 0
For I = 0 To Betrag Step 1
Portc.3 = 0
Waitms 5
Portc.3 = 1
Waitms 20
Next I
Stepper_curr_pos = Stepper_goto_pos
Print Stepper_curr_pos
End If
End Sub
End
mfg
jagdfalke
Lesezeichen