Go to Post FIRST kids never cease to amaze me. - Wayne C. [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-02-2016, 18:27
ollien ollien is offline
Registered User
FRC #5202
 
Join Date: Feb 2015
Location: United States
Posts: 317
ollien has a spectacular aura aboutollien has a spectacular aura aboutollien has a spectacular aura about
PID Controller behaving erratically

This year, my team is trying to get our robot to drive straight using a PID controller and a NavX rather than having our driver correct for it manually. However, whenever I do this, the robot seems to shake left and right. I've tried raising/lowering the P value to get the robot to oscillate around the 0 degree mark, but once it gets to the point, it starts to shake rather violently. Changing the D value seems to make next to no difference, and if anything the robot seemed to shake more violently.

From some googling, it seems that the cause is a P value that is too high, but I can't seem to find a P value where the robot doesn't either shake, brown out, or not have enough power to move. I've posted the relevant pieces of my code below. Can someone help me out? Thanks so much.

Code:
public class Robot extends IterativeRobot implements PIDOutput {
    double turnCompensation = 0;
    final double kP = 0.01;
    final double kI = 0.00;
    final  double kD = 0.00;
    final double kF = 0.00;	
    CANTalon frontLeft = new CANTalon(2);
    CANTalon backLeft = new CANTalon(3);
    CANTalon frontRight = new CANTalon(4);
    CANTalon backRight = new CANTalon(5);
    Joystick joystick = new Joystick(0);
    Compressor compressor = new Compressor();
    int toggleDirection = -1;
    RobotDrive robotDrive = new RobotDrive(frontLeft, backLeft, frontRight, backRight);
    AHRS gyro = new AHRS(SPI.Port.kMXP);
    PIDController straightController = new PIDController(kP, kI, kD, kF, gyro, this);


	private double getLeftStick(){
		return joystick.getRawAxis(1);
	}
	
	private double getRightStick(){
		return joystick.getRawAxis(5);
	}
	
	private double getCorrectedRightStick(){
		double correctedValue = getRightStick() * 2;
		return correctedValue < 1 ? correctedValue : 1;
	}
	
	private double getCorrectedLeftStick(){
		double correctedValue = getLeftStick() * 2;
		return correctedValue < 1 ? correctedValue : 1;
	}
	//...
	public void robotInit(){
            compressor.start();
	    straightController.setInputRange(0,  360);
	    straightController.setOutputRange(-1.0, 1.0);
	    straightController.setAbsoluteTolerance(3);
            straightController.setContinuous(true);
	    straightController.enable();
            SmartDashboard.putData("DrivePID", straightController);
	    robotDrive.setSafetyEnabled(true);
	}
	
	@Override
	public void autonomousInit(){
//...
	}
	
	
	//Called periodically during auto
	//Use quick operations, must be done in less than 20ms.
	@Override
	public void autonomousPeriodic(){
//...		
	}
	
	@Override
	public void teleopInit(){
		gyro.reset();
		straightController.setSetpoint(0);
		frontLeft.enableBrakeMode(false);
		frontRight.enableBrakeMode(false);
		backLeft.enableBrakeMode(false);
		backRight.enableBrakeMode(false);

	}
	
	@Override
	public void teleopPeriodic(){
		SmartDashboard.putNumber("gyroValue", gyro.getAngle());
		if (joystick.getRawButton(8)){
			toggleDirection = 1;
		}
		else {
			toggleDirection = -1;
		}
		robotDrive.arcadeDrive(getCorrectedLeftStick() * toggleDirection, turnCompensation);
	}
	
	@Override 
	public void disabledInit(){
		straightController.disable();
	}

	@Override
	public void pidWrite(double output) {
		turnCompensation = output;
	}
}
  #2   Spotlight this post!  
Unread 02-02-2016, 18:32
Turing'sEgo Turing'sEgo is offline
Registered User
no team
 
Join Date: Jan 2016
Rookie Year: 2010
Location: Boulder
Posts: 47
Turing'sEgo can only hope to improve
Re: PID Controller behaving erratically

Check out this thread: http://www.chiefdelphi.com/forums/sh...d.php?t=142349
  #3   Spotlight this post!  
Unread 02-02-2016, 19:56
ollien ollien is offline
Registered User
FRC #5202
 
Join Date: Feb 2015
Location: United States
Posts: 317
ollien has a spectacular aura aboutollien has a spectacular aura aboutollien has a spectacular aura about
Re: PID Controller behaving erratically

Quote:
Originally Posted by Turing'sEgo View Post
So is the answer just to pick better values? Alright. I'll try this when I'm in the lab tomorrow.
  #4   Spotlight this post!  
Unread 06-02-2016, 22:43
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: PID Controller behaving erratically

Set the kP just low enough that you don't get oscillation. As you've seen, that doesn't always give enough power to get to the desired target, and you get a steady-state error. Now increase kI just high enough to overcome that error. Then tweak kD to account for rotational inertia so it doesn't overshoot badly and oscillate again.

It helps if you can modify the PID constants while the code is running. Perhaps you could use SmartDashboard for that.
Closed Thread


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 00:43.

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