OK so basically im pretty good with programming on the whole and as my MCU is programmed in a BASIC like language im suprized i get this problem. Basically this is the code for my robotic arm. The Visual Basic application sends information via a serial cable to the MCU (this is the code) and the MCU picks it up and uses it to move the servos. So the actual thing im stuck on is that whenever i turn the robotic arm on, all the servos move and the arm looks like its having a spasm. Also im not to sure that the code is picking up info from the computer. Any ideas as to why this is happening?
here's the code:
Dim Data(1 To 3) As Byte ' defne variables
Dim Com1_In(1 To 40) As Byte
Dim Com1_Out(1 To 20) As Byte
dim baseservo as single
dim basejointservo as single
dim middlejointservo as single
dim turngripperservo as single
dim tiltgripperservo as single
dim gripperservo as single
Sub Main()
Call OpenQueue(Com1_In, 40)
Call OpenQueue(Com1_Out, 20)
Call OpenCom(1, 2400, Com1_In, Com1_Out)
' Set pins 5 - 20 to outputs
Register.DDRA = &HFF
Register.DDRC = &HFF
baseservo = 0.0 ' start of with the pulses being 0, ie not moving
basejointservo = 0.0
middlejointservo = 0.0
turngripperservo = 0.0
tiltgripperservo = 0.0
gripperservo = 0.0
Do
call pulseout(5, baseservo, 1) ' move joints
call pulseout(6, basejointservo, 1)
call pulseout(7, middlejointservo, 1)
call pulseout(8, turngripperservo, 1)
call pulseout(9, tiltgripperservo, 1)
call pulseout(10, gripperservo, 1)
If StatusQueue(Com1_In) Then
Call GetQueue(Com1_In, Data(1), 1)
If Data(1) = 255 Then ' if data byte is found do algorithm
Call GetQueue(Com1_In, Data(2), 2)
Call GetQueue(Com1_In, Data(3), 3)
' Write the 2 data byte to the BX-24 pins
Register.PortA = Data(2)
Register.PortC = Data(3)
if (Data(2) = 1) then
baseservo = csng(Data(3)) * 0.00001
elseif (Data(2) = 2) then
basejointservo = csng(Data(3)) * 0.00001
elseif (Data(2) = 3) then
middlejointservo = csng(Data(3)) * 0.00001
elseif (Data(2) = 4) then
turngripperservo = csng(Data(3)) * 0.00001
elseif (Data(2) = 5) then
tiltgripperservo = csng(Data(3)) * 0.00001
elseif (Data(2) = 6) then
gripperservo = 0.002
elseif (Data(2) = 7) then
gripperservo = 0.001
elseif (Data(2) = 8) then
exit do
end if
end if
End If
Loop
End Sub