PID explained
engunneer | February 28, 2012 10:20 amThe topic of PID often comes up when I talk with FIRST teams. This post is how I explain it to students. I was recently explaining it in a post on Chief Delphi, so I decided to turn it into a blog post while I was at it.
The basic idea for PID is that it corrects for errors. if you make a PID loop based on position, it will move your motors such that the position is what you want. you can replace the word position with the words velocity, angle, and even acceleration or motor current. you can also loop multiple parts of your motion. (i.e. Loop position and velocity), but for FIRST, you usually only need to put a loop around one thing.
Let’s use position for discussion, which is easiest to visualize. First, you need a way to measure your position (an encoder can be used for position or velocity, the gyro or an accelerometer can measure angular data.). The difference between the position you are in, and the position you want to be in, is your error. PID acts on this error to try and make it 0.
In a typical machine tool (like a CNC machine (Hey look, FIRST applies to the real world
)), you want to position an axis. Say the axis is currently at zero, and you want to move it a meter. Your commanded position is 1m, and your actual is 0m, making your error +1m. (The sign is important!). Proportional Gain is a number we multiply by the error to get a motor command. Sometimes this is a speed (engineering unis such as m/s), or in our case, it is a motor command in the range of -1 to +1. Let’s say our proportional gain is 0.5. 0.5(gain)*1m(error) = 0.5(command), which moves our motor towards where it is supposed to go.
For the sake of discussion, let’s say our motor is geared such that a command of 1 means the mechanism in question is moving at 1m/s. That is also the top speed of the motion, since the command cannot be greater than 1.
PID loops execute repeatedly in your Periodic tasks, so they occur with a fixed time base. To demonstrate, I’ve put this together as an excel worksheet, and posted it to here -> PID worksheet. The sheet lets you play with some different PID settings, and lets you look at how the mechanism will move based on the commanded velocity. It’s not taking friction or even acceleration into account, but it gives the basic idea of how PID works.
The D (derivative) gain is applied to the difference between the error last cycle, and this cycle. It can be used to slow down the movement if it is approaching the target to quickly.
Integral Gain (I) is applied to the total sum of all errors. It is common to not accumulate errors if the error is too large, or to limit the accumulation to a certain value, or to clear out the accumulator when you are in position. The job of I is to take care of small position errors that occur when the P gain alone is not enough to overcome friction or some other limiting mechanical feature.
The sum of the P I and D values are added together to create the motor command. The gains have to be tuned to get the response you want. If P I or D are too large, the system will oscillate. If the signs are wrong, the system will run away. If I is not controlled a bit, it can overshoot significantly. Most FIRST mechanisms work just fine using P, PI, or PD modes. P mode means that I and D gains are 0. PD means I is 0, and PI means that D is 0.
PID does not always need to be reactive. In general terms, there is a further thing you can add called FeedForward, which you can apply to either velocity or acceleration, as the case may be. The basic idea with Feedforward is that you know you’ll be moving in a certain direction anyway, so give a little boost to your velocity or acceleration, then let the rest of PID react once you get going. You can see this on the second sheet of the workbook.
If you have any questions, please post a comment!
Categories: FIRST Robotics
No Comments »
Updated Shot simulation (Still no Drag or Magnus effect)
engunneer | February 17, 2012 11:12 amI got a request to add the second angle option to the macro calculated angle section. In theory, there are two launch angles that hit the same target. I biased towards the highest one, because the margin of error for making the basket is wider.
I also noticed that the macro section assumed the ball launched from 36″ off the floor (set on the third sheet), so I changed it to take the h_0 setting from the top of the first page, so all charts assume the same launch height.
Here’s the updated spreadsheet:shot simulation (macro)
The biggest thing to keep in mind is that there is still no Drag (Air resistance) or Magnus effect (increased range due to backspin). I’m hoping the two effects somewhat cancel each other out, but they will both be significant in the real world.
Categories: FIRST Robotics
No Comments »
DIY CNC milling machine
engunneer | January 29, 2012 9:58 pmOne of my friends from seattle wrote to ask about my CNC milling machine, so I finally have taken some pictures of it to share. Click the thumbnails for a larger view. To the right of the X axis, you can see the E-Stop switch, which is wired in to the computer. There is a small tray (part of an old printer) behind the X axis, which can be used for holding tools or bits.
The machine itself is built on a plywood frame. The X axis carries the Z axis, which has the dremel attached to it. The dremel mount itself is not particularly exciting, except that the main wood part of it was milled on this machine. It was a bit of a chicken/egg problem. Each axis has a wooden block to act as a spacer, with a small metal plate to aid in alignment. The X and Y axes both have damping weights on the back shaft of the motor.
The motors themselves are NEMA 17 sized bipolar stepper motors with the shaft going all the way through. They are attached via a servo coupler to the lead screw, which has a 1 mm pitch. Overall, the travel of all axes is about 95mm.
The Y Axis is mounted under the table. All three axes have limit switches that are used for homing.
The main control board uses an old printer connector (from the same printer that donated the tray) to go back to the parallel port on the PC. The PC itself is an old P4 1.8GHz that I got for $40 from the UW Madison Swap Surplus Store. It runs the EMC on top of Ubuntu Linux. The machine has a separate PC power supply to power the stepper drivers. I modified it to include a small relay and a power outlet (to the left of the control board). This lets me have a logic switchable power outlet for the dremel. All the 120VAC wiring is done inside the case of the power supply, so risk of shock is reduced. Each stepper is driven from a very handy Pololu A4988 Stepper driver. I have little heat sinks that I have not yet installed to let me push a little more current through the drivers.
One of the other nice features I added are four storage boxes above the power supply. These were originally microscope slide boxes. A cup hook keeps each one from falling out. turning the hook a quarter turn releases them.
All told, this project cost me about $100 in parts that I didn’t already have. The linear axes from THK were all free surplus from a friend of mine. I’ve used it to mill plastic boxes for prototype circuits, and some 3D profile milling with a 1/16″ end mill.
Categories: Uncategorized
No Comments »
FIRST 2012 Ball Trajectory Spreadsheet
engunneer | January 9, 2012 11:07 pmIt’s the time of year for FIRST again, and this year’s game (Rebound Rumble) is looking like it’s going to be pretty exciting. This year, I’m helping Team 2151, the Monty Pythons.
I made a spreadsheet to help with planning a shooting mechanism, and to help with testing or writing code.
The spreadsheet is broken up into different sections. The first section has the basic parameters to calculate what velocity is needed for a given set of shot parameters. Set the cells that are green to your values, and the first orange boxes will show the velocity needed for each of the three hoop levels. If the angle of the ball entering the hoop is too shallow, the box will turn red. The h0 (robot shooter height) parameter is used for all the sections, so make sure you set this accurately before going down to the other sections.
The next section calculates a the velocity needed for a variety of shooting angles for a given range. This does not check to see if the shot is too shallow. The first section can be used to look at any individual shot to see if it passes the shallowness test. There is an inverted chart off to the right that swaps the X and Y axes, which gives a different view of the data. The left chart can be used to find a desired velocity for a given range and angle, where the right chart can help you choose an angle to go with your known velocity.
The next section is useful for robots with a fixed shooting angle. It calculates the velocity needed to make baskets at a variety of ranges. There is an inverted chart off to the right that swaps the X and Y axes, which gives a different view of the data. The left chart can be used to find a desired velocity, while the right chart can be used to see what range you’d get out of your current velocity.
The last section is only in the macro version of the spreadsheet. It is designed for robots with a fixed firing velocity (such as a pneumatic launcher). It calculates (using an iteration macro) the needed angle of launch for a fixed velocity and a variety of ranges.
The most useful part of this is for estimating a formula to use in the robot code. The math itself is non-trivial to rearrange.
Hopefully this spreadsheet is useful to other teams, so I am posting them here. shot simulation (macro)
Please let me know what you think below
UPDATE (10AM): I added some trendlines to the last graph in the macro version. Now you can specify what range to look at and it will give you a cubic formula for a trendline for each hoop. The trendline will get messed up if you don’t have enough velocity to make the range (blank results in the orange boxes). if you ever get an error message (if the macro fails to find a result), you may have to go to sheet 3 and change cells in the B10 to D22 range to 89 to get it working again. Basically, if the GoalSeek Function can’t find a result, it can make an error pop up. I try to prevent the most common errors, but asking for longer ranges is more likely to have issues.
Be sure to check results back up in the first section to make sure the angles are still valid. The first section can also be used for checking the human player parameters needed to make a shot. set the range to 54 or 56 feet, set the angle high enough to clear the 8 foot alliance wall, and then see what sorts of velocities are needed to make the shot.
UPDATE (10:10AM): I fixed a bug with the entry angle lookup code.
UPDATE (10:40AM): I added the height of the apex of the curve to section 1.
Tags: calculator,FIRST,FRC 2151
Categories: FIRST Robotics
5 Comments »
Working on the Workshop88 makerbot calibration
engunneer | November 28, 2011 9:28 pm
Last week at Workshop88, I was working on the makerbot calibration, and the DC extruder motor managed to die. I had two spare DC motors at home, so I brought one over to the hackerspace tonight to repair the bot. We just need it to work long enough to print itself a stepper upgrade kit.
After the replacement, I calibrated a bit more, and printed a pair of small gears. I still need to work on the first few layers, and now I’m printing a Mr. Alligator
Stepper upgrade kit:
Tags: makerbot,workshop88
Categories: hackerspaces, makerbot
No Comments »
BuRbot Initial Assembly
engunneer | September 21, 2011 10:44 amI managed to convince my boss to let me try an experiment with a second makerbot, based on the industrial CNC control software and industrial control hardware made by my company. This gives me the excuse to play ability to learn more about how our hardware and software work, and I get to make a pretty Makerbot, to boot.
This past weekend, I did the paint job (except for two end caps I forgot to paint), and did the initial assembly of the hardware, including the new control system to replace the Gen3 electronics (which are in my spares bin for the first makerbot). I really like how the paint came out, and the company colors look really good on the bot.
I still have to finish assembling the extruder (need to order thermocouples), but I put the MK6 in place anyway. I’ll end up using a HBP instead of the stock platform, most likely.
The plan now is to still use Skeinforge for slicing models (Using SFACT, which was the suggestion of Sacha at Pumping Station:One), but to replace most of the rest of it with the new control system. Certain items (parametric open scad scripts) will be able to be compiled on the fly, sliced, and then printed, all on board the bot. The main issue will be the time to slice files, since that can take a few minutes, and possibly longer on this computer. I will at least have some precompiled gcode for demonstrations. I need to look into a nice STL viewer (particularly one that can be run in a web browser).
The user interface is going to be this nice looking touchscreen computer that we make. I still need to work out how I’m going to mount it.
Things mentioned in this post:
Categories: BuRbot, makerbot
No Comments »
Makerbot Upgrades
engunneer | September 3, 2011 8:35 pmI finally got my heated build platform put together. I had tried some thin steel (from my ABP attempt), but it was too fliexible. I went to Menards and got some 0.025″ aluminum, which is a hair too thin, but I was able to cut it with tin snips, and get it installed.
I still need to do something to level it properly, and find better screws, but the plate is too thin to properly countersink them anyway.
Another easy modification was precipitated by the drive gear stripping off the M6 bolt in my stepper extruder. While I had it apart, I drilled an access hole to reach the set screw on the filament drive. If it ever loosens up again, I can get in here with a hex wrench and tighten everything up again.
Categories: Uncategorized
No Comments »
Hackerspace Tours – Freeside Atlanta, Atlanta, GA
engunneer | August 25, 2011 8:35 pmThis month, I also got to tour Freeside Atlanta. I was a member here from July to November 2010, but it was good to go see how things have been going at the space since I left.
If you are ever in the Atlanta area, go check them out!
Categories: Uncategorized
No Comments »
3D Printing Filament
engunneer | August 18, 2011 8:18 amI’ve been wanting to know what filament costs, so I decide to make a google doc that works out prices in a nice comparable way. The RepRap wiki page for suppliers is a great resource, but it quickly becomes obvious that there are infinite ways to sell plastic, making price comparisons difficult. So I made a Google Spreadsheet. This sheet converts all the prices into USD using current exchange rates. This should allow for a more direct comparison, though shipping is not included.
If you want to view the raw data (so far), go to the spreadsheet.
If you want the csv file for doing your own comparisons, look here.
Or try the Interactive Filterable List. I just wish it had sorting.
If you want to help add data, send me an email (engunneer @ this domain) with the subject [printing supplier data], and I’ll add you to the sheet. I’m not quite ready to throw it out to the public for editing yet.
If you see an error in the data, let me know. There are a few known inaccuracies, for example really special colors, and I’m approximating the volume and length based on published density information.
If you know of a supplier that isn’t on the wiki, please add them!
Update: I created a form. Let’s see how this goes, shall we?
Categories: Uncategorized
1 Comment »










