Multiple JoySTick/Potentionmeter Problem

So, i have a robotic arm project that i am working on. I decided to use a joystick from a playstation 2 controller to control it. I extracted the joystick and wired up the potentiometer. When i use 1 potentiometer(to turn the base left and right) it works 100% correctly. However, when i try to add a second potentiometer/ joystick it doesnt work right. The second joystick will control the base not the shoulder that i want it to control. The code i use is below. I am using the picaxe 28x1 board.

 

Symbol less = 100
Symbol more = 150

main:
readadc 0, b0
if b0 < less then
gosub rotateleft
else
endif

if b0 > more then
gosub rotateright
endif

readadc 3, b3
if b3 < less then
gosub shoulderup
else
endif

if b3 > more then
gosub shoulderdown
else
endif
goto main

rotateleft:
servo 0, 75
goto main

rotateright:
servo 0, 225
goto main

shoulderup:
servo 1,75
servo 2,75
goto main

shoulderdown:
servo 1, 225
servo 2, 225
goto main

 

goto and gosub

Gotta keep an eye on the gosub’s, goto’s and returns.

You’ve got “goto main” on your subroutines.

How to do diagnostics

Have you proven its not hardware?  

Before trying to determine what is wrong with software, always verify all the hardware is working well.  

For example switch the connections and make sure the shoulder is 100% correct.

 

Next: - remove the else - its not needed and clutters things up

if b3 < less then
gosub shoulderup
else
endif 

 

also - I noticed if your moving the base you’ll be starving the shoulder

Refactor … It’s a “good” thing .

Symbol less = 100
Symbol more = 150

loop:
readadc 0, b0
if b0 < less then 
  servo 0, 75
else if b0 > more then
  servo 0, 225
endif

readadc 3, b3
if b3 < less then
  servo 1, 225
  servo 2, 225
else if b3 > more then
  servo 1,75
  servo 2,75
endif

goto loop


This won’t starve … 

Now…

I tried the code that jinx posted but right now i couldnt get it to work. Anyway, i revised my code and this is what i got(below). Now, i can use the x and y axis of one joystick. It works ok. When i rotate the base. It works perfectly. When i go to move the shoulder the base rotates as well although i dont want it to.??? Waiting for more parts… then i will hook up other joystick but overall i have progress.

Symbol less = 75
Symbol more = 175

main:
readadc 0, b0
if b0 < less then
gosub rotateleft
else
endif

if b0 > more then
gosub rotateright
endif

readadc 1, b1
if b1 < less then
gosub shoulderup
else
endif

if b1 > more then
gosub shoulderdown
else
endif
goto main

rotateleft:
servo 0, 75
return

rotateright:
servo 0, 225
return

shoulderup:
servo 1,75
servo 2,75
return

shoulderdown:
servo 1, 225
servo 2, 225
return

gotta fix that

gootta fix that one up there

This is wiring…

This is hardware…

We need a clear picture of your board and the joystick.

k

ok

Pictures

102_0218.jpg

------------------------------------------------------------------------------------------------------------------------------------

102_0228.jpg

--------------------------------------------------------------------------------------------------------------------------------------

102_0230.jpg

----------------------------------------------------------------------------------------------------------------------------------

102_0232.jpg

----------------------------------------------------------------------------------------------------------------------------------

These are the best i could get. Let me know if u need better

Darlington chip

The darlington chip is still in place. Remove it and in its place, add a 330 resistor for each servo output.

Have you done a debug yet? I assume you already did this to see if your numbers are coming in wrong or if they are coming in right and going out wrong. If not, I would.

Yes

I am pretty sure the resistor  is already in there, it is just a black version. When i did a debug the inputs seemed fine.

Code proposal

Hi Jaryd,

 

This code should allow you to move arm slowly and stop in any position

 

symbol less = 100
Symbol more = 150
symbol basepos =b11
symbol armpos = b12
let basepos = 150
let armpos = 150

main:
readadc 0, b0
if b0 < less then
gosub rotateleft
endif

if b0 > more then
gosub rotateright
endif

readadc 3, b3
if b3 < less then
gosub shoulderup
endif

if b3 > more then
gosub shoulderdown
endif

pause 10       REM for slower movement
goto main

rotateleft:
let basepos = basepos - 1 min 75
servo 0, basepos
return

rotateright:
basepos = basepos + 1 max 225
servo 0, basepos
return

shoulderup:
let armpos = armpos - 1 min 75
servo 1,armpos
servo 2,armpos
return

shoulderdown:
let armpos = armpos + 1 max 225
servo 1, armpos
servo 2, armpos
return

thanks,

thanks,