Go to Post Actually there are several Wayne Cokeleys circulating around. We cloned him in 2001. This is his evil twin Mordechai responding.....-WC 3 - Wayne C. [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 28-02-2012, 16:38
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
Use Gyro to turn 90 Degrees

We are trying to modify the example gyro program so that the robot will turn 90 degrees then continue in its straight line.

How is the best way to acomplish this?
__________________
FRC Team 539
Student Member: 2010 Breakaway - 2014 Aerial Assist
Mentor: 2015 Recycle Rush - present
Reply With Quote
  #2   Spotlight this post!  
Unread 28-02-2012, 19:13
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: Use Gyro to turn 90 Degrees

There are many ways to do that.
  • You could just reset the gyro angle then command the robot to start to turn while monitoring the gyro angle until it reaches or passes beyond your target angle (e.g. 90). This is the simplest but you probably will overshoot (e.g. turn 95 degrees instead of 90).
  • You could use a PID controller to control the speed of turning so that when it is approaching your target angle, it slows down and hopefully stops at your target angle within the allowed steady state error. This requires you to use the PID controller and also tune the PID constants.
__________________
Reply With Quote
  #3   Spotlight this post!  
Unread 28-02-2012, 21:04
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
Re: Use Gyro to turn 90 Degrees

What are the values of the gyro. Is it 0 - 359 or what?
__________________
FRC Team 539
Student Member: 2010 Breakaway - 2014 Aerial Assist
Mentor: 2015 Recycle Rush - present
Reply With Quote
  #4   Spotlight this post!  
Unread 28-02-2012, 21:08
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: Use Gyro to turn 90 Degrees

The gyro actually gives you angular velocity (turn rate), but the FPGA is doing integration for you. If you are calling the GetAngle() method, I believe you will get the accumulated angle. So if you turn several rounds, for example, you could get angle values > 360 or < -360. Remember, it is not a compass. It doesn't give you absolute heading. If only gives you current angle relative to your starting angle.
__________________
Reply With Quote
  #5   Spotlight this post!  
Unread 28-02-2012, 21:15
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
Re: Use Gyro to turn 90 Degrees

So another words, if you were heading a direction recording 0. Then you used "GetAngle() + 90" when the drive is correcting itself it will think the robot turned 90 degrees to the right and will try to correct itself by turning 90 degrees to the left?
(Assuming a positive value turns the robot right and a negative value turns the robot left).

I am trying to accomplish this program without using the Reset() because that causes unpredictable angles at which it reset itself.
__________________
FRC Team 539
Student Member: 2010 Breakaway - 2014 Aerial Assist
Mentor: 2015 Recycle Rush - present
Reply With Quote
  #6   Spotlight this post!  
Unread 28-02-2012, 21:19
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: Use Gyro to turn 90 Degrees

Yes, you can do the following, for eample:
Code:
float targetHeading = gyro->GetAngle() + 90.0;
while (gyro->GetAngle() < targetHeading)
{
    drive->ArcadeDrive(0.0, 0.5);
}
__________________
Reply With Quote
  #7   Spotlight this post!  
Unread 28-02-2012, 21:27
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
Re: Use Gyro to turn 90 Degrees

Alright I will be testing that tomorrow. I was curious about the value range because we had the bot set up with the following code:
Code:
float angle = gyro.GetAngle() + 90;
myRobot.Drive(-0.2, -angle / 30);
The robot went straight before the "+ 90"; the -0.2 is because a negative value is actually forward on the bot.

The result when running this was that the robot would turn right at a medium rate and continue turning after passing 90 degrees.

The other result that seemed odd was that changing "/ 30" to "/ 1" caused a slower turn rate while changing it to "/ 60" caused a faster turn rate.
__________________
FRC Team 539
Student Member: 2010 Breakaway - 2014 Aerial Assist
Mentor: 2015 Recycle Rush - present
Reply With Quote
  #8   Spotlight this post!  
Unread 28-02-2012, 21:42
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: Use Gyro to turn 90 Degrees

If you just want a simple turn, don't use myRobot.Drive, just use ArcadeDrive, like this:
Code:
#define TURN_TOLERANCE 0.5
void Turn(float angle)
{
    float targetHeading = gyro.GetAngle() + angle;
    while (fabs(targetHeading - gyro.GetAngle()) > TURN_TOLERANCE)
    {
        myRobot.ArcadeDrive(0.0, (angle < 0.0)? -0.5: 0.5);
    }
}
However, if you want to adjust the turn power according to how far you are from your target, then you need to use PID.
BTW, you should really fix your signs by calling myRobot->SetInvertedMotor(), you will benefit from it in the long run.
__________________

Last edited by mikets : 28-02-2012 at 21:46.
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 17:42.

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