|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools |
Rating:
|
Display Modes |
|
#1
|
||||
|
||||
|
PID control help
So I'm a new programmer on my team and I'm not very familiar with PID loops/controls. We have two motors on our robot and were trying to run them both at the same speed. of course there will be some minor differences in speed but we're trying use a PID to keep them equal in case one gets off. We also have encoders on each motor. Any help appreciated thanks!
|
|
#2
|
|||
|
|||
|
Re: PID control help
Quote:
|
|
#3
|
||||
|
||||
|
Re: PID control help
Quote:
Last edited by KosmicKhaos : 09-02-2015 at 23:57. |
|
#4
|
|||
|
|||
|
Re: PID control help
Quote:
Alternatively you can use two PIDCommands which will also then have methods onthem for usePIDOutput and returnPIDInput. You can set those to access return values from the subsystems. (i.e. usePIDOutput in one command sets the motor on one subsystem and returnPIDInput in that same command returns the encoder rate on that same subsystem. However you do it, you end up with a PIDController object (either managed by the PIDSubsystem super class or by the PIDCommand super Class). Once the PIDControllers are tuned (if the mechanisms are largely similar, they will likely have the same PID vaues), you can call setSetPoint() on the PIDController/PIDSubsystem and when they are enabled, they will drive at a particular rate. Each will function independent of the other, but both will rely on the respective encoder to maintain the rate. Note, there are two approaches for usePIDOutput for a rate PID. One is to treat it like a positional PID in which case as you approach your set rate, you try to apply 0V, which of course will actually be trying to slow down your motor, rather than drive it at a constant value. Also in the application of something like a shooter where the motor may be spinning very fast as opposed to a very geared-down application, if the rate gets a bit large, you may try to apply negative voltage to a motor with a very strong forward momentum. The other approach iirc is to change usePIDOutput to maintain a last value sent and add/decrease that last value sent by the output. If you search CD you can find some good articles and all the math behind them to support something along the lines of Code:
class PIDCommand {
double m_output;
...
public void usePIDOutput(double output) {
m_output += output;
motor.set(m_output)
}
I'll be honest, we use encoder/talon pairs for our drive train this year and did so all last season. Last year we originally used positional and the discovered the rate formulation mid-season. We tried it, but either we implemented it poorly or didn't take enough time to properly tune it, but it did not seem to behave as nicely for us as the original positional formulation. I think the rate formulation is more correct, but I can only say that the positional formulation got our team through an entire season with no observable problems, though after driving 10 minutes or more our cims did get quite hot. That was more due though to poor cooling-- when the cims were exposed to air on the practice chassis it was not a problem, but when they were somewhat enclosed by electrical above and a pan below, they would get hot. I suspect a rate formulation may have helped with this. But regardless of how you do this-- PIDController, PIDSubsystem, rate formulation or positional formulation, the concept is the same. Drive each motor based on feedback from its respective encoder to adjust the motor speed. You will find that each independently will then maintain the same rate. We did find that some small tweaks to DistancePerPulse might be necessary to tune the two encoders to one another, but even without such adjustments the rates will be relatively equal-- much better than otherwise. |
|
#5
|
||||
|
||||
|
Re: PID control help
Quote:
|
|
#6
|
|||
|
|||
|
Re: PID control help
Fair point-- I took the reply to mean the *only* concern was rate and not position, but it is not entirely clear that the question was properly answered. My reply is only relevant (or at best only half relevant) if one does not care about position. If one is trying to keep two forks at the same height, position is critical, not just rate.
|
|
#7
|
||||
|
||||
|
Re: PID control help
Quote:
Last edited by Ether : 10-02-2015 at 15:14. |
|
#8
|
||||
|
||||
|
Re: PID control help
@ CD control gurus: Assuming it is desired to synchronize position (both the steady-state position and while the actuators are moving), what control method(s) would you recommend a) if the driver is issuing a position command, and |
|
#9
|
|||
|
|||
|
Re: PID control help
You'll need to make sure that the commanded rate doesn't drive one of the motors to 100% power.
It's common to have one drive be slightly more efficient than the other, and the slower one can't catch up. |
|
#10
|
|||
|
|||
|
Re: PID control help
Quote:
Year before we tried to drive 2 mechanisms completely in sync on PIDs (had very low tolerance for getting out of sync. But the code was climbing the robot and the pid could not react quickly enough if force on one side increased. In the end they fused the right/left together mechanically and it was much easier to code. So when in doubt, a hardware fix may be the best option. Looking forward to hearing what the gurus suggest. |
|
#11
|
|||
|
|||
|
Re: PID control help
After reflecting on the code from last year a bit, I'm thinking the same thing could have been accomplished (more simply) simply by writing a PID command along the lines if
Code:
public void returnPIDValue()
{
return leftEncoder.getDistance()-rightEncoder.getDistance();
}
public void returnPIDOutput(double output)
{
driveTrain.tankDrive(baseSpeed+output, baseSpeed-output);
}
Our code did something similar, but not entirely identical. Thoughts? |
|
#12
|
|||||
|
|||||
|
Re: PID control help
Quote:
Code:
public void returnPIDValue()
{
return leftEncoder.getDistance()-rightEncoder.getDistance();
}
public void returnPIDOutput(double output)
{
driveTrain.arcadeDrive(baseSpeed, output);
}
|
|
#13
|
||||
|
||||
|
Re: PID control help
Quote:
|
|
#14
|
|||||
|
|||||
|
Re: PID control help
Ether, could you explain in layman's terms what that means?
|
|
#15
|
||||
|
||||
|
Re: PID control help
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|