Go to Post every year presents new challenges. What worked well last year might well be a clunker-bot this year. keep an open mind! - KenWittlief [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rating: Thread Rating: 14 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 03-17-2015, 08:28 PM
Nathan Powell's Avatar
Nathan Powell Nathan Powell is offline
The Prime Function
FRC #2582 (PantherBots)
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Lufkin, TX
Posts: 37
Nathan Powell is an unknown quantity at this point
PID Control Loop Assistance

Greetings, all.
My team has requested that we programmers code an automated lift this year, because of the fine control required to consistently pick up totes during a match. We decided to use a PID control loop, since it would help us hone in on the positions we want on the lift, and consistently reach those positions.
However, once the lift reaches that spot, I have it cut off, to prevent it from oscillating back and forth around the spot. Unfortunately, this has a side effect of having the lift fall down under the weight of the totes. Is there a way to fix this, code-wise?
Finally, I personally have been wrestling with automation and PID control for all 4 years of my time on the team, and I still have trouble implementing it. I understand (most) of the logic behind it, but I am only somewhat familiar with the calculus behind it, and any help in actually writing a PID loop into a program would be incredibly useful.
For reference:
We code in C++.
The lift uses one Talon SR speed controller.
The PID loop receives input from a 10-turn potentiometer, and outputs to the motor.
Code:
Talon *lifter = new Talon(6);		//lift motor
AnalogPotentiometer *pot = new AnalogPotentiometer(0, 360, 0); //potentiometer
PIDController *autolift = new PIDController(0,1, 0.001, 0.0, pot, lifter); //PID controller
void LiftParameters()	//sets parameters for the lift PID control loop
	{
		autolift->SetAbsoluteTolerance(0.5);
		autolift->SetOutputRange(0.4, -0.4);
		autolift->SetSetpoint(325.0);
	}
void PLift()	//PID control loop for automating the lift
	{
		if(rstick->GetRawButton(1))
		{
			PID = true;
			autolift->SetOutputRange(0.4, -0.4);
			autolift->Enable();
			autolift->SetSetpoint(325.0);	//ground level
			//lift = true;
		}
		else if(rstick->GetRawButton(2))
		{
			PID = true;
			autolift->SetOutputRange(0.4, -0.4);
			autolift->Enable();
			autolift->SetSetpoint(234.0);	//1st position
		}
		else if(rstick->GetRawButton(3))
		{
			PID = true;
			autolift->SetOutputRange(0.4, -0.4);
			autolift->Enable();
			autolift->SetSetpoint(300.0);	//second position
		}
		else if(rstick->GetRawButton(4))
		{
			PID = true;
			autolift->SetOutputRange(0.4, -0.4);
			autolift->Enable();
			autolift->SetSetpoint(340.0);	//third position
		}
		if(autolift->OnTarget())
		{
			autolift->Disable();
			autolift->SetOutputRange(0.25, -0.25);
			PID = false;
		}
		if(rstick->GetRawButton(9))
		{
			autolift->Disable();
			PID = false;
		}
	}
__________________
"What's this I keep hearing about always blame programming?"
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 10:45 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