Go to Post You know what they say, the mind is the second thing to go and I can't remember the first. - GaryVoshol [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Spotlight this post!  
Unread 01-02-2011, 14:49
basicxman basicxman is offline
Emily Horsman
FRC #2200 (MMRambotics)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Burlington, Ontario
Posts: 971
basicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant future
Send a message via AIM to basicxman Send a message via MSN to basicxman Send a message via Yahoo to basicxman
Re: gyro c++ Programing

Placing any sort of loop in your overridden functions (such as AutonomousPeriodic()) is discouraged.

Code off the top of my head:
Code:
// ...
float targetAngle;
int currentState;
float fowardStartTime;

const static int TURNING = 0;
const static int FORWARD = 1;
// ...
void AutonomousInit() {
  targetAngle = gyro.GetAngle() + 45.0;

  GetWatchdog().SetEnabled(true);
  GetWatchdog().SetExpiration(0.5);

  currentState = FORWARD;
}

void AutonomousPeriodic() {
  GetWatchdog().Feed();
  if (currentState == TURNING) {
    if (gyro.GetAngle() < targetAngle) {
      Turn(); // Implement this function
    } else {
       currentState = FORWARD;
       forwardStartTime = GetTime(); // Implement this function with your preferred method of time.
    }
  } else if (currentState == FORWARD) { 
    if (GetTime() < forwardStartTime + 3000)
      DriveFoward(); // Implement this function.
    else
      currentState = -1;
  }
}
Reply With Quote
 


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


All times are GMT -5. The time now is 03:05.

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