Go to Post There's lots of other "stuff" that make a team work well in the FIRST environment, beyond designing and building a robot. - KathieK [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 Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 15-01-2009, 09:31
levp92 levp92 is offline
Registered User
FRC #3089
 
Join Date: Jan 2009
Location: Haifa, Israel
Posts: 3
levp92 is an unknown quantity at this point
IsAutonomous() function

When i'm trying to run this code the program it's working:
Code:
#include <iostream.h>
#include "math.h"

#include "AxisCamera.h" 
#include "BaeUtilities.h"
#include "FrcError.h"
#include "TrackAPI.h" 
#include "WPILib.h"

class robot1 : public IterativeRobot
{
public:
	
	TrackingThreshold td;
	ParticleAnalysisReport par;
	ColorReport cReport;
	robot1(void)
	{
		td = GetTrackingData(RED, FLUORESCENT);
		printf("auto5\n");
		if (StartCameraTask(20, 0, k160x120, ROT_0) == -1) {
			printf("Failed to spawn camera task; exiting. Error code %s\n",
					GetVisionErrorText(GetLastVisionError()) );
		}
		printf("auto5\n");
		
	}
	
	
	void AutonomousContinuous(void){
			IsAutonomous();
			if ( FindColor(IMAQ_HSL, &td.hue, &td.saturation, &td.luminance, &par, &cReport) ){
				printf ("**  found: Servo: x: %f  y: %f \n", par.center_mass_x_normalized,	par.center_mass_y_normalized);	 
						
						}
		
		}
};

START_ROBOT_CLASS(robot1);
but if I run this code the program it's working:
Code:
#include <iostream.h>
#include "math.h"

#include "AxisCamera.h" 
#include "BaeUtilities.h"
#include "FrcError.h"
#include "TrackAPI.h" 
#include "WPILib.h"

class robot1 : public IterativeRobot
{
public:
	
	TrackingThreshold td;
	ParticleAnalysisReport par;
	ColorReport cReport;
	robot1(void)
	{
		td = GetTrackingData(RED, FLUORESCENT);
		printf("auto5\n");
		if (StartCameraTask(20, 0, k160x120, ROT_0) == -1) {
			printf("Failed to spawn camera task; exiting. Error code %s\n",
					GetVisionErrorText(GetLastVisionError()) );
		}
		printf("auto5\n");
		
	}
	
	
	void AutonomousContinuous(void){
			
			if ( FindColor(IMAQ_HSL, &td.hue, &td.saturation, &td.luminance, &par, &cReport) ){
				printf ("**  found: Servo: x: %f  y: %f \n", par.center_mass_x_normalized,	par.center_mass_y_normalized);	 
						
						}
		
		}
};

START_ROBOT_CLASS(robot1);
can somebody please explain me why?
Reply With Quote
  #2   Spotlight this post!  
Unread 15-01-2009, 09:41
popnbrown's Avatar
popnbrown popnbrown is offline
FIRST 5125 HOTH Lead Mentor
AKA: Sravan S
FRC #5125 (Hawks on the Horizon)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2007
Location: Illinois
Posts: 367
popnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond repute
Re: IsAutonomous() function

My first guess would be that "IsAutonomous()" asks the robot if it is still in the autonomous status. Can you tell me what the status of the driver station is? If you are even connected?

I'll get back to you, after double checking the WPILib documentation. But it might be a little bit, so here is my advice. Figure out what IsAutonomous() does.

My guess is that it looks at the driver station and if it driver station is enabled and in autonomous mode, then the IsAutonomous() will continue and if the driver station is not in autnomous then IsAutonomous() breaks the loop in which it is called.

Check the WPILib documentation, there should be something about IsAutonomous() in there.

Good Luck,
Sravan
__________________
I am an employee of FIRST. However, the postings on this site are of my own perspective as a FIRST mentor and volunteer and do not necessarily reflect the views of FIRST.

FIRST Team 5125 Hawks on the Horizon Lead Mentor
FRC Team 4096 Ctrl-Z Former Mentor
FTC Team 5203 #19@! Former Mentor
FRC Team 1403 Cougar Robotics Alumni
Reply With Quote
  #3   Spotlight this post!  
Unread 15-01-2009, 10:16
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,077
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: IsAutonomous() function

I think that this is because calling IsAutonomous() on every pass through the continuous code causes the print buffer to be flushed.

Try calling the function "fflush()" (no arguments) after your printf() statement without calling IsAutonomous().

As an aside, you probably won't want to print in the XXXContinuous() functions. It will go so fast you won't be able to read it. The XXXPeriodic() functions might be a better fit here.

Last edited by Jared Russell : 15-01-2009 at 10:30.
Reply With Quote
  #4   Spotlight this post!  
Unread 15-01-2009, 10:57
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: IsAutonomous() function

