Go to Post Making GP a rule would be the equivalent of making a law that says you have to help get kittens out of trees. - Molten [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 Rating: Thread Rating: 53 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 11-13-2014, 09:36 PM
772programming 772programming is offline
Registered User
FRC #0772
 
Join Date: Nov 2014
Location: Canada
Posts: 2
772programming is an unknown quantity at this point
PID function to reduce drift

Hello. So my team has been trying to write code to get the robot to drive in a straight line for a certain distance, which we managed to do using encoders and gyro input; however, once the encoders register that we have traveled the ideal distance and the motor shuts off, our robot drifts a considerable amount. We're trying to come up with a solution using PIDs, as shown below.
Any help with deciding on what the Kp, Ki and Kd values should be or with
any potential logic flaws we have would be appreciated. Also, if anyone has any better ideas than PIDs to reduce drifting, feel free to comment them. Ask for more code if you need to see anything else.Thanks!
Code:
//Initialization code for the gyrodrive command that is called to drive
the robot forward along a straight line until it reaches the desired dist.
protected void initialize() {
        log("Initialized GyroDriveCommand"); // prints to show that
        CommandBasedRobot.resetEncoders();   // resets encoders
        drivesub.enable();                   //
        gyroCalc();                          //
        
    }
//isFinished method for gyroDrive to try to stop without passing the desired
position
protected boolean isFinished() {
    
        return(drivesub.getPosition() - setpoint) < 1; // finishes when pos - setpoint < 1
            
        
    }

Declarations for the Kp, Ki and Kd values as well as the PIDInput and
PID output methods:
Code:
    private static final double Kp = 3;
    private static final double Ki = 0.2;
    private static final double Kd = 0.0;

protected double returnPIDInput() {
        return EncoderInfo.distanceL;//returns the current encoder distance
    }

    protected void usePIDOutput(double d) {
        System.out.println(d);
        start(d, 0);//gives the speed value to arcade drive
    }
public DriveTrainSubsystem(){
        super("DriveTrainSubsystem", Kp, Ki, Kd);
//OI code for calling the gyrodrivecommand
                                                               //dist, speed, setpoint
button1.whenPressed(new GyroDriveCommand(24, 0.70, 24));
    }
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:15 AM.

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