buttons

im extremely confused about buttons. ive read the section in the basic manual several times, and played with them a little. however, ive gotten two conflicting definitions of the last parameter on target state. 1) that is says which state the button should be in in order to branch 2) that when in downstate, 0 it doesnt branch and 1 it does. also, ive been trying to program a kill switch in that is basically a button statement that says when the button is pressed, goto a subroutine that puts the program into an infinite loop. ive written this program before for the edu robot and had it work, and i also have last year’s code which is working. but mine isnt, and i cant figure out why.the program goes into the kill switch subroutine whether the button is pressed or not, and wont get out of the subroutine. here is the code:
the pin is p4_sw_aux1, and ive already tested the mechanical switch and it works physically.

*in main section
BUTTON p4_sw_aux1, 0, 255, 0, wksp, 0, KillSwitch:

*in subroutine section
KillSwitch:
Serin COMA\COMB, INBAUD, [oi_swA,oi_swB,rc_swA,rc_swB,p2_x,p1_x,p4_x,p3_x,PB_mode,packet_num,p2_y,p1_y,p4_y,p3_y,p2_wheel,p1_wheel,p4_wheel,p3_wheel]

BUTTON p4_sw_aux1, 0, 255, 0, wksp,1, Mainloop:

Serout USERCPU, OUTBAUD, [255,255,127,0,127, 0, 127,127,127,127,127,127,127,127,127,127,127,127,127,127]

GOTO KillSwitch:

I thought buttons were those things teams handed out at the comps…

LOL

ermm…

that may possibly be the most complicated way to do anything i have ever seen…

a button is nothing more than a if-then loop

example, using p1_sw_trig :
(the trigger swich on the joystick plugged into P1)

panicbutton: 'lables the loop (neatness)
if p1_sw_trig = 1 then mysub: 'if button is pressed then goto sub
goto endsub: 'if it isnt… then dont

mysub: 'put whatever you want the
out 8 = 1 'button to do here
out8 = 1 'this example Turns on some LED’s
out9 = 1
out10 = 1

endsub: resumes the rest of the code


as for infinite loops… you really cant do that unless you use a do while loop, wich pretty much is the same structure. Rbayer posted a discription of the commands in the Pbasic programming section, you may want to check that out!

~Pyro

and you may want to avoid the Serin/out things… you really dont need more than 2 at most

BUTTON is a PBASIC command that is not available to us in the Innovation First Robot Controller. Only a small number of the PBASIC commands are actually of use to us.

The BUTTON command works on a physical pin. The BS2SX our robot programs run on doesn’t have access to any of the inputs and outputs on the RC.

p4_sw_aux1 is aliased to a bit in either oi_swA or oi_swB which is passed to us via the SERIN command. You will need to do something like what PyroPhin said to do.

Probably the easiest way to do what you want to would be something like this (I’m not even going to try for proper syntax, so watch out):

MainLoop:
Serin (blah blah blah)
If kill_switch then skip_all:
blah
blah 'code to do stuff
blah
blah
blah 'code to do more stuff
blah
skip_all:
serout (pwm1, pwm2, etc.)
Goto MainLoop:

This was written (poorly, by a programmer who hasn’t slept in days) in “old-style” PBASIC… 2.0, whoo… so… tired… eyes so heavy… must program robot… make it clean my room… ::yawn:: :o

whats with the excessive use of the serouts? you can route anything you need through the one statement if you code it right

(im really just curious, not being a smartypants)
~Pyro

hmmm…thanks for the alternate advice, but whats wrong with what i wrote? i hate unsolved programming bugs. they keep me up at night, and when i fall asleep its to dream of possible reasons for the bug. also, my team mates and i were wondering what the difference was between using an if statement or a button statement. i suppose all the loop stuff… could it do with an interrup or something like in java?
thanks

the multiple serouts are to output neutral values to all the the motors to turn everything off. if u stop outputting everything, will the motors stop or stay the same as they were before the program went into an infinite loop?

Maybe you could try posing this in the programming forum if you wan more responses. That seems to be where it belongs.

*Originally posted by rosebud *
hmmm…thanks for the alternate advice, but whats wrong with what i wrote? i hate unsolved programming bugs. they keep me up at night, and when i fall asleep its to dream of possible reasons for the bug. also, my team mates and i were wondering what the difference was between using an if statement or a button statement. i suppose all the loop stuff… could it do with an interrup or something like in java?
thanks

I can’t explain why your eduBot code works. Maybe you could post that code for me to analyze too. But I do know why it won’t work on the full sized robot controller. Please reread my previous post. YOU CANNOT USE THE BUTTON COMMAND IN THIS APPLICATION (the innovation first full size robot controller.)

Just to dig a little further: the PIN parameter on your BUTTON command (p4_sw_aux1) is a bit sized variable. Which means that when the BUTTON command is executed, it will sometimes read pin 0 and sometimes pin 1 (depending upon the state of the switch on the OI). I don’t know what, if anything, is connected to pin 0 inside the RC, but pin 1 is the pin the serin command uses to read its data from the master microprocessor. In either case, you’re NOT reading aux switch 1 on port 4 on the operator interface which is what I believe was your intention.

As for the target state parameter, I’m afraid I don’t know which way it’s going to work. I think I saw the same conflicting information you saw: 1) was in the command description, and 2) was from the example code. Am I correct? I don’t know of any way (using either the eduBot or the full sized robot controller) to check which way it will work, but my team has one of Parallax’s BOE 'Bots. Maybe if I get a round tuit :wink: one of these days, I will check it out.

hmmm… now im really confused. from the pbasic manual the first parameter is the name/alias of the pin it will be gathering information from, not the actual number of the pin it should be looking at. also, ive used the button command numerous times and had it work, both with the edurobot and the full sized rc, on the joystick buttons and switches hooked up to a port on the operator interface. however, im curious why u say the button command isnt valid for bs2sx. can u please refer me to a manual or something so i can look it up? id really appreciate solving this problem. ill also be posting my original message under programing. thanks!

Rosebud,

Have you read the Innovation First documentation? Remember, the control system was built by Innovation First. They happened to use the Parallax BASIC Stamp 2sx processor, but we have to live within the architecture they chose.

Here is the list of some documents you should be familiar with:
Overview:

  • Control System Overview

Quick Start Guides:

  • Full-Size Control System Quick Start Guide
  • EDU Control System Quick Start Guide
  • EDU Default Software Quick Start Guide

Reference Guides:

  • Full-Size RC Reference Guide
  • Operator Interface Reference Guide
  • EDU-RC & Motherboard Ref Guide
  • Programming Reference Guide

All of these are available at innovationfirst.com.

At the end of the Programming Reference Guide, they have a list of PBASIC commands which are valid for the IFI control system. BUTTON is NOT on the list.

My question is, why do you need the BUTTON command? I don’t see much functionality to an auto-repeat button with a debounce feature