View Single Post
  #7   Spotlight this post!  
Unread 31-01-2011, 19:57
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: gyro c++ Programing

Well, it is not the best way especially on the Wait(3.0). The cRIO has a watchdog timer. You need to feed it periodically or your motors will be cut out. Waiting for 3 seconds will definitely starve your dog. So instead of a plain Wait(3.0) statement, you may want to read the timer in a loop. I beleive the WPI library this year will feed your watchdog for you when you call any of the Drive methods. If not add a feed watchdog statement in each of the loops. So something like this:
Code:
float targetAngle = gyro.GetAngle() + 45.0;
 
while (gyro.GetAngle() < targetAngle)
{
    GetWatchdog().Feed();
    //
    // Turn the robot to the right at half speed.
    //
    myRobot.ArcadeDrive(0.0, 0.5);
    Wait(0.1);
}
//
// Go straight at half speed for 3 seconds.
//
UINT32 targetTime = GetFPGATime()/1000 + 3000;
while (GetFPGATime()/1000 < targetTime)
{
    GetWatchdog().Feed();
    myRobot.ArcadeDrive(0.5, 0.0);
    Wait(0.1);
}
//
// Stop.
//
myRobot.ArcadeDrive(0.0, 0.0);
And of course this is not the best way either, but it should work for your purpose. BTW, the rule of thumb is: never have a Wait statement in your code that's close to or greater than your watchdog timer interval.
__________________
Reply With Quote