BS2 program issue 2axis joystick(inbetween values)
Basically Ive tried taken a bunch of parallax parts and tried to make a simple wireless robot cotroller.
It has on one board a
BS2
433mhz tranceiver
two 2axis joysticks set for RCtime one channel each.so forward,backwards on one right left on the other.
The other has a
BS2
433mhz tranceiver
two HB25's
two 12v motors
Im very close I think my code works but when I make a forward movent on the joystick it continues to go forward after I let go.Thats where I need help getting a better solution.Ive played with it for a day added a bunch of stall comands in subgroups. It's not right.The code works just the stall comands are bogging down the code.It's trying to stall on one command while trying to go on another.I think. Heres what I got so far for code on the receiver.
It has on one board a
BS2
433mhz tranceiver
two 2axis joysticks set for RCtime one channel each.so forward,backwards on one right left on the other.
The other has a
BS2
433mhz tranceiver
two HB25's
two 12v motors
Im very close I think my code works but when I make a forward movent on the joystick it continues to go forward after I let go.Thats where I need help getting a better solution.Ive played with it for a day added a bunch of stall comands in subgroups. It's not right.The code works just the stall comands are bogging down the code.It's trying to stall on one command while trying to go on another.I think. Heres what I got so far for code on the receiver.
'Tcvr_RxCode_v1.1.bs2 com13
'{$STAMP BS2}
'{$PBASIC 2.5}
'---Variables-------------------------------------------
x VAR Word
y VAR Word
'---Pin Descriptions------------------------------------
HB25r PIN 13
HB25l PIN 12
'---initializations------------------------------------
DO : LOOP UNTIL HB25r = 1 ' Wait For HB-25 Power Up
LOW HB25r ' Make I/O Pin Output/Low
PAUSE 20 ' Wait For HB-25 To Initialize
PULSOUT HB25r, 750
DO : LOOP UNTIL HB25l = 1 ' Wait For HB-25 Power Up
LOW HB25l ' Make I/O Pin Output/Low
PAUSE 20 ' Wait For HB-25 To Initialize
PULSOUT HB25l, 750
LOW 1 ' T/R Line
'---main program------------------------------------------
DO
LOW 1
SERIN 0, 16468, [WAIT("!"), x.HIGHBYTE, x.LOWBYTE, y.HIGHBYTE, y.LOWBYTE]
HIGH 0
DEBUG ? x
DEBUG ? y
IF x = > 400 THEN
GOSUB backwards
ELSE: GOSUB stall
ENDIF
IF x = < 270 THEN
GOSUB forwards
ELSE: GOSUB stall
ENDIF
IF y = < 220 THEN
GOSUB left
ELSE: GOSUB stall
ENDIF
IF y = > 380 THEN
GOSUB right
ELSE: GOSUB stall
ENDIF
LOOP
'---Subroutines------------------------------------------
forwards:
PULSOUT HB25r, 850
PULSOUT HB25l, 850
PAUSE 20
RETURN
backwards:
PULSOUT HB25r, 650
PULSOUT HB25l, 650
PAUSE 20
RETURN
left:
PULSOUT HB25l, 850
PULSOUT HB25r, 650
PAUSE 20
RETURN
right:
PULSOUT HB25l, 650
PULSOUT HB25r, 850
PAUSE 20
RETURN
stall:
PULSOUT HB25r, 750
PULSOUT HB25l, 750
PAUSE 20
RETURN

Comments
Not sure how to do it though,any thoughts?
You can use the CASE command to good effect when dealing with joysticks. Note that th emain loop just continually checks all joysticks. Also, no function can stall the rest of the program.
I've attached some code for a fan-drive research barge from a few years ago. It used fwd-rev and left-right joysticks over a r/c link.
It probably won't be exactly what you need but you can see the use of timer subroutines and the CASE statement to accept a range of joystick values.
Cheers,
barge2spd_xcr.bs2
What I would do... Scale the (x,y) values to the PULSEOUT values with a little math and maybe RC values. That way you do not need all the conditional logic to convert joystick position to PULSEOUT values. You're code will be much more concise
edit it still never returns the same center value after you push one way then the other.
Ive made other changes that seemed to help