Our team has finally decided to try and build an elevator on our off season robot. I can get the elevator working perfectly fine with motor control but I’ve discovered PID control and have not a single clue how to go about implementing it on my robot. If anyone has code examples and documents that you use to explain it and show it to your programmers I would greatly appreciate it!
Take a look at “elevatorprofiledPID” and “elevatortrapezoidalprofile” folders here:
They are a bit more advanced (under the covers) than a traditional PID, but are EASY to use and should provide repeatable, reliable results. They also require PID tuning.
This past year I added PID Control to our elevator on the robot:
The main thing is to figure out what your encoder value means to the elevator’s height, then be able to pass that information to the motors
I would have to test that once the builders actually complete the elevator, hopefully this helps!
Hi,
First, you need to make sure the elevator has a sensor of some sort, either a potentiometer or encoder. Last year, our team used a potentiometer to measure the height of the elevator. Once you have the sensor working in code, you will want to figure out which set positions your elevator will need to travel to. For DESTINATION Deep Space, we had a low, middle, and high position.
After these positions are determined, you can write a simple P control loop method that sends voltage to the elevator motor(s). The farther away you are from the set position, the higher the power and vice versa.
void setPosition(double setpoint) {
double error = setpoint - this.getPosition();
double output = Kp * error;
double final_output = Math.min(Math.max(output, this.Kminoutput), this.Kmaxoutput);
this.setPower(final_output);
}
First, we pass in the setpoint we would like to go to. Using the setpoint, we can determine our error by comparing our setpoint to our current sensor position. The calculated error is then multiplied by our “P” value to determine the output. This “P” value will be a low number, for example, our elevator “P” value last year was 0.065. You will have to tune this “P” value in order for the elevator to operate smoothly.
If the “P” is too high, you will likely see the elevator oscillate above and below the setpoint.
If the “P” is too low, the elevator will not reach the setpoint.
There may be better ways to determine a good starting “P” value, but we usually start at a very low value, such as 0.01, and then double it until we either see the elevator reach the desired position or until we see the elevator begin to oscillate (“P” is too high).
The next part in the method, trims the output to be within a certain range of acceptable voltages then we send the final output to our motors.
I hope this helps!
Here’s a video of it working:
I am not saying that I am a good programmer… because I am not. What I had set up is something that I hope to replicate going into the future for anything like this. It was really simple and it solved every problem that we shoved into it.
The basic concept was that I wanted to serialize the data for each level, and I did that through creating a data class then put it into a list. This list was then split into two “sub-lists” (ball locations, panel locations). Depending on if there was a ball or a panel, the appropriate sub-list would be fed into an iterator. This was the toughest part, everything else is relatively easy. The iterator would spit out the next level on each button press.
I can’t speak on efficient PID tuning, because it is as simple as this for me: did it hit its target? If no then change something. I wish I could tell stories on how I used method XXX to tune our PID controllers each year, but I cannot.
Last year our 4 bar lift used Motion Magic, and it worked out very well. It was really set it up correctly and forget it. Look into our Lift.java to get an overview of how it worked.
I would say it is my greatest masterpiece of programming that I have made in the past 20 years doing FRC (Darn it, Jim, I am a mechanical engineer, not a robot programmer…). Next, I will be quitting my day job and running off to the programming circus.
Not exactly what you asked for… but in 2018 we used a modified bang-bang controller to get us to the right height.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.