

maybe I'm just easily amused.  JVN [more] 



Thread Tools  Rate Thread  Display Modes 
#16




Re: Tuning a PIDF follower on a robot with high gearing
Quote:

#17




Re: Tuning a PIDF follower on a robot with high gearing
We're hoping that the Talon SRX's setNominalClosedLoopVoltage() can account for battery voltage sag, though we haven't at all considered inductance.
Last edited by Oblarg : 10022017 at 10:21 PM. 
#18




Re: Tuning a PIDF follower on a robot with high gearing
BTW I recently came across a procedure for tuning acceleration gain that I thought I would share. Haven't tried this myself yet, but it is pretty intuitive and the math checks out.
1) Tune velocity feedforward gain using standard methods (e.g. measure actual speed and divide by applied voltage). 2) Using (slowing ramping) triangular or trapezoidal motion profiles, tune the velocity integral gain (Ki) to achieve zero steady state error tracking during the ramp up and down. Leave all other feedback gains set to zero. It doesn't have to be perfect, you just want to achieve a ~zero error steady state without a ton of oscillation. You will probably lag behind the velocity profile at first, then integral will kick in and you'll converge with the velocity ramp, then you'll overshoot the end of the ramp up. 3) Plot the effect of integral gain (integrator * Ki) during the ramp up. Measure the peak control contribution of the integrator term during the ramp up, divide by the acceleration of the ramp, and you have your acceleration feedforward gain (Ka). 4) You can now remove the integral gain if you want (and you should try to if you can...integrators suck) 
#19




Re: Tuning a PIDF follower on a robot with high gearing
That is really, really clever. We'll have to try it.
I'm still hoping that, now that we've got a better handle on how to account for frictional losses, there's a chance that the "theoretical" value of Ka (i.e. calculated from motor stall torque, max voltage, gearing, robot mass, and wheel size) will work. Last edited by Oblarg : 10022017 at 10:43 PM. 
#20




Re: Tuning a PIDF follower on a robot with high gearing
Quote:
setNominalClosedLoopVoltage() does work wonders for battery voltage sag, though it still can't help you when you saturate. 
#21




Re: Tuning a PIDF follower on a robot with high gearing
Quote:
I'll report back next Monday on how the value of Ka we settle on compares to the theoretical value, now that we've fully ironed out intercept and Kv. 
#22




Re: Tuning a PIDF follower on a robot with high gearing
Quote:
I'm a big fan of doing things empirically, since it's often the shortest path to a solution that gets the job done, and I am a very busy (and *very* lazy) man. Not sure if your motor matches it's spec sheet? Don't have a clue how efficient your geartrain is or how much inertia it has? Not sure how to make the right tradeoffs when doing pole placement or LQR? Stuck using Java? Who cares (*), throw a Talon at it! Both approaches have their time and place *: A rudimentary model to validate that the mechanism is reasonably close to a firstorder LTI system and to bootstrap PIDF gains into the right ballpark is still helpful. Last edited by Jared Russell : 10022017 at 11:14 PM. 
#23




Re: Tuning a PIDF follower on a robot with high gearing
Quote:
One of my other recent finds has been comparing modeled acceleration to measured acceleration in our drivetrain. I'm finding that the difference is even higher than I originally expected. I've got a disturbance force term in the drivetrain kalman filter which serves a similar purpose to Jared's integral solution before. That term should be 0 in an ideal model. So, you can correlate that signal with what's going on to try to determine where your model mismatch is. I'm not sure where this exploration will lead, but it might lead to discovering gearbox inefficiencies, wiring problems, etc. Our model based feedforwards is essentially just numerically inverting the model. I've now also got feedforwards on all our subsystems because the math is already solved. Model based controls tend to push the work more upfront, whereas empirical controls might save you time, or might push you to react to each problem. Building off (*), I'd say that having a good understanding of the models for a couple mechanisms can really help you cut corners. If I'm doing a position loop with an arm, I know intuitively how all the dynamics work, what the different constants mean, etc. If I were given a brand new configuration that I hadn't seen before, I might have much more trouble writing a loop for it without understanding the physics. 
#24




