OI Input Autonomous

What our team is trying to do this year is to select our Autonomous mode by using the joystick buttons or some other type of button mounted on our control box. While searching Chief Delphi forums for possible solutions we have stumbled upon this code:

It’s written by Kevin Watson. We used a slightly modified version of it.

Quote:
void auton_selector(void)
{
static char last_sw1;
static char last_sw2;

if(AUTON_UP == 1 && AUTON_UP != last_sw1)
{
if(auton_select < MAXAUTONROUTINES)
auton_select++;
else
auton_select=99;
}
if(AUTON_DN == 1 && AUTON_DN != last_sw2 && auton_select > 0)
{
if (auton_select == 94)
auton_select=MAXAUTONROUTINES;
else
auton_select–;
}
last_sw1 = AUTON_UP; //oneshot the trigger and top buttons
last_sw2 = AUTON_DN;

User_Mode_Byte = auton_select;

}
User_Mode_Byte is the user display on the OI. Use that little button to change to it.

AUTON_UP/DOWN are the defines to which a joystick button or something similar.

Now we are stumped as we are unable to make this code work for us. First of all we are unsure in which of the program files should we put this function into. Second of all when we tried simply pasting this code into our user_routines.c or user_routines_fast.c functions the compiler came out with a bunch of errors. Can anyone take a look and maybe guide us to a solution if possible. Thanks in advance!

Hmm, why would anyone want to select autonomous modes from the OI… :cool:

A better question is, will the drivers need to step back from the OI BEFORE the refs move the rack?

I’d guess not, but I’m sure it can be asked on the Q&A, this is the closest I’ve found.

Many teams have selected auton on the OI for years, seeing it as better than putting switches on the robot.

Put that snippet of code in user_routines.c and call it from the same place you’re reading the joysticks for other purposes. Default_Routine(), perhaps.

Your compiler errors are probably because you didn’t get the hint to replace AUTON_UP and AUTON_DN with the actual OI controls you will be using to step the number up and down. p1_sw_trig and p1_sw_top, for example. You will also have to declare auton_select as a global variable so you can use it in your actual autonomous routine.

I have a few questions. Well first of all I edited the code and this is what it looks like now as I try to compile:

void auton_select(void)
{
static char last_sw1;
static char last_sw2;

if(p1_sw_trig == 1 && p1_sw_trig != last_sw1)
{
if(auton_select < 2)
{
auton_select++;
}
else
{
auton_select=99;
}
}
if(p1_sw_top == 1 && p1_sw_top != last_sw2 && auton_select > 0)
{
if (auton_select == 94)
{
auton_select= 2 ;
}
else
{
auton_select–;
}
}
last_sw1 = p1_sw_trig; //oneshot the trigger and top buttons
last_sw2 = p1_sw_top;

User_Mode_Byte = auton_select;
}

Second of all, how would I got about declaring auton_select as a global variable, and third I would need to get around the following errors:

C:\2007 arm code\FrcCode2005v2.4\user_routines.c:661:Error [1128] compatible scalar operands required for comparison
C:\2007 arm code\FrcCode2005v2.4\user_routines.c:663:Error [1147] scalar type expected for increment operator
C:\2007 arm code\FrcCode2005v2.4\user_routines.c:667:Error [1131] type mismatch in assignment
C:\2007 arm code\FrcCode2005v2.4\user_routines.c:670:Error [1128] compatible scalar operands required for comparison
C:\2007 arm code\FrcCode2005v2.4\user_routines.c:672:Error [1128] compatible scalar operands required for comparison
C:\2007 arm code\FrcCode2005v2.4\user_routines.c:674:Error [1131] type mismatch in assignment
C:\2007 arm code\FrcCode2005v2.4\user_routines.c:678:Error [1148] scalar type expected for decrement operator
C:\2007 arm code\FrcCode2005v2.4\user_routines.c:684:Error [1105] symbol ‘User_Mode_Byte’ has not been defined
C:\2007 arm code\FrcCode2005v2.4\user_routines.c:684:Error [1101] lvalue required

The code is from 2005 since we are just testing our prototype arm with the 2005 controller.

You made the name of the function the same as the name of the variable it’s trying to set. That’s what most of your compiler errors are about. You should probably change it back to auton_selector the way it was in the example. You also misspelled User_Mode_byte with a capital B.

