Author Topic: Anyone know whats wrong?  (Read 1516 times)

0 Members and 1 Guest are viewing this topic.

Offline jakx12Topic starter

  • Robot Overlord
  • ****
  • Posts: 183
  • Helpful? 2
Anyone know whats wrong?
« on: July 10, 2009, 02:24:26 PM »
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:
Code: [Select]
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


Need help with an algorithm or a maths related problem? Ill be glad to help :)

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Anyone know whats wrong?
« Reply #1 on: July 10, 2009, 08:47:01 PM »
Most servos spaz a little bit when they are first powered.

Offline kpmcgurk

  • Robot Overlord
  • ****
  • Posts: 152
  • Helpful? 3
  • Robot Love?
Re: Anyone know whats wrong?
« Reply #2 on: July 10, 2009, 09:11:32 PM »
so when you say "spasm" do you mean that they just twitch a little, or do they really dramatically move? I am not familiar with basic so I cant help you on that end, I just want to know more on this for future purposes!
some people are just Born smart, but some people have to work for it, and those are the people who succeed.

http://www.proboticworld.com

Offline jakx12Topic starter

  • Robot Overlord
  • ****
  • Posts: 183
  • Helpful? 2
Re: Anyone know whats wrong?
« Reply #3 on: July 11, 2009, 01:59:49 AM »
i know when they first power they twitch. This is like really strong. but i found out it might be to do with the fact that sending a pulse of 0 causes the servos to still move. So ill try changing the code later
Need help with an algorithm or a maths related problem? Ill be glad to help :)

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
Re: Anyone know whats wrong?
« Reply #4 on: July 11, 2009, 07:13:31 AM »
There are 2 things to do to eliminate that twitch:
- do not power the servos at the same time you power on the microcontroller
- set the start position to be the position of the servos when the arm is relaxed (inert) so the servos do not have to move at all at start

After you send the start position to the servos, power them up, then wait a bit and send the home position that you want the arm to stay when not in use. It may be the same position as the start position, but may be different.
Check out the uBotino robot controller!

Offline jakx12Topic starter

  • Robot Overlord
  • ****
  • Posts: 183
  • Helpful? 2
Re: Anyone know whats wrong?
« Reply #5 on: July 11, 2009, 03:19:17 PM »
no the problem is that they move when in the 'relaxed' position. I think its to do with either the MCU re-booting due to current issues or that if one calls a pulseout with a pulse width of 0 it still moves. I need to fix the arm so will try the new code later.
Need help with an algorithm or a maths related problem? Ill be glad to help :)

Offline Tazdevil

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Anyone know whats wrong?
« Reply #6 on: July 14, 2009, 10:25:09 AM »
I had servo's twiching when the programmer was hooked up. I upgraded the battery wiring and added a cap closer to the micro which solved the issue.

 


Get Your Ad Here

data_list