Shop OBEX P1 Docs P2 Docs Learn Events
Selectable Program Modes in one program — Parallax Forums

Selectable Program Modes in one program

Scott PortocarreroScott Portocarrero Posts: 72
edited 2009-08-04 06:01 in BASIC Stamp
I have two separate programs I would like to combine into 1. The first program is the autonomous one and the second robot is the remote control one. Basically at processor startup I would like the BS2 to wait for a level of 556 or 557 (AUX2 switch position 0 on remote control) which means RC mode. Otherwise goto autonomous mode. Can someone take a look at my code and tell me what I am doing wrong?

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2009-08-04 02:54
    FREQOUT Piezo, 2000, 3000               ' Signal Program Start/Reset
    PULSIN BPS,1,pselect
    DEBUG "Waiting for Program Mode Instruction.....", CR
    
    PAUSE 500
    
    IF (pselect = 556 OR pselect = 557) THEN                 ' Read Program Switch value in Pos. 0
      DEBUG "We're going RC!!!", CR
      GOSUB rc
    ELSE
      DEBUG "we're going Autonomous!!!", CR                  ' Read Program switch value in any Position of RC off = 0
      GOSUB main
    
    ENDIF
    
    



    It might be better to put the pulsin command inside a for..next loop that executes a bunch of times - something like this;
    FREQOUT Piezo, 2000, 3000               ' Signal Program Start/Reset
    DEBUG "Waiting for Program Mode Instruction.....", CR
    
    FOR i = 1 TO 25
    PULSIN BPS,1,pselect
    IF (pselect = 556 OR pselect = 557) THEN                 ' Read Program Switch value in Pos. 0
      DEBUG "We're going RC!!!", CR
      GOSUB rc
    ENDIF
    PAUSE 20
    NEXT
    
    
    DEBUG "we're going Autonomous!!!", CR                  ' Read Program switch value in any Position of RC off = 0
    GOSUB main
    



    Rich H
  • iDaveiDave Posts: 252
    edited 2009-08-04 03:35
    Not sure if your using pulsin correctly. Are u using a universal remote? Do u have an IR detector connected to pin 3?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "THE ONLY TRUE WISDOM IS IN KNOWING YOU KNOW NOTHING." - SOCRATES
  • Scott PortocarreroScott Portocarrero Posts: 72
    edited 2009-08-04 03:49
    I am using a servo output on a JR receiver.
  • Scott PortocarreroScott Portocarrero Posts: 72
    edited 2009-08-04 03:55
    Hey WG9FO
    It might be better to put the pulsin command inside a for..next loop that executes a bunch of times said...




    Out of curiosity why did you choose i = 1 to 25 and why would I want it to loop?
  • W9GFOW9GFO Posts: 4,010
    edited 2009-08-04 04:06
    Why 556 or 557?

    For instance with the autonomous select switch in the ON position the pulse width that your receiver is sending may be 1100, with it OFF it may be 1900. That would correspond to PULSIN values of 550 and 850. As it is now you are only going into rc mode if the pulse width is within a 4 microsecond window.

    Better to say - IF (pselect < 600) THEN...

    Rich H
  • W9GFOW9GFO Posts: 4,010
    edited 2009-08-04 04:10
    Scott Portocarrero said...


    Out of curiosity why did you choose i = 1 to 25 and why would I want it to loop?

    25 times through the loop is close to the same as the pause of 500 that you had originally. I don't know the details of exactly how the PULSIN command works, looping makes sure that the input is thoroughly checked. With it running the PULSIN only one time, something could occur where the signal gets missed.
    Rich H
  • Scott PortocarreroScott Portocarrero Posts: 72
    edited 2009-08-04 05:07
    cool that worked! How would I make the program look for when ever the switch has changed so I can move from autonomous to rc on the fly? Right now I can only do it at startup and can't switch back unless I push the reset button on the BOE.
  • W9GFOW9GFO Posts: 4,010
    edited 2009-08-04 06:01
    Scott Portocarrero said...
    cool that worked! How would I make the program look for when ever the switch has changed so I can move from autonomous to rc on the fly? Right now I can only do it at startup and can't switch back unless I push the reset button on the BOE.

    Great! Which part worked?

    I would start by having two subroutines. Autonomous and RC

    In your rc loop I would change it to;
    
    RC:
    
    DO
    PULSIN RCS,1,whl
    PULSIN RCT,1,thr
    PULSIN BPS,1,pselect 
    
    PULSOUT 12,whl
    PULSOUT 13,thr
    
    IF (pselect = > 600) THEN        
    GOSUB Autonomous
    ENDIF
    
    PAUSE 15
    LOOP
    



    I would then add this to your Autonomous (main) routine;
    PULSIN BPS,1,pselect 
    
    IF (pselect = < 600) THEN        
    GOSUB RC
    ENDIF
    



    That way every time through the loop it will check to see if it needs to do something different.

    If there is no signal when PULSIN listens while in the loop it will cause a delay of about 1/8 of a second before it times out. That may cause a problem if you want it to run with the receiver off, if you will always have the receiver on then it would be fine.

    Rich H
Sign In or Register to comment.