let w5 = 75
let w4 = 1
let b1 = 0
let b2 = 0
let b3 = 0
main:
if pin4=1 then anticlockwise
if pin5=1 then clockwise
if pin6=1 then claw
readadc 1,b4
readadc 2,b5
readadc 3,b6
if b4 != b1 then analyse_1
if b5 != b2 then analyse_2
if b6 != b3 then analyse_3
goto main
" ---------------------------------- servos --------------------------------- "
analyse_1:
w1 = b1 * 2 / 3 + 75
servo 4,w1
goto main
analyse_2:
w2 = b1 * 2 / 3 + 75
servo 5,w2
goto main
analyse_3:
w3 = b1 * 2 / 3 + 75
servo 6,w3
goto main
[code/]
This part of my programming moves a robotic arm i made; analyse 1 to 3 move 3 seperate servos according to the position a variable resistor is in. When i tried to execute the program i found that it would only be able to move one servo a time, so if i moved 2 variable resistors only one of the servos moved.
You see the way i understand it is that the program is excuted from top to bottom, but what if you want more than one sideprogram running at the same time. For example, scanning for an IR signal and communitacating with a different robot aswell as navigating through a maze (ie having touch sensors active)...
lol, i hope tht made it a little bit more clear =S
let w5 = 75
let w4 = 1
let b1 = 0
let b2 = 0
let b3 = 0
main:
if pin4=1 then anticlockwise
if pin5=1 then clockwise
if pin6=1 then claw
readadc 1,b4
readadc 2,b5
readadc 3,b6
if b4 != b1 then analyse_1
if b5 != b2 then analyse_2
if b6 != b3 then analyse_3
goto main
" ---------------------------------- servos --------------------------------- "
analyse_1:
w1 = b1 * 2 / 3 + 75
servo 4,w1
goto main
analyse_2:
w2 = b1 * 2 / 3 + 75
servo 5,w2
goto main
analyse_3:
w3 = b1 * 2 / 3 + 75
servo 6,w3
goto main
" --------------------------------- end servos ------------------------------ "
" ----------------------------------- claw ---------------------------------- "
claw:
if w4 >= 1 then
goto open_claw
else
goto close_claw
endif
close_claw:
w4 = 0
servo 7,w5
w5 = w5 + 1
if pin7=1 then main
goto claw
open_claw:
servo 7,220
w4 = 1
gotomain
" -------------------------------- end claw -------------------------------- "
" ------------------------------ stepper motor ----------------------------- "
clockwise:
let pins = %00001100
pause 250
let pins = %00000110
pause 250
let pins = %00000011
pause 250
let pins = %00001001
pause 250
if pin5=1 then main
goto clockwise
anticlockwise:
let pins = %00001001
pause 10
let pins = %00000011
pause 10
let pins = %00000110
pause 10
let pins = %00001100
pause 10
if pin4=1 then main
goto anticlockwise
" ---------------------------- end stepper motor ----------------------------- "
ok so i think i understand what your tell me to do; just got on question about that. Basically when you move the variable resistor it will already have started to excute the code before having completed the movement of the variable resistor, hence not having the final position of the variable resistor, but just a bit when you started turning it. which is why i left it in a loop so i could check everytime untill the variable resistor stopped moving. is this a problem?Welcome to the PICAXE forum.
All SERVO commands will operate in parallel so you shouldn't have a problem. It seems most likely to be a program flow error - In this case where b4 != b1 the flow goes to analyse_1, then to main, and it remains in that loop until b4 does equal b1. During that time it will not execute the b5 != b2 code etc.
Change the "goto main" to "return" in the analyse_1/2/3 routines, change the "if ... then analyse_1/2/3" to "if ... then gosub analyse_1/2/3" and that should resolve the problem.
hmm... thats a shame =/ so ye, i was thinking of either having 2 pics, one which would run the communications, and that would then be able to communitcate with the other pic, I dont know how well this would work though, perhaps as you suggested with an interrupt command it could work. Do you reckon that could work? communication with one pic and then driving with the other?No, the PICAXE cannot do two things at the same time, except those things which are handed-off to internal hardware to handle, servos, PWM, background serial, I2C Slave and so on. Most commands are "blocking", in that they wait for whatever a particular command expects until continuing; infra red receive commands will wait until a valid infra-red signal is received.
There are ways round that; interrupts, bit-banged IR receive, using smaller PICAXE's to off-load the polling for IR commands to. What you have to do is emulate the parallel processing you want.