Ok so basically i have built a robotic arm and would like to control it from the computer.
I have done the application for the computer and it works. I have also programmed the
firmware for the bx-24 chip. However when i turn it on, all the servo's move so the arm
looks like it is having a spasm. I dont know why this is. Could someone please check
through it and tell me whats wrong, many thanks, zack.
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
------------------------------------

(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )