Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   User_Autonomous_Code() questions (http://www.chiefdelphi.com/forums/showthread.php?t=24720)

sscanf 03-02-2004 12:24

User_Autonomous_Code() questions
 
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:

Code:

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:

Code:

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.

Thanks.

Dan Rasmussen

Mark McLeod 03-02-2004 13:15

Re: User_Autonomous_Code() questions
 
It's not you.

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:
Code:

    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();


Ryan M. 03-02-2004 15:13

Re: User_Autonomous_Code() questions
 
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... :)

seanwitte 03-02-2004 15:21

Re: User_Autonomous_Code() questions
 
Quote:

Originally Posted by Texan
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.

Ryan M. 03-02-2004 15:25

Re: User_Autonomous_Code() questions
 
Quote:

Originally Posted by seanwitte
This is based on last year, but I think it still applies.

And they all told me it was impossible when I suggested that... :D

seanwitte 03-02-2004 15:33

Re: User_Autonomous_Code() questions
 
Quote:

Originally Posted by Texan
And they all told me it was impossible when I suggested that... :D

Don't hold me to it, this is pure speculation. You can build the competition mode dongle using the plans on IFI's web site and test it for yourself.

Code\\Pilot 05-02-2004 19:58

Re: User_Autonomous_Code() questions
 
can you help me?

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.

Astronouth7303 06-02-2004 15:01

Re: User_Autonomous_Code() questions
 
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 :):):):):).

Ryan M. 07-02-2004 07:16

Re: User_Autonomous_Code() questions
 
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())
Code:

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())
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
Code:

#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. :D


All times are GMT -5. The time now is 04:19.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi