daviid
17.08.2010, 18:39
Hallo,
Ich hab mir gestern die Teile für meinen ersten Bot bestellt, und zwar das Fahrgestell des RP5 und lauter kleinkrams, angesteuert wird das ganze von meiner eigenen Steuerung gesteuert, bestehend vorerst aus nem Mega 16 und nem L293 als Hauptsteuerung, der rest is ersmal uninterresant.
Hab mir folgenden Code geschrieben:
'Uart Protokoll:
'Drive : R_l -pwm_l -r_r -pwm_r
'drive:1-120-1-130
$regfile = "m16def.dat"
$crystal = 16000000
$baud = 9600
Config Serialin = Buffered , Size = 30 , Bytematch = 13
Declare Sub Serial0charmatch()
'Config Outputs
Config Portc.4 = Output 'M_left1a
M_left1a Alias Portc.4
Config Portc.5 = Output 'M_left2a
M_left2a Alias Portc.5
Config Portc.6 = Output 'M_left3a
M_left3a Alias Portc.6
Config Portc.7 = Output 'M_left4a
M_left4a Alias Portc.7
'Declare Motor-PWM
Config Portb.0 = Output 'm-left-enable
M_left_e Alias Portb.0
Config Portb.1 = Output 'm-right-enable
M_right_e Alias Portb.1
'Config Inputs
Config Portd.2 = Input 'emergency-out
Em_out Alias Portc.0
Em_out = 1 'enable pullup
'Config Interrupts
Config Int0 = Falling 'fallende Flanke
On Int0 On_em_out
Enable Int0
Enable Interrupts
'Config Var's
Dim Tmp As Byte
Dim New_command As String * 30
Dim Incoming_array(5) As String * 30
Dim Command_array(5) As String * 30
Dim New_status As Bit
Dim Pwm_1 As Integer
Dim Pwm_2 As Integer
Dim Drive_command(4) As String * 15
Do
If New_command <> "" Then
New_command = Ucase(new_command)
'Anweisung aufteilen
Tmp = Split(new_command , Command_array(1) , ":")
Select Case Command_array(1)
Case "DRIVE"
Tmp = Split(command_array(2) , Command_array(1) , "-")
Drive_command(1) = Command_array(1)
Drive_command(2) = Command_array(2)
Drive_command(3) = Command_array(3)
Drive_command(4) = Command_array(4)
Gosub Exc_drive
Case Else
Print "ERROR: unknown command"
End Select
New_command = ""
End If
Loop
End
Sub Serial0charmatch()
Input New_command Noecho
Print New_command
End Sub
Exc_drive:
If Drive_command(1) = "1" Then Gosub Forward_left 'drive forward
If Drive_command(1) = "0" Then Gosub Backward_left 'drive backward
If Drive_command(3) = "1" Then Gosub Forward_right 'drive forward
If Drive_command(3) = "0" Then Gosub Backward_right 'drive backward
Pwm_1 = Val(drive_command(2))
Pwm_2 = Val(drive_command(4))
Pwm1a = Pwm_1
Pwm1b = Pwm_2
Print "exc_drive " ; Drive_command(1) ; " " ; Drive_command(2) ; " " ; Drive_command(3) ; " " ; Drive_command(4)
Return
Forward_left:
M_left1a = 1
M_left2a = 0
Return
Backward_left:
M_left1a = 0
M_left2a = 1
Return
Forward_right:
M_left4a = 1
M_left3a = 0
Return
Backward_right:
M_left4a = 0
M_left3a = 1
Return
Theoretisch sollte also wenn ich übern Uart "drive:1-130-1-120" eingeb auf PWM1a 130 stehen und bei PWM1b 120 im Simulator, tuts aber nich, da steht immer null.
Hat jemand ne Idee warum?
Edit:
Hab den Fehler nach langem überlegen selber gefunden, mal wieder total banal ... :-b
Tmp = Split(new_command , Command_array(1) , ":")
Select Case Command_array(1)
Case "DRIVE"
Tmp = Split(command_array(2) , Command_array(1) , "-")
Und zwar wird da beim zweiten splitten das command_array wieder überschrieben.
Hab das ganze nun so gelöst:
Tmp = Split(new_command , Incoming_array(1) , ":")
Select Case Incoming_array(1)
Case "DRIVE"
Tmp = Split(incoming_array(2) , Command_array(1) , "-")
Gruß
David[/code]
Ich hab mir gestern die Teile für meinen ersten Bot bestellt, und zwar das Fahrgestell des RP5 und lauter kleinkrams, angesteuert wird das ganze von meiner eigenen Steuerung gesteuert, bestehend vorerst aus nem Mega 16 und nem L293 als Hauptsteuerung, der rest is ersmal uninterresant.
Hab mir folgenden Code geschrieben:
'Uart Protokoll:
'Drive : R_l -pwm_l -r_r -pwm_r
'drive:1-120-1-130
$regfile = "m16def.dat"
$crystal = 16000000
$baud = 9600
Config Serialin = Buffered , Size = 30 , Bytematch = 13
Declare Sub Serial0charmatch()
'Config Outputs
Config Portc.4 = Output 'M_left1a
M_left1a Alias Portc.4
Config Portc.5 = Output 'M_left2a
M_left2a Alias Portc.5
Config Portc.6 = Output 'M_left3a
M_left3a Alias Portc.6
Config Portc.7 = Output 'M_left4a
M_left4a Alias Portc.7
'Declare Motor-PWM
Config Portb.0 = Output 'm-left-enable
M_left_e Alias Portb.0
Config Portb.1 = Output 'm-right-enable
M_right_e Alias Portb.1
'Config Inputs
Config Portd.2 = Input 'emergency-out
Em_out Alias Portc.0
Em_out = 1 'enable pullup
'Config Interrupts
Config Int0 = Falling 'fallende Flanke
On Int0 On_em_out
Enable Int0
Enable Interrupts
'Config Var's
Dim Tmp As Byte
Dim New_command As String * 30
Dim Incoming_array(5) As String * 30
Dim Command_array(5) As String * 30
Dim New_status As Bit
Dim Pwm_1 As Integer
Dim Pwm_2 As Integer
Dim Drive_command(4) As String * 15
Do
If New_command <> "" Then
New_command = Ucase(new_command)
'Anweisung aufteilen
Tmp = Split(new_command , Command_array(1) , ":")
Select Case Command_array(1)
Case "DRIVE"
Tmp = Split(command_array(2) , Command_array(1) , "-")
Drive_command(1) = Command_array(1)
Drive_command(2) = Command_array(2)
Drive_command(3) = Command_array(3)
Drive_command(4) = Command_array(4)
Gosub Exc_drive
Case Else
Print "ERROR: unknown command"
End Select
New_command = ""
End If
Loop
End
Sub Serial0charmatch()
Input New_command Noecho
Print New_command
End Sub
Exc_drive:
If Drive_command(1) = "1" Then Gosub Forward_left 'drive forward
If Drive_command(1) = "0" Then Gosub Backward_left 'drive backward
If Drive_command(3) = "1" Then Gosub Forward_right 'drive forward
If Drive_command(3) = "0" Then Gosub Backward_right 'drive backward
Pwm_1 = Val(drive_command(2))
Pwm_2 = Val(drive_command(4))
Pwm1a = Pwm_1
Pwm1b = Pwm_2
Print "exc_drive " ; Drive_command(1) ; " " ; Drive_command(2) ; " " ; Drive_command(3) ; " " ; Drive_command(4)
Return
Forward_left:
M_left1a = 1
M_left2a = 0
Return
Backward_left:
M_left1a = 0
M_left2a = 1
Return
Forward_right:
M_left4a = 1
M_left3a = 0
Return
Backward_right:
M_left4a = 0
M_left3a = 1
Return
Theoretisch sollte also wenn ich übern Uart "drive:1-130-1-120" eingeb auf PWM1a 130 stehen und bei PWM1b 120 im Simulator, tuts aber nich, da steht immer null.
Hat jemand ne Idee warum?
Edit:
Hab den Fehler nach langem überlegen selber gefunden, mal wieder total banal ... :-b
Tmp = Split(new_command , Command_array(1) , ":")
Select Case Command_array(1)
Case "DRIVE"
Tmp = Split(command_array(2) , Command_array(1) , "-")
Und zwar wird da beim zweiten splitten das command_array wieder überschrieben.
Hab das ganze nun so gelöst:
Tmp = Split(new_command , Incoming_array(1) , ":")
Select Case Incoming_array(1)
Case "DRIVE"
Tmp = Split(incoming_array(2) , Command_array(1) , "-")
Gruß
David[/code]