|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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?
|
|
#2
|
||||
|
||||
|
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. |
|
#3
|
||||
|
||||
|
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?
|
|
#4
|
||||
|
||||
|
Re: Gyro Turning
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) {
|
|
#5
|
||||
|
||||
|
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)
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|