|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Can't get auto mode to run with OI switches
Hey all..
I have a potentiometer with detents that is mounted on the oi controller. I have no idea whats going on.. I set up a static int newautoselect inside user_control.h, int currentauto; unsigned int autopos; unsigned int temp_autopos; int autocount; autopos = p2_wheel; autocount ++; if(autocount >= 26) { autopos = currentauto; } if(currentauto > 20 | currentauto < 40) { newautoselect = 1; } else if(currentauto > 50 | currentauto < 60) { newautoselect = 2; } else if(currentauto > 100 | currentauto < 120) { newautoselect = 3; } else if(currentauto > 130 | currentauto < 150) { newautoselect = 4; } else if(currentauto > 160 | currentauto < 190) { newautoselect = 5; } else if(currentauto > 200 | currentauto < 250) { newautoselect = 6; } why doesnt auto mode pick this up? |
|
#2
|
|||||
|
|||||
|
Re: Can't get auto mode to run with OI switches
When the OI is switched into autonomous mode it no longer reads input from the joystick ports. All input values get zeroed (127 for analogs) until it is placed back into standard operating mode. What you'll want to do is read the input value only when the robot is not in auto mode, then evaluate it when the robot is. Otherwise it will always read 127 as the selector input, no matter what position it's in. Remember that the OI can receive input from the ports when the robot is disabled, which means that you will be able to set the autonomous mode selector at any point before the match begins.
|
|
#3
|
|||
|
|||
|
Re: Can't get auto mode to run with OI switches
Quote:
and use "int newautoselect = 0;", outside of any routine, in one of the files that the header is included in. If you use "static int newautoselect;" in the header a different instance of newautoselect is what you will get in each file the header is included in and desired communication will not occur. |
|
#4
|
||||
|
||||
|
Re: Can't get auto mode to run with OI switches
You need to save the value of the OI reading the last cycle before you enter autonomous.
I recommend creating a char to hold the state of the OI input and updating it in Process_Data_From_Master_uP() as long as the autonomous_mode flag is not set. Code:
unsigned char currentauto = 0; //Set outside function to make it global
void Process_Data_From_Master_uP(void)
{
Getdata(&rxdata);
if(!autonomous_mode)
currentauto = p2_wheel;
// Remainder of function
}
Code:
extern unsigned char currentauto; The only thing, I'm not sure if the name of the flag (autonomous_mode) is right, I don't have code to reference at the moment. |
|
#5
|
||||
|
||||
|
Re: Can't get auto mode to run with OI switches
Okay,I just put in Getdata(&rxdata); if (!autonomous_mode) { blha blah blah; the other stuff up there goes here! } See, i moved the int declarations and that other stuff.. and moved it up to the top of the user_routines.c int currentauto; int newautoselect; unsigned int autopos; unsigned int temp_autopos; int autocount; Now in user_routines_fast.c, extern unsigned char currentauto; extern unsigned char newautoselect; WHAT IS WRONG!!?!?! ![]() |
|
#6
|
||||
|
||||
|
Re: Can't get auto mode to run with OI switches
Quote:
Code:
autopos = p2_wheel;
autocount ++;
if(autocount >= 26)
{
autopos = currentauto;
}
I believe that that (last) line should be "currentauto = autopos;"... Regards, Mike |
|
#7
|
||||
|
||||
|
Re: Can't get auto mode to run with OI switches
Okay,
Based on a if and elseif statement, the bot would read the potentiometer on the OI which is p2_wheel, called autopos. Autopos is going to equal to currentauto within 26 ms. once that happens, current auto is compared using a little deadband then setting newautoselect. newautoselect is now supposed to be pulled from the user_routines.c now newautoselect is put into a little if and then and then the new auto mode is supposed to be selected. Shouldnt that code already work? |
|
#8
|
|||
|
|||
|
Re: Can't get auto mode to run with OI switches
Quote:
|
|
#9
|
|||||
|
|||||
|
Re: Can't get auto mode to run with OI switches
Indirectly related, but you should also code for the in-betweens: What If currentautro were to evaluate at, say 45? At least trap and manage the error.
Don |
|
#10
|
||||
|
||||
|
Re: Can't get auto mode to run with OI switches
Quote:
You can find more information about bitwise operations here |
|
#11
|
||||
|
||||
|
Re: Can't get auto mode to run with OI switches
Yeah.. I forgot about using &, the code has been replaced. I'm going to write the newautomode into the eraseable memory because im having SO much trouble with this.. Hopefully that would work.
![]() |
|
#12
|
|||
|
|||
|
Re: Can't get auto mode to run with OI switches
Quote:
and the definitions in user_routines.c You need them to be consistent. If you put the extern declarations in a common header file that is also included in user_routines.c the compiler will catch this sort of error for you. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A statistical analysis of the "autonomous advantadge" | Greg Marra | General Forum | 51 | 25-03-2006 21:09 |
| Favorite Autonomous Mode | George A. | General Forum | 49 | 12-05-2005 15:33 |
| I fail to see the point.. | randomperson | Programming | 14 | 27-03-2003 11:38 |
| picking auto program | Mike375 | Programming | 19 | 03-03-2003 15:47 |
| Need help with 255 Variable | Joseph F | Programming | 18 | 26-02-2002 14:49 |