View Single Post
  #4   Spotlight this post!  
Unread 02-06-2009, 04:07 AM
MattD's Avatar
MattD MattD is offline
Registered User
AKA: Matthew Douglas
FRC #0228 (GUS Robotics)
Team Role: Alumni
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Indianapolis, IN
Posts: 185
MattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to behold
Send a message via AIM to MattD
Re: Continuous vs. Autonomous in Iterative Robot

The function that sets the rate for the Periodic loop has been depreciated in Update 3. Periodic functions are now synchronized to run when the robot receives new data from the Driver Station, similar to the old "slow loop" on the IFI platform.

The Continuous functions will run as fast as they can, and they're not interrupted by the Periodic functions.

This is the sequence of events for IterativeRobot, in pseudocode:

Code:
call RobotInit()

while (1)
{
    if current mode has not been initialized:
          call Init() for current mode (eg TeleopInit)

    if there has been new data from DS:
          call Periodic() for current mode

    call Continuous() for current mode
}
Any code that depends on new information from the Driver Station really should be in a Periodic function.

Code that sets up joysticks, speed controllers, sensors, etc should be in your robot class constructor or in RobotInit(). The variables for these objects should be declared in the robot class, outside of any functions. Anything else that needs to continuously run should be in a continuous function.

Regarding the example with the Ultrasonic class, this part would be for initialization:

Code:
Ultrasonic ultra(ULTRASONIC_PING, ULTRASONIC_ECHO);
ultra.SetAutomaticMode(true);
You'd need to declare the Ultrasonic object somewhere in your class as a member variable, and initialize it in RobotInit() or the constructor.

Code:
class MyRobot : public IterativeRobot
{
   Ultrasonic *m_ultra;
   // other declarations...

   void RobotInit()
   {
          m_ultra = new Ultrasonic(pingchannel, echochannel);
          m_ultra.SetAutomaticMode(true);
   }

   void AutonomousPeriodic()
   {
       // Do something with m_ultra->GetRangeInches();
   }
}
The Ultrasonic::GetRangeInches() function is non-blocking and will return 0 if no measurements have completed. Also, when you use Automatic Mode with the Ultrasonic class the pinging will be done automatically in the background. You won't have to do anything except ask it for range information wherever you need it.
__________________
GUS Robotics Team 228

2010 WPI Engineering Inspiration Award
2010 WPI Regional Champions (Thanks 230 & 20!)
2010 CT VEX Champions
2010 CT VEX Innovate Award
2009 QCC VEX Champions
2009 CT Motorola Quality Award
2007 CT J&J Sportsmanship Award
2006 CT Best Website Award

Last edited by MattD : 02-06-2009 at 04:10 AM.
Reply With Quote