|
|
![]() |
![]() |
|
|||||||
|
![]() |
Thread Tools | Rate Thread | Display Modes |
#1
![]() |
||||
|
||||
picking auto program
whew, the extension might give me the time to get my "auto code picking" program working, so that I dont have to carry around my laptop during the competition. I have written several auto programs that have worked surprisingly well, but I have been having a bit of trouble writing code to select which one I want to run. I built a switch box wired to rc_sw1 through rc_sw8 (rc_sw0 used for the pressure switch) and plugged it into the RC's digital inputs, but it fails to select the program I wish to run. Could someone provide me with some guidance on the matter?
-Mike |
#2
![]() |
||||||
|
||||||
It is impossible to tell you what is wrong with the details given.
What types of switches are you using, and how are they connected to the RC? Does the box you made pinout with a multimeter the way that you think it should? Does a debug statement showing the states of the switches show what you expect. What code are you using to try to switch programs? Answer those, and people here will be much better able to help you. |
#3
![]() |
||||
|
||||
What types of switches are you using, and how are they connected to the RC?
-They are 2 position switches, on and off. Each switch has one connection to a digital input pin and the other goes to a common digital input ground. Does the box you made pinout with a multimeter the way that you think it should? -This was tried, everything worked as it should Does a debug statement showing the states of the switches show what you expect. -I have no idea how debug works What code are you using to try to switch programs? -I was hoping a simple IF THEN in the autonomous section of code would perform this task example: counter var word counter=0 IF auton mode = 1 THEN select counter IF rc_sw1=1 THEN start_left: IF rc_sw2=1 THEN start_right: 'Starting on left side of field start_left: (left auto program here) goto imdone: 'Starting on right side of field start_right: (right auto program here) goto imdone: ELSE 'Resume Human Control imdone: |
#4
![]() |
||||
|
||||
IF auton mode = 1 THEN
First of all, I'm not sure if your line "IF auton mode = 1 THEN" is a typo cause you were typing fast, or if it's copied from your code. The variable is "auton_mode," so double check that (although I'd assume you'd get a tokenize error if you forgot the _ in your code).
Another problem may be the actual status of this bit. Have you followed the instructions on enabling auto mode (here or here)? There are basically two ways to do it: set the team number to zero, or make a dongle (the dongle I made this year is shown below). If you're checking the auton_mode bit, you have to have turned it on in the first place. Not sure if you did this or not - you never specified. -- Another suggestions: just a small note: it would have been a lot more simpler and elegant if you just hooked the left and right side to one toggle switch... IF sw = 1 THEN <left code> ELSE <right code> But with the goto imdone, it'll still work. |
#5
![]() |
||||
|
||||
[edit]Forgot to upload that pic of my dongle.... apparently you can't upload attachments to a attachmentless post when editing it... *glare at Brandon*)
|
#6
![]() |
|||
|
|||
Quote:
if auton_mode = 0 then goto end_o_this_code {auto mode stuff, like if left_sw then goto the_left, &c} end_o_this_code: rest of program: |
#7
![]() |
|||||
|
|||||
I like
direction VAR bit program VAR bit(2) direction = sw5 program = sw6 <<1 + sw7 program1 CON 0 if program = program1 then ... endif if program = ... |
#8
![]() |
||||
|
||||
eh, problem there is you're wasting precious bits. Last year we used up ALL of our memory for our program, and this year we've been VERY conservative with our memory (i.e. if you put your light-relay-on code at the very end of your code, then you can use the two light relay bits as temporary swap bits cause they're just hard-coded later on).
For example... direction = sw5 If you're setting direction to be equal to sw5, there's no need to make a seperate bit for it. Just make "direction" an alias for "sw5" if you don't want to use sw5 (aliases take no memory). Same thing with program1 CON 0 I see no reason for this. Just make the if statement "IF program = 0...." On PC programming, there's no real problem with memory allocation being as leniant as you're doing it if it's something as small as the robot code is (although it's much more efficient if you use less memory). However, with something that has as little memory as a PBASIC stamp, you should be really careful with memory allocation - otherwise, you're going to run out. |
#9
![]() |
|||||
|
|||||
Quote:
Right...I have room for 20 more bytes in my auton program (160 bits). ![]() ![]() You know there are 8 slots on the RC right? |
#10
![]() |
|||||
|
|||||
Here...Lemme put into comments what need to be fixed:
'******************** counter var word counter=0 IF auton mode = 1 THEN 'needs to be auton_mode select counter IF rc_sw1=1 THEN start_left: 'lose the colon... IF rc_sw2=1 THEN start_right: 'lose the colon 'Starting on left side of field start_left: (left auto program here) goto imdone: 'Starting on right side of field start_right: (right auto program here) goto imdone: ELSE 'Resume Human Control imdone: '************************** Here is what it should look like corrected (with a few tweaks added for efficency): '************************** counter var word counter=0 IF auton_mode = 1 THEN goto auton_on else goto imdone endif auton_on: select counter IF rc_sw1=1 THEN start_left IF rc_sw2=1 THEN start_right 'Starting on left side of field start_left: (left auto program here) goto imdone 'Starting on right side of field start_right: (right auto program here) goto imdone 'Resume Human Control imdone: '********************** You could also just use 1 switch for the left-right selection. Have it if the switch is open, then it goes left, else it goes right. This way, you avoid the instance of having both acidetally closed or open. Here is what your code would look like: '********************** counter var word counter=0 IF auton_mode = 1 THEN goto auton_on else goto imdone endif auton_on: select counter IF rc_sw1=1 THEN goto start_left else goto start_right endif 'Starting on left side of field start_left: (left auto program here) goto imdone 'Starting on right side of field start_right: (right auto program here) goto imdone 'Resume Human Control imdone: '********************* Hope this helps. Bill B. Last edited by Scooter : 02-18-2003 at 07:54 PM. |
#11
![]() |
||||
|
||||
select var nib 'in the variable initialization part
select = (rc_sw1 * 2) + rc_sw2 'in the start of autonomous mode if select = 1 then follow_the_yellow_brick_road if select = 2 then fly_vertically_through_space if select = 3 then seek_and_stack_all_drivers_on_opposing_team 'put regular code here Make sure that you don't run through 'two sections at once The preceding code may or may not have been taken from our robot code ![]() But you get the idea. |
#12
![]() |
|||||
|
|||||
the word "select" is a reserved operator. choose a different one.
|
#13
![]() |
||||
|
||||
I got ours to work with a 3-position switch using simple if/then statements.....
|
#14
![]() |
||||
|
||||
Oh. It wasn't the word I used anyway.
What is select used for then? |
#15
![]() |
|||||
|
|||||
Quote:
From the PBASIC 2.5 Documentation: Quote:
Last edited by Greg Ross : 02-21-2003 at 04:31 PM. |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
2-week FIRST summer program @ WPI | ColleenShaver | General Forum | 20 | 05-31-2009 02:02 AM |
Fried program slots? | Jeff Waegelin | Programming | 18 | 03-19-2003 05:08 PM |
Ahh! Program trick confusing! | archiver | General Forum | 9 | 06-24-2002 01:26 AM |
Credits for FIRST program. | archiver | General Forum | 6 | 06-23-2002 11:16 PM |
An invitation for HS Juniors | archiver | General Forum | 0 | 06-23-2002 09:51 PM |