OK. I’m new to FIRST but not new to C. I’m trying to understand the default FRC code. I see that main is calling User_Autonomous_Code() when the autonomous_mode flag is set and after calling Process_Data_From_Master_uP(). like so:
while (1) /* This loop will repeat indefinitely. */
{
if (statusflag.NEW_SPI_DATA)
{
Process_Data_From_Master_uP();
if (autonomous_mode)
{
User_Autonomous_Code();
}
}
Process_Data_From_Local_IO();
} /* while (1) */
What I don’t understand is Process_Data_From_Master_uP() will in-turn call Default_Routine() which handles the operator interface. This doesn’t seem correct but maybe I’m mis-understanding something.
It seems to me that the if check in main should be something more like this:
while (1) /* This loop will repeat indefinitely. */
{
if (statusflag.NEW_SPI_DATA)
{
GetData(&rxdata);
if (autonomous_mode)
{
User_Autonomous_Code();
}
else
{
Process_Data_From_Master_uP(); //Modify to remove Get/PutData()
}
PutData(&txdata);
}
Process_Data_From_Local_IO();
} /* while (1) */
I’m operating remotely from my team and finally got a hold of the edu robot kit and have managed to program and download it. I got started on this because there is no autonomous mode in the edu default code and want to add it, somehow simulating the autonomous_mode.
I want to be sure I’m not misunderstanding anything before I procede.
I think there have been quite a few late, late nights at IFI getting this stuff ready, and you know there’s always a bug in software. You just may not know what it is yet.
We changed this around to where it made sense as you have done.
We decided to go through Process_Data_From_Master_uP() to check switches like the competition bit, then do the branch to auto or driver code.
Ours looks like:
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{ /* I'm slow! I only execute every 26.2ms because */
/* that's how fast the Master uP gives me data. */
Getdata(&rxdata); /* Get fresh data from the master microprocessor. */
Process_Data_From_Master_uP(); /* Process switch/joystick changes */
if (autonomous_mode) /* DO NOT CHANGE! */
{
User_Autonomous_Code(); /* Autonomous drive controls */
}
else
{
User_Driver(); /* User driver controls */
}
Generate_Pwms(pwm13,pwm14,pwm15,pwm16); /* N/A for EDU */
Putdata(&txdata); /* DO NOT CHANGE! */
}
Process_Data_From_Local_IO();
I’m not sure about this, so don’t quote me, but I believe you are actually able to read the operator inputs once at the start of the match. For instance, assuming that is true, you could have your autonomous function selected by switches that are part of whatever panel you have for the drivers instead of them having to be on the robot.
Of course, maybe I’m wrong and the thing is just incorrectly written…
This is based on last year, but I think it still applies. During the competition, when you turn the robot on it is in Disabled mode. The information from the OI is still being sent to the RC but the RC outputs are disabled. We had a thumbwheel switch (little plastic digit with a button to increment/decrement) on the OI to pick the program. While the robot was disabled we updated a global variable with the program number from the OI. Once autonomous started we used that global variable to pick which program to run.
I have pasted a code in the part that says “add your own autonomous code here”,.
Then I Closed the switch in the competition port, the controls disable, but autonomous didn’t run.
What should i do?
Thanks.
Close the switch for auto mode. Check the doc on IFI’s site. But be careful: I already fried our OI doing that (“This is what happens when programmers get bored …”) Fortunately, That was Saturday and we got back Thursday :):):):):).
Instead of risking frying stuff :), for testing you could use preprossesor directives to make the tests for autonomous mode always true when a certain macro is/isn’t defined. Something like this:
main.c (in main())
while (1) /* This loop will repeat indefinitely. */
{
...
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{
Process_Data_From_Master_uP();
**#ifndef AUTO_TESTING**
if (autonomous_mode)
{
User_Autonomous_Code();
}
**#else
User_Autonomous_Code();**
**#endif
** }
...
}
user_routines_fast.c (in User_Autonomous_Code())
**#ifndef AUTO_TESTING**
while (autonomous_mode) /* DO NOT CHANGE! */
**#else**
while(1)
**#endif**
{
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{
Getdata(&rxdata);
autonomousRun(autonomousModeSelection);
Putdata(&txdata);
}
}
auto_testing_setting.h
#define AUTO_TESTING
Just #include auto_testing_setting.h in main and user_routines fast and your autonomous stuff will run. This doesn’t stop after 15 sec, but it can be useful for testing your IR homing works or something like that.
Don’t forget to comment the #define out when you’re in competition.