Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Help in Driving Straight (http://www.chiefdelphi.com/forums/showthread.php?t=125457)

Zman1311 29-01-2014 20:26

Help in Driving Straight
 
Greetings,

Our robot does not drive straight with the current code we have. We are using different methods to make it drive straight with encoders and gyros. However, these methods are causing it to veer to one side.

Code:

public class AutonomousDrive extends CommandBase {

    double left = .5;
    double right = .475;

    public AutonomousDrive() {
        requires(driveTrain);
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        driveTrain.resetEncoder();
        driveTrain.gyro.reset();
       
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        driveTrain.driveXboxTank(left, right);
       
        double rightEncoderCompensation = driveTrain.leftEncoder.getDistance() - driveTrain.rightEncoder.getDistance();
       
        double increaseFactor = rightEncoderCompensation/200.0;
       
        if (rightEncoderCompensation > 0)
        {
            if (right >= 0.5) {
                left -= increaseFactor;
            } else {
                right += increaseFactor;
            }
        } else if (rightEncoderCompensation < 0) {
            if (left >= 0.5) {
                right -= increaseFactor;
            } else {
                left += increaseFactor;
            }
        }

        /*if (driveTrain.gyro.getAngle() > 0.5) {
            if (right == 1.0) {
                left -= .0025;
            } else {
                right += .0025;
            }
        } else if (driveTrain.gyro.getAngle() < -0.5) {
            if (left == 1.0) {
                right -= .0025;
            } else {
                left += .0025;
            }
        }*/
    }

We were thinking maybe PID is the solution, but we have no idea on how to implement it.

otherguy 29-01-2014 20:49

Re: Help in Driving Straight
 
How severely does it veer to one side?
Does it always veer to the same side?

What are the units of the getDistance methods? There would be a big difference between adjusting your turn if one wheel was ahead of the other by 0.5 feet vs 0.5 inches.

How did you pick your increaseFactor to divide the distance error by 200?
If the increaseFactor is too small your system will not respond quickly enough to compensate for deviations off your desired heading.

For reference, last year our drive straight code would compensate if we were +/- 1 degree off our heading. Our slow wheel's commanded value would be increased by 10%. this yielded good results on our robot at speeds that were pretty close to our top travel speeds.

stefanp 11-02-2014 21:48

Re: Help in Driving Straight
 
Quote:

Originally Posted by Zman1311 (Post 1334482)
Greetings,

Our robot does not drive straight with the current code we have. We are using different methods to make it drive straight with encoders and gyros. However, these methods are causing it to veer to one side.

Code:

public class AutonomousDrive extends CommandBase {

    double left = .5;
    double right = .475;

    public AutonomousDrive() {
        requires(driveTrain);
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        driveTrain.resetEncoder();
        driveTrain.gyro.reset();
       
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        driveTrain.driveXboxTank(left, right);
       
        double rightEncoderCompensation = driveTrain.leftEncoder.getDistance() - driveTrain.rightEncoder.getDistance();
       
        double increaseFactor = rightEncoderCompensation/200.0;
       
        if (rightEncoderCompensation > 0)
        {
            if (right >= 0.5) {
                left -= increaseFactor;
            } else {
                right += increaseFactor;
            }
        } else if (rightEncoderCompensation < 0) {
            if (left >= 0.5) {
                right -= increaseFactor;
            } else {
                left += increaseFactor;
            }
        }

        /*if (driveTrain.gyro.getAngle() > 0.5) {
            if (right == 1.0) {
                left -= .0025;
            } else {
                right += .0025;
            }
        } else if (driveTrain.gyro.getAngle() < -0.5) {
            if (left == 1.0) {
                right -= .0025;
            } else {
                left += .0025;
            }
        }*/
    }

We were thinking maybe PID is the solution, but we have no idea on how to implement it.

Have you calibrated your talons? We figured this out one meeting when we were having problems going straight.

rwkling1 11-02-2014 21:52

Re: Help in Driving Straight
 
2 problems our team found:
As mentioned before, calibrate your talons (if that's what you're using).
Second, make sure the bearings flanges inside of your gearbox is in the right orientation, so they're not grinding together, slowing one side down.

ekapalka 11-02-2014 23:08

Re: Help in Driving Straight
 
Quote:

Originally Posted by rwkling1 (Post 1341557)
make sure the bearings flanges inside of your gearbox is in the right orientation, so they're not grinding together, slowing one side down.

[emphasis added by me] THIS. Our robot could hardy even move when we first drove it (a few days ago :P ). We implemented a crude feedback loop to correct for it using the gyro (which worked fairly well), but we later disassembled the gearboxes to find out the problem. We checked our individual wheel speed and two of them were severely off. It turns out that two of our four gearboxes had the bearings improperly installed, causing them not to function properly. From what I heard, it was really difficult to spot, and was only found out when attempting to disassemble and reassemble the entire thing (meaning it wasn't blatantly obvious, regardless of whether or not the gearbox was assembled).

jls667 13-02-2014 09:20

Re: Help in Driving Straight
 
How do you calibrate a Talon?

Ether 13-02-2014 09:31

Re: Help in Driving Straight
 
Quote:

Originally Posted by jls667 (Post 1342332)
How do you calibrate a Talon?

The Talon manual is located on the crosstheroadelectronics.com website, and it explains the calibration procedure in detail.

jls667 13-02-2014 12:00

Re: Help in Driving Straight
 
The calibration sounds easy. Thank you.


All times are GMT -5. The time now is 17:59.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi