Shop OBEX P1 Docs P2 Docs Learn Events
BS2 program issue 2axis joystick(inbetween values) — Parallax Forums

BS2 program issue 2axis joystick(inbetween values)

graffixgraffix Posts: 389
edited 2011-11-22 20:39 in BASIC Stamp
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.
'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

  • graffixgraffix Posts: 389
    edited 2011-11-06 04:44
    This would be easier if the rctime value went back to center.Instead the value varys alot.I could use something like if x was inbetween values 270 and 310.then output 750.
    Not sure how to do it though,any thoughts?
  • stamptrolstamptrol Posts: 1,731
    edited 2011-11-06 06:13
    Hi,

    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
  • graffixgraffix Posts: 389
    edited 2011-11-06 06:40
    Hey THANKS! Im lookn up SELECT CASE and TO in the WAM and BSSyntax manual.I think its what I need.If theres more than one way to skin a cat?lets hear it.
  • Mike GMike G Posts: 2,702
    edited 2011-11-06 07:32
    SELECT CASE is like multiple IF... ELSEIF statements. But that's not the problem, it's your logic. For example, if the x value is less than 400, stall is called in the first if block. If X is less then 270 forward is called again in the next block. The same thing happens with the Y validations. You really should identify the stall parameters then call the correct SUB. The SELECT CASE will force your to write the appropriate logic.

    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
  • graffixgraffix Posts: 389
    edited 2011-11-22 20:39
    theres a dial to set center trim on these?Thanks Gordon
    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
Sign In or Register to comment.