To declare a global variable, do it at the top of user_routines.c where it says DEFINE USER VARIABLES AND INITIALIZE THEM HERE.

Oh, and I believe there was a typo in the example code. It looks like the 94 ought to be 99 instead.

Thanks so much for your help so far. We have managed to get the code up and running displaying the numbers on the OI, however anytime I try to get a value from auton_select in my Autonomous Mode I keep getting

C:\2007 arm code\FrcCode2005v2.4\user_routines_fast.c:154:Error [1105] symbol ‘auton_select’ has not been defined
C:\2007 arm code\FrcCode2005v2.4\user_routines_fast.c:154:Warning [2058] call of function without prototype

even though I have defined auton_select in user_routines.c as so

/*** DEFINE USER VARIABLES AND INITIALIZE THEM HERE ***/
#if _USE_CMU_CAMERA
#include “user_camera.h”

int auton_select;

Any solution for this problem? Thanks in advance!

Add this at the top of user_routines_fast.c to tell the compiler that auton_select is created in another file.


extern int auton_select; 

C:\2007 arm code\FrcCode2005v2.4\user_routines_fast.c:137:Warning [2058] call of function without prototype

Keep getting this warning, is it important or not really?

P.S. - Got it working HOWEVER I still have one more question. When the robot is disabled through the competition port it refuses to change the autonomous mode. Will our team have to change autonomous modes before we come to the player stations.

If the competition switch is set to manual (non-autonomous) and disabled, you should still be able to read the OI settings.

It’s important. It means you’re calling a method that doesn’t exist. Check your spelling on that line. Remember that method names are case sensitive.

Either that or you’re calling a function before it is declared. This code will generate the warning

void void main()
{
  func();
}

void func()
{
}

From the compiler’s point of view, it doesn’t know that func exists when it parses through main and thus throws the warning.

Here are two ways to get rid of the warning. I prefer the first method.

  1. Create a function prototype either at the top of the C file or in a header included by that C file. This will tell the compiler that a function named func that takes no inputs and returns nothing is defined somewhere in the code.
void func(void);  /* Here is the prototype */

void main()
{
  func();
}

void func()
{
}
  1. Write your function before you call it. In this case, the compiler will parse through the function and know about it by the time it gets to the call.

void func()
{
}

void main()
{
  func();
}

I highly suggest that you get in the habit of dealing with warnings as they pop up so that they don’t get lost in the shuffle and manifest themselves into a problem.

I thought the Master code didn’t allow any data transfer between the OI and the RC during autno mode.

It doesn’t. But when the robot is on the field before the match, it isn’t in autonomous mode, but it is disabled.

In this state, you can do just about anything except set any outputs on the RC (you can read inputs on the RC and the OI, and save these for when you start autonomous mode).

Close - You can set outputs, but they don’t actually make it to the pins.

This is an important distinction when debugging. The dashboard displays the PWM values, even when you’re disabled. This is useful if you don’t want your arm to swing wildly.

[/nit pick]

A useful nitpick. I use this very technique to demonstrate how the drive train feedback loop works every year, and how you can make sure the values are correct before enabling it.

I like that code that you found and i tried using it in our code but I get a syntax error on the line that says:

void auton_selector(void)

I declared the global variable in user_routines.c and put the extern int in the user_routines_fast.c (both are in the correct places). I changed the AUTON_UP and AUTON_DN to buttons on the joystick. I changed the 94 to 99. I also checked the lines before it so see if I left out a ; or } but I did’nt.

I also got another syntax error when I try using auton_select in user_routines_fast.c to select the autonomous.

Thanks!

I thought this too, for the competition radio completely disconnects the RC and OI, so maybe do this when you are on the field, but the match has not started

The RC and OI are always in communication with each other (as long as they are on and the radio link is good). The OI/RC master code determines what information is passed depending on the competition port state (disabled, autonomous, et cetera).

sorry for my lack of knowledge, i’m a rookie, but i don’t get why a team would want to set a button for autonomous mode at all. isn’t it controlled via the competition port and thus out of our hands? in the docs for the OI it says that if you jumper pins 5 and 8, it puts the bot into auto mode. i imagine that’s what they do at the competitions, not have a team member push a button on the controller…