Go to Post And whether or not we are awarded in the course of the season, at its end our team will look back, and we’ll look at one another, and we will wonder how we were able to accomplish what we did. - John Wanninger [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 08-10-2013, 21:58
tuXguy15's Avatar
tuXguy15 tuXguy15 is offline
Team Mentor
AKA: Devin Kolarac
FRC #2559 (Normality Zero)
 
Join Date: Apr 2012
Rookie Year: 2012
Location: Harrisburg, PA
Posts: 127
tuXguy15 is an unknown quantity at this point
Gyro Turning

So i know that gyros can help your robot drive straight in autonomous, but can they also turn your robot? Say im going forward for 3 seconds and then i want to turn 90 degrees to the left. Can the gyro help me do this and then continue driving straight?
__________________
Reply With Quote
  #2   Spotlight this post!  
Unread 08-10-2013, 22:16
Pault's Avatar
Pault Pault is offline
Registered User
FRC #0246 (Overclocked)
Team Role: College Student
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Boston
Posts: 618
Pault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond repute
Re: Gyro Turning

Yes, it is definitely possible. You would probably want to use PID. The basic logic goes something like this.

The input of the PID is the gyro angle.
The setpoint of the PID is 90 degrees.
The output of the PID is 1 side of your drivetrain, and then the other side of your drivetrain should run at the exact opposite of the normal output.

Hope this helps.
Reply With Quote
  #3   Spotlight this post!  
Unread 09-10-2013, 08:05
tuXguy15's Avatar
tuXguy15 tuXguy15 is offline
Team Mentor
AKA: Devin Kolarac
FRC #2559 (Normality Zero)
 
Join Date: Apr 2012
Rookie Year: 2012
Location: Harrisburg, PA
Posts: 127
tuXguy15 is an unknown quantity at this point
Re: Gyro Turning

So Kp would be the value of the angle? Say i were to want it to turn 90 degrees, P if PID would be 90?
__________________
Reply With Quote
  #4   Spotlight this post!  
Unread 09-10-2013, 09:30
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,077
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Gyro Turning

Quote:
Originally Posted by tuXguy15 View Post
So Kp would be the value of the angle?
From the source code that came with your Java installation:

Code:
    /**
     * Allocate a PID object with the given constants for P, I, D, and F
     * @param Kp the proportional coefficient
     * @param Ki the integral coefficient
     * @param Kd the derivative coefficient
     * @param Kf the feed forward term
     * @param source The PIDSource object that is used to get values
     * @param output The PIDOutput object that is set to the output percentage
     * @param period the loop time for doing calculations. This particularly effects calculations of the
     * integral and differential terms. The default is 50ms.
     */
    public PIDController(double Kp, double Ki, double Kd, double Kf,
            PIDSource source, PIDOutput output,
            double period) {
Reply With Quote
  #5   Spotlight this post!  
Unread 09-10-2013, 09:31
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 430
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Gyro Turning

No, Kp is the proportional gain term. It's a value which is multiplied by the measured error. Where "error" is your desired position (input into the PID controller) minus actual measured position.

I would suggest reading up on PID controllers, and learn at least at a high level how they operate before attempting to use one on your robot.
Some helpful links:
PID without a PHD (pdf) a good overview of how different controllers work
PID Tuning This one will help you choose your gains.

That said, you can turn x number of degrees using the gyro without a PID controller. A simple implementation is provided below.
If you have never used a PID controller before, it may be easier to implement a simple algorithm like what is below, then itterate on the design to improve the performance problems you identify.

Sudocode (this needs to be run in a loop in a simple robot project, or have supporting state variables in an itterative or command based robot project (to flag when you're finished)
Code:
//Positive angle is roatation clockwise
//currentAngle is the angle measured off the gyro
//destinationAngle is the desired angle to rotate to
//forwardSpeed and reverseSpeed are variables between 1.0 and -1.0, the larger they are the faster you will turn.
//    making one the negative of the other will 
if ( abs(currentAngle) >= abs(destinationAngle)) {
    //we're there, stop turning
    drivetrain.tankdrive(0,0)
} else if ( destinationAngle  > currentAngle) {
    //rotate clockwise
    drivetrain.tankDrive(reverseSpeed, forwardSpeed);
} else {
    //rotate counter-clockwise
    drivetrain.tankDrive(forwardSpeed, reverseSpeed)
}
Note, this code could (Read will) overshoot its destination. Depending on your intended applicaiton this may or may not be a desireable feature.
__________________
http://team2168.org
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 22:35.

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