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.
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.
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)
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
");
}
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.
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:
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
GetWatchdog().SetExpiration(100);
and this to the top every function that you’re overriding from IterativeRobot (i.e. AutonomousContinuous)
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)