Re: Tuning a PIDF follower on a robot with high gearing
So we tested the intercept and Kv yesterday using velocityonly motion profiles, and it worked very well except that we needed to get separate intercept and Kv for each side of the drive. The difference between sides was about 10% for us, on a robot using 3 cims per side but in opposite directions (probably some combination of motor bias and 4yearold CIM slop). We didn't have time to go back and calculate the intercept and Kv for the other side (the data posted earlier was for the right side only), so we just tuned it until it drove straight. Once it did, we checked the distance and it went 102 inches (setpoint was 100), so I'd guess it would work great first try if you calculate each side from the vel vs voltage curve. We added in the theoretical Ka of 100 feet/(sec^2) and it reduced the error down to 101 (still without position servo, just velocity FF). We tested it with two different profiles and the error was about the same. Adding in the position servo reduced the error down to 0.25 inches. Next week we'll test this on some curved profiles and report back.

#25




Re: Tuning a PIDF follower on a robot with high gearing
It's worth noting that with a calculated maximum acceleration of ~100 feet/sec^2, the actual voltage value of the acceleration feedforward is quite small (on the order of half a volt, maximum, with the profiles we're running). The addition of an intercept to the feedforward was by far more important in getting reasonably good openloop following of the profiles.
It seems that this form of feedforward (intercept + Kv*vel + Ka*acc) works reasonably well across different cruise speeds  we tested it on 100''long profiles with peak velo/acc/jerk of 4/3/6 and 7/4.5/9 (ft/sec, ft/sec^2, ft/sec^3) and saw no major difference in error between the two. I think we can conclude that this is likely a better solution than gain scheduling, and teams should try it first. Last edited by Oblarg : 10102017 at 09:44 AM. 
#26




Re: Tuning a PIDF follower on a robot with high gearing
This seems to be the right thread to post this.
This is my first time trying to tune PIDF. Our robot has a (measured) max speed of 15 ft/s, and acceleration of 6.4 ft/s/s. I started with a simple 24 foot long straight path, a max speed of 8 ft/s and max acceleration of 4.5 ft/s (I plan to use these values for all paths) using 254's 2014 trajectory follower and trajectory lib code. In 254's presentation, they mentioned kv being 1/velocity and ka being 1/acceleration. I tried that first, and the robot flew away and almost killed a bush. Using excel I graphed the desired path vs the actual one taken. The path is cut short because I needed to save the poor bush: So it seems my acceleration was off. I took a different approach next, First tuning kv until it went the correct velocity (after accelerating and lagging behind). I ended up with kp = 0, kv = 1/12, ka = 0: Then I added onto ka until the profiles were very similar. kp = 0, kv = 1/12, ka = 1/18: I couldn't seem to make them any better than that, any change to ka made it worse. At most the error was ~6" in the path. Then I raised kp until the error was a flat line kp = 2, kv = .0833, ka = .0556: My Questions: Is this the correct way to tune PIDF? Did I tune kv and ka well enough before adding in kp? Kp seems really high, Is that normal? Why are kv and ka not 1/ tested velocity and 1/tested acceleration? My ka was 1/18, my robot definitely does not accelerate to full speed in under a second, though it does seem faster than 6.4 ft/s/s. Here are the imgur links to the graphs, as they seem blurry as thumbnails: https://imgur.com/xFTN8zV https://imgur.com/xHTJT5m https://imgur.com/1wZ5kBR https://imgur.com/Esi2zkY Thanks! Julia Team 291 Last edited by Classified* : 10112017 at 12:53 PM. 
#27




