Go to Post The less we talk about the game hints the faster they will come. - BrendanB [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 08:40.

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