Go to Post I think FIRST is a big trap. They lure you in with these cool competitions and shiny robots and along the way they trick you into learning something :) - =Martin=Taylor= [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 31-01-2011, 18:41
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 495
tomy has a spectacular aura abouttomy has a spectacular aura about
gyro c++ Programing

can anyone direct me on how to properly program the robot to drive in autonomous mode with the gyro?
Reply With Quote
  #2   Spotlight this post!  
Unread 31-01-2011, 18:52
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: 671
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

That is a very broad question. Can you narrow it down to more specifics what you want to do in autonomous? Gyro is normally used to determine your heading. If you want to tell the robot to turn a certain angle during autonomous, you can certainly use it to achieve what you want. If that's what you want to do, you can either program the robot to turn at a constant speed while monitoring the reading of the gyro until it reaches the target then you stop, or you can use PID control to adjust the speed while you turn (i.e. slow down when you are close to your target).
__________________
Reply With Quote
  #3   Spotlight this post!  
Unread 31-01-2011, 18:56
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 495
tomy has a spectacular aura abouttomy has a spectacular aura about
Re: gyro c++ Programing

in the gyro example they use this

Code:
gyro.Reset();
		while (IsAutonomous())
		{
			float angle = gyro.GetAngle();			// current heading (0 = target)
			myRobot.Drive(-1.0, -angle / 30.0);		// proportionally drive in a straight line
			Wait(0.004);
		}
		myRobot.Drive(0.0, 0.0); 	// stop robot
how do we make the robot turn lets say 45 degrees then drive for 3 seconds
Reply With Quote
  #4   Spotlight this post!  
Unread 31-01-2011, 19:02
ElliotCourant's Avatar
ElliotCourant ElliotCourant is offline
Elliot Courant
AKA: Elliot Courant
FRC #3038 (ICE Robotics)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Minnesota
Posts: 19
ElliotCourant is an unknown quantity at this point
Re: gyro c++ Programing

Would this work


Code:
//what tommy wants
			angle = 45;
			myRobot.Drive(-1.0, -angle / 30.0);
			Wait(3.0);
__________________
"Error, Cannot Find Back-End!" -WindRiver C++ Error
"If you aren't getting any errors while you are programming, then you are doing something wrong." -Elliot Courant
Reply With Quote
  #5   Spotlight this post!  
Unread 31-01-2011, 19:07
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: 671
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

A simple way, not necessarily the best way, is to do the following:
Code:
float targetAngle = gyro.GetAngle() + 45.0;
 
while (gyro.GetAngle() < targetAngle)
{
    //
    // Turn the robot to the right at half speed.
    //
    myRobot.ArcadeDrive(0.0, 0.5);
}
//
// Go straight at half speed.
//
myRobot.ArcadeDrive(0.5, 0.0);
Wait(3.0);
//
// Stop.
//
myRobot.ArcadeDrive(0.0, 0.0);
__________________
Reply With Quote
  #6   Spotlight this post!  
Unread 31-01-2011, 19:19
ElliotCourant's Avatar
ElliotCourant ElliotCourant is offline
Elliot Courant
AKA: Elliot Courant
FRC #3038 (ICE Robotics)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Minnesota
Posts: 19
ElliotCourant is an unknown quantity at this point
Re: gyro c++ Programing

That looks like it will work better than mine
__________________
"Error, Cannot Find Back-End!" -WindRiver C++ Error
"If you aren't getting any errors while you are programming, then you are doing something wrong." -Elliot Courant
Reply With Quote
  #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: 671
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
  #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
  #9   Spotlight this post!  
Unread 01-02-2011, 14:58
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: 671
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

Basicxman,
That's why I said it's not the best way. What you are doing is essentially a state machine. That's the preferred way to do it. In general, one should be able to code the entire competition without using a single wait loop. Whenever you need to wait, you return. And the next time you get called, you check the condition again. If it's still not ready, you return again. When it is finally ready, you move on to the next state. Using a state machine not only allows you to eliminate wait loops, it also allow you to do several things concurrently. For example, moving your claw while tracking the line simultaneously.
__________________
Reply With Quote
  #10   Spotlight this post!  
Unread 01-02-2011, 15:00
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

Quote:
Originally Posted by mikets View Post
Basicxman,
That's why I said it's not the best way. What you are doing is essentially a state machine.
Correct, some people have also referred to this technique as 'hooping.'
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


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