Go to Post There is nothing that compares to the smell of burning flesh, especially when it is your own. - Al Skierkiewicz [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
  #16   Spotlight this post!  
Unread 01-27-2016, 04:11 PM
techkid86's Avatar
techkid86 techkid86 is offline
Magic Programer
FRC #3044 (0xBE4)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: ballston spa
Posts: 58
techkid86 is an unknown quantity at this point
Re: Drive train PID control

1: you don't need the .get() in auto init. you might want to make it a .reset().
2: you also probably want to set a defined Max and Min output.
In auto periodic, you need to set a distance for the PID to get to, but before all that, you have to tune your PID.

PID tries to get to it's target with as little error as possible, but it uses coefficients to multiply by this error to get to this point. Now, for your use, it's likely you can get away with PD control, and leave I at 0. First thing you're going to need to do, is set it up such that your bot goes back and forth on it's own. ((be VERY careful with this. you might want the robot on blocks first, as I've had bad experiences with a run away robot while tuning PID)) you do this by using 2 set points, say, 100 and -100. it will set this set point every, say 10 seconds. now, the bot will get to that point, and either over shoot it, or slow down too early and never reach it. you want to only set 1 PID variable at a time.

So I typically start with P, and small values like 0.1 should be close. increase this until it starts to over shoot, or decrease it until it no longer overshoots, (then go back up one tick)

now you increase D until it no longer overshoots.
__________________
"you can build a perfect machine out of imperfect parts" -Urza
Reply With Quote
  #17   Spotlight this post!  
Unread 01-27-2016, 04:17 PM
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Drive train PID control

PROGRESS! Sorry for doing a double post.

So I just enable autonomous and the robot drove backwards very quickly right. I guess I need to change the direction the robot drives, so going forwards instead of backwards and then make the leftPID mask the rightPID so it drives straight.

Code:
public class Robot extends IterativeRobot {
	double xThrottle = 0;

	RobotDrive tankDrive;

	Talon leftDrive = new Talon(0);
	Talon rightDrive = new Talon(1);

	Joystick joystick = new Joystick(0);

	Encoder rightEncoder = new Encoder(0, 1, true,
			EncodingType.k4X);

	PIDController rightPID = new PIDController(0.1, 0, 0, rightEncoder, rightDrive);

	public void robotInit() {
		rightEncoder.setPIDSourceType(PIDSourceType.kDisplacement);

		rightEncoder.setReverseDirection(true);
		rightDrive.setInverted(true); // only one side needs inversion

		rightEncoder.reset();

		rightPID.setOutputRange(-0.75, 0.75); // max speed it can set to motors

		rightPID.enable();
	}

	public void autonomousInit() {
		final double distancePerPulse = Math.PI * Defines.WHEEL_DIAMETER / Defines.PULSE_PER_REVOLUTION
				/ Defines.ENCODER_GEAR_RATIO / Defines.GEAR_RATIO * Defines.FUDGE_FACTOR;

		rightEncoder.setDistancePerPulse(distancePerPulse);
		rightEncoder.reset();
	}

	public void autonomousPeriodic() {
		rightPID.setSetpoint(20);
	}

	public void teleopInit() {
		rightPID.disable();
		tankDrive = new RobotDrive(leftDrive, rightDrive);
	}

	public void teleopPeriodic() {
		double throttle = joystick.getRawAxis(Defines.THROTTLE);
		xThrottle = (-throttle + 2) / 4;

		tankDrive.arcadeDrive(joystick.getX() * xThrottle, -joystick.getY() * xThrottle);
	}
}

Last edited by curtis0gj : 01-27-2016 at 04:20 PM.
Reply With Quote
  #18   Spotlight this post!  
Unread 01-27-2016, 04:20 PM
techkid86's Avatar
techkid86 techkid86 is offline
Magic Programer
FRC #3044 (0xBE4)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: ballston spa
Posts: 58
techkid86 is an unknown quantity at this point
Re: Drive train PID control

Splendid! Sounds like you're on the right track. Shoot me a msg if you have any more issues, either PM here, or the skype that is connected to this account.
__________________
"you can build a perfect machine out of imperfect parts" -Urza
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 07:56 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