Go to Post West Coast Drive is best coast drive. - [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 29-01-2014, 20:26
Zman1311 Zman1311 is offline
Registered User
None #2876
 
Join Date: Jan 2014
Location: Burly
Posts: 3
Zman1311 is an unknown quantity at this point
Unhappy 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.
Reply With Quote
  #2   Spotlight this post!  
Unread 29-01-2014, 20:49
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: 429
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: 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.
__________________
http://team2168.org

Last edited by otherguy : 29-01-2014 at 21:23. Reason: changed response, didn't see you were using two encoders in the code block, makes more sense now
Reply With Quote
  #3   Spotlight this post!  
Unread 11-02-2014, 21:48
stefanp stefanp is offline
Registered User
AKA: Stefan Pleava
FRC #4946 (The Alpha Dogs)
Team Role: Alumni
 
Join Date: Oct 2013
Rookie Year: 2014
Location: Canada
Posts: 17
stefanp will become famous soon enough
Re: Help in Driving Straight

Quote:
Originally Posted by Zman1311 View Post
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 11-02-2014, 21:52
rwkling1's Avatar
rwkling1 rwkling1 is offline
Registered User
FRC #2977 (Sir Lancer Bots)
Team Role: Leadership
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Minnesota
Posts: 143
rwkling1 has a spectacular aura aboutrwkling1 has a spectacular aura about
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.
Reply With Quote
  #5   Spotlight this post!  
Unread 11-02-2014, 23:08
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
Re: Help in Driving Straight

Quote:
Originally Posted by rwkling1 View Post
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).
Reply With Quote
  #6   Spotlight this post!  
Unread 13-02-2014, 09:20
jls667 jls667 is offline
Registered User
None #2579
 
Join Date: Feb 2014
Location: ny
Posts: 25
jls667 is an unknown quantity at this point
Re: Help in Driving Straight

How do you calibrate a Talon?
Reply With Quote
  #7   Spotlight this post!  
Unread 13-02-2014, 09:31
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,995
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: Help in Driving Straight

Quote:
Originally Posted by jls667 View Post
How do you calibrate a Talon?
The Talon manual is located on the crosstheroadelectronics.com website, and it explains the calibration procedure in detail.
Reply With Quote
  #8   Spotlight this post!  
Unread 13-02-2014, 12:00
jls667 jls667 is offline
Registered User
None #2579
 
Join Date: Feb 2014
Location: ny
Posts: 25
jls667 is an unknown quantity at this point
Re: Help in Driving Straight

The calibration sounds easy. Thank you.
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 05:33.

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