Re: Tuning a PIDF follower on a robot with high gearing
Quote:
The first thing to realize is that, while it is true that Kv should be on the order 1/max velocity, and Ka on the order of 1/max acceleration, these mean rather specific things and so may not neatly correspond to what you have measured. In order to understand why this is the case, we must look at the state equation for a brushed DC motor, which is of the following form (we shall assume, for sake of convenience, that there is neither friction nor wheel slip): V = K*w + IR Where V is the applied voltage, K is some constant, w is the angular velocity of the motor, I is the current, and R is the resistance. Well, what does this tell us? We know that w is, clearly, proportional to robot velocity. We also know that I is proportional to torque, which is proportional to robot acceleration. Thus, by appropriately absorbing constants, we can rewrite this state equation: V = Kv*vel + Ka*acc This yields the general form of our feedforward. So, how do we figure out the values of Kv and Ka? Well, note that from our two equations we can observe the following: Kv*vel = K*w Ka*acc = IR Let's consider the first equation. At free speed, we know that K*w must equal the entire applied voltage, V (this is the definition of "free speed"). Thus, if we call the robot's velocity with the motor running at free speed "maxvel," we have Kv*maxvel = V => Kv = V/maxvel. Similarly, let's consider the second equation. At stall, we similarly know that IR must equal the entire applied voltage (since w is 0). Thus, if we call the robot's acceleration with the motor outputting stall torque "maxacc," we similarly have Ka*maxacc = V => Ka = V/maxacc. So, you'll note that the above formulas have a 'V' instead of a '1'  this is simply because we have done the math with voltage output, instead of fractional output. But, more importantly, after going through the math it should now be clear exactly which values of "velocity" and "acceleration" are required. We need the velocity of the robot with the motors running at free speed, and the acceleration of the robot with the motors at stall, both with our maximum applied voltage (actually, the math works at any arbitrary applied voltage but you'd have to change the numerator to match, and the values thus remain the same). So, why might your measured velocity and acceleration have resulted in your robot running away? Likely, because it is actually rather hard to empirically measure these two quantities. Max velocity is the easier of the two to measure, but you will likely run into the problem of not being able to actually clock the robot's speed at 12V applied, because a) it takes a lot of space for a robot to actually reach steady state at max speed and b) the internal resistance of the battery will likely prevent you from actually applying 12V at any nontrivial current load. Still, a reasonable job can be done to account for these, for instance by measuring at a voltage other than max (as noted above), or (better) by taking the "linear regression" approach I detailed earlier in the thread. Note that a reason your Kv seems to imply a max speed lower than what you have measured is likely due to the presence of an "intercept" in the voltage/speed curve due to friction resulting in your linear approximation not fitting quite right at your target velocity, again as discussed earlier in the thread. Max acceleration is basically impossible to directly measure because, in addition to the problems above, it is not actually attainable without slipping the wheels (unless you measure it at a fairly low applied voltage), and because it is only achieved instantaneously (and so, unless you have very highresolution encoders and a very fast loop reading them, you likely will have trouble taking an accurate measurement). You may be better off calculating the theoretical value from the stall torque of your motors (if you followed the math above, it should be clear how to do this), or else just tuning it empirically as you already have done. Note, however, that (as you noticed) the value for "max acceleration" actually used in this calculation is likely going to seem huge  but even with no wheel slip and a perfect voltage source, it could never be attained for more than a split second before dropping as the motors begin to speed up (again, refer to the state equation to see why). As for your other question: What solution are you using for following the paths? Are you running the loop yourself on the RIO, or are you using the CANTAlonSRX's Motion Profiling mode? It is hard to know whether your P value is reasonable or not without this information  the scaling of P depends on your units, and thus on your implementation. If you are using the Talon's MP mode, a P of 2ish (with 512 CPR encoders and the Talon's native units) is reasonable in my experience; again, though, this does not necessarily generalize! Last edited by Oblarg : 10112017 at 05:06 PM. 
#28




Re: Tuning a PIDF follower on a robot with high gearing
Quote:
I am reading the encoders and calculating the outputs on the RIO scaled to be in feet with the loop running at 50 per second. We do not have talons, we are using Sparks. I measured the velocity on the ground, so not at free speed. And to get the acceleration I took the approximate slope of the (very nonlinear) velocity graph. Bad I know. Quote:
Last edited by Classified* : 10112017 at 01:58 PM. 
#29




Re: Tuning a PIDF follower on a robot with high gearing
Quote:
Regarding the value of Kp, rather than thinking of the value of the gain itself (which does not generalize because it depends on units), it is better to think of some reasonablydimensioned quantities that depend on it. For example, determine what fractional output is added if your positional error is 1 inch with your current Kp value of 2. This is a much easier quantity to make sense of. Quote:

#30




Re: Tuning a PIDF follower on a robot with high gearing
Quote:
How did you measure the points on this graph? Was your robot up on blocks or on the ground? It seems like you would only get an intercept if the robot is on the ground. 
Thread Tools  
Display Modes  Rate This Thread 

