Go to Post Never leave future engineers alone, especially with something like gravity. - Alex Pelan [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 05-02-2009, 23:11
Shira Shira is offline
Registered User
FRC #1836
Team Role: College Student
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Los Angeles
Posts: 30
Shira is an unknown quantity at this point
Continuous vs. Autonomous in Iterative Robot

So I've decided to use Iterative Robot over Simple Robot. I'm editing the BuiltinDefaultCode project. I notice they use the autonomous and teleoperated periodic functions but not the continuous. I was wondering what the relationship is between the periodic and continuous. If you put code in both, how do they run relative to one another? Also, what specifically is the difference? And I guess, all this leads to the question, what should I use (or based on what should I decide?)

Also, I've found the code I need for getting data from the sensors, but I'm not very familiar with C++ and object oriented programming so I'm not really sure of where to put what.

I've got this for the camera. Which parts go wherever I decide to refresh my sensors? For that matter, where is it a good idea for me to refresh my sensors? Also, is there other necessary camera configuration stuff I need to put in somewhere in my code?
double timestamp; // timestamp of image returned
Image* cameraImage = frcCreateImage(IMAQ_IMAGE_RGB);
if (!cameraImage) { printf("error: %s", GetErrorText(GetLastError()) };

if ( !GetImage(cameraImage, &timestamp) ) {
printf("error: %s", GetErrorText(GetLastError()) };


And then there's this, which I assume will go right after I get my image:
imaqImageToArray(const Image* image, Rect rect, int* columns, int* rows);

And finally there's this: basically, I'm not sure what parts of this (if any) set up the sensors, and which parts just get the data.
Ultrasonic ultra(ULTRASONIC_PING, ULTRASONIC_ECHO);
ultra.SetAutomaticMode(true);
double range = ultra.GetRangeInches();


Any help would be appreciated...there isn't much programming experience on my team. Thanks!
Reply With Quote
  #2   Spotlight this post!  
Unread 06-02-2009, 00:16
nathanww nathanww is offline
Hacker
FRC #1678 (Citrus Circuits)
Team Role: Programmer
 
Join Date: Dec 2008
Rookie Year: 2007
Location: Davis, CA
Posts: 224
nathanww is just really nicenathanww is just really nicenathanww is just really nicenathanww is just really nice
Re: Continuous vs. Autonomous in Iterative Robot

A "periodic" function is one that is run only at a certain interal--if you look in the c++ reference, you'll see there's actually a function to set how often it runs.

A "continuous" function is called as fast as the robot is able to--there's no way to explicity specify when it should be called.

As for how they interact---the system considers them two functions of the same class. This means they can both use global variables in your file, call each other, etc.
__________________
Get yer robot source code here!
Reply With Quote
  #3   Spotlight this post!  
Unread 06-02-2009, 02:39
Shira Shira is offline
Registered User
FRC #1836
Team Role: College Student
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Los Angeles
Posts: 30
Shira is an unknown quantity at this point
Re: Continuous vs. Autonomous in Iterative Robot

Quote:
Originally Posted by nathanww View Post
A "periodic" function is one that is run only at a certain interal--if you look in the c++ reference, you'll see there's actually a function to set how often it runs.

A "continuous" function is called as fast as the robot is able to--there's no way to explicity specify when it should be called.

As for how they interact---the system considers them two functions of the same class. This means they can both use global variables in your file, call each other, etc.
So--if I have code in autonomous and periodic, what happens? Does continuous loop as fast as it can, but is interrupted by periodic every time the time interval specified has past?

And so, should I put my sensor refresh code in the periodic loop, depending on how fast it refreshes, and the rest of my code in continuous? Or could I set the periodic time interval to 0, and then just stick the sensor refreshes in the if ((m_telePeriodicLoops % n) == 0)statements that run enclosed code only on every nth iteration?

Finally, in all cases does the code wait for data to return (ie, for the ultrasonic ping to come back) before moving on? Because in that case, whether I ran it every nth loop or every loop, technically it would still hold up my robot's reaction rate? (Say then that my robot just sets drive speed and turn depending on data, and the calculations are simple, it would act the same in the following situations: 1) if it were stuck waiting on sensor data to return and the motors were still running on info from the old command, and 2) if it were looping through the code and making new drive commands based on old data. Right? I may have very probably confused myself by now.)

Last edited by Shira : 06-02-2009 at 02:41.
Reply With Quote
  #4   Spotlight this post!  
Unread 06-02-2009, 04:07
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 : 06-02-2009 at 04:10.
Reply With Quote
  #5   Spotlight this post!  
Unread 06-02-2009, 04:20
Shira Shira is offline
Registered User
FRC #1836
Team Role: College Student
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Los Angeles
Posts: 30
Shira is an unknown quantity at this point
Re: Continuous vs. Autonomous in Iterative Robot

Thanks! I understand the setup a lot better now.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Robot: Simple or Iterative? Abrakadabra Programming 3 14-01-2009 22:01
Continuous turret jjdebner Motors 10 05-02-2007 11:19
Iterative Scoring Program TimA Rules/Strategy 1 18-01-2007 21:43
The Continuous Letter Sentence Game xtremedarkness Games/Trivia 38 11-02-2005 10:12
Cable rigging: Cascade vs. Continuous Madison Technical Discussion 2 19-01-2004 23:23


All times are GMT -5. The time now is 10:06.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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