|
Re: Setting Autonomous Settings from OI
Our team has had switches for autonomous on our operator interface for years. The way this is done is you take the imput from your switch (multi-position, what-haveyou) and store it in a variable so it is not reset when you go into autonomous mode. This is the code we use this year to do that. We have 4 swithes on our OI, two 5 position for delay and variation choices. And a 6 position for position choice and another for program choice.
/*****************read program switches.c*********************/
#include "ifi_aliases.h"
#include "ifi_default.h"
#include "ifi_utilities.h"
#include "user_routines.h"
#include "printf_lib.h"
void check_program (void)
{
//extern unsigned char variation;
unsigned char delay_val;
unsigned char var_val;
unsigned char prog_val;
unsigned char posit_val;
extern unsigned char position_choice;
extern unsigned char auto_choice;
extern unsigned char variation_choice;
extern unsigned char delay;
prog_val=rxdata.oi_analog08;
var_val=rxdata.oi_analog12;
delay_val=rxdata.oi_analog16;
posit_val = rxdata.oi_analog04;
if (prog_val<10)
{
auto_choice = 2;
}
else if( prog_val >20 && prog_val < 30 )
{
auto_choice = 3;
}
else if( prog_val >70 && prog_val < 90 )
{
auto_choice = 4;
}
else if(prog_val >140 && prog_val < 160)
{
auto_choice = 5;
}
else if(prog_val >120 && prog_val < 130)
{
auto_choice = 1;
}
else if(prog_val>240)
{
auto_choice = 6;
}
if (var_val<10)
{
variation_choice = 2;
}
else if( var_val > 55 && var_val<70 )
{
variation_choice = 3;
}
else if(var_val > 140 && var_val<150)
{
variation_choice= 4;
}
else if(var_val > 200)
{
variation_choice = 5;
}
else if( var_val <135 && var_val>110)
{
variation_choice = 1;
}
if (delay_val<10)
{
delay = 2;
}
else if( delay_val > 55 && delay_val<70 )
{
delay = 3;
}
else if(delay_val > 140 && delay_val<150)
{
delay = 4;
}
else if(delay_val > 200)
{
delay = 5;
}
else if( delay_val <135 && delay_val>110)
{
delay = 1;
}
/*********Get Starting Position****************/
if (posit_val<10)
{
position_choice = 2;
}
else if( posit_val >20 && posit_val < 30 )
{
position_choice = 3;
}
else if( posit_val >70 && posit_val < 90 )
{
position_choice = 4;
}
else if(posit_val >140 && posit_val < 160)
{
position_choice = 5;
}
else if(posit_val >120 && posit_val < 130)
{
position_choice = 1;
}
else if(posit_val>240)
{
position_choice = 6;
}
}
As you can see the outputs of the switches are not linear but those values can be obtained using a print f statement or the dashboard. The position selection is stored in an external variable "position_choise" that is defined in user_routines.c. This variable is not reset when initializing autonomous mode, and it is then looked at when it comes time to chose which auto function to run. ALSO note that this function is called in manual mode since the robot is disabled before it goes into auto, that is the only time the switches can be read.
__________________
"Better to remain silent and be thought a fool, than to speak out and erase all doubt"
Abraham Lincoln
|