As to why your first code block isn't working, I can't say exactly. Looking at the code, IsAutonomous gets data from the driver station and returns the value of the autonomous member. Maybe there's an issue with getting data in the continuous loop?

Additionally, with an IterativeRobot,you don't need to explicitly call IsAutonomous since your AutonomousPeriodic and AutonomousTeleop will only be called when the mode is autonomous (check out IterativeRobot::StartCompetition)
Code:
else if (IsAutonomous())
		{
			// call AutonomousInit() if we are now just entering autonomous mode from
			// either a different mode or from power-on
			if(!m_autonomousInitialized)
			{
				// KBS NOTE:  old code reset all PWMs and relays to "safe values"
				// whenever entering autonomous mode, before calling
				// "Autonomous_Init()"
				AutonomousInit();
				m_autonomousInitialized = true;
				// reset the initialization flags for the other modes
				m_disabledInitialized = false;
				m_teleopInitialized = false;
				printf("Autonomous_Init() completed\n");
			}
			if (NextPeriodReady())
			{
				AutonomousPeriodic();
			}
			AutonomousContinuous();
		}
Also, just so you're aware in case you or someone else needs it, IsAutonomous returns a boolean telling if the state is autonomous or not. Simply calling it like you did in your first code block won't actually do anything since the return value is ignored. If you want to use it to make a decision you would need to put it in an IF statement (for example) as is done in the code block that I posted.
Reply With Quote
  #5   Spotlight this post!  
Unread 15-01-2009, 11:00
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Electrical/Programming Mentor
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,738
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: IsAutonomous() function

From the doxygen output:

Quote:
bool RobotBase::IsAutonomous ( void )

Determine if the robot is currently in Autnomous mode.

Returns:
True if the robot is currently operating Autonomously as determined by the field controls.
So what you're doing there is asking if you're in autonomous mode inside of your autonomous loop, and then doing nothing with that information!

When using an iterative robot, you don't need to call IsAutonomous() - the loop will only run while you are in autonomous, and will stop when you aren't. If you're running a simple robot (with no build in looping structure, you'll want to put something similar to:

Code:
void Autonomous(void) 
{
    while(IsAutonomous())
    {
        //do your autonomous stuff
        watchdog.feed();
    }
}
Reply With Quote
  #6   Spotlight this post!  
Unread 15-01-2009, 11:12
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: IsAutonomous() function

That brings up a good point. I don't see you doing anything with the watchdog. Unless you a) set the expiration to something manageable and b) feed the watchdog regularly, you have the potential of running into major problems with the cRIO resetting on you. Once you get into this scenario, it will be hard to fix depending on where the problem is because you will have a link to the driver station for just a few seconds before it resets again.

I would highly suggest adding this to your robot1 constructor
Code:
GetWatchdog().SetExpiration(100);
and this to the top every function that you're overriding from IterativeRobot (i.e. AutonomousContinuous)
Code:
GetWatchdog().Feed();
Reply With Quote
  #7   Spotlight this post!  
Unread 15-01-2009, 11:34
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,077
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: IsAutonomous() function

Quote:
Originally Posted by eagle33199 View Post
From the doxygen output:



So what you're doing there is asking if you're in autonomous mode inside of your autonomous loop, and then doing nothing with that information!

When using an iterative robot, you don't need to call IsAutonomous() - the loop will only run while you are in autonomous, and will stop when you aren't. If you're running a simple robot (with no build in looping structure, you'll want to put something similar to:

Code:
void Autonomous(void) 
{
    while(IsAutonomous())
    {
        //do your autonomous stuff
        watchdog.feed();
    }
}
I think what he was trying to say (sorry if I get this wrong) is that his code works if he calls IsAutonomous(), but doesn't if he doesn't.

As I said in my previous response, I think that this is an issue with the stdout buffer not getting flushed.
Reply With Quote
  #8   Spotlight this post!  
Unread 15-01-2009, 13:12
danielg30 danielg30 is offline
Registered User
FRC #3089
 
Join Date: Jan 2009
Location: israel
Posts: 1
danielg30 is an unknown quantity at this point
Re: IsAutonomous() function

Hi!

I'm a programming mentor from lev's team, we are trying to get an iterative robot camera example up and running, the DS is OK and configured properlly but still no success

we have discoverd that the "isAutonomos()" line is present everthing works fine, and nothing otherwise, any ideas why?

(i would appriciate if someone can upload here a simple IterativeRobot camera color tracking example)

thanks
daniel
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
Looping a function Tz0m Programming 14 20-02-2007 11:22
Scoring function in C mgreene Programming 7 12-01-2007 02:36
Arcade Function gabrielse Programming 1 08-02-2006 00:49
Limit_Mix() Function EricWilliams Programming 2 27-07-2005 23:19
FreeLibrary() Function Raven_Writer Programming 0 09-08-2003 15:39


All times are GMT -5. The time now is 13:15.

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