Tuning Recipe
by Yang/wdaehn, with edits by OlliW
A major problem for people new to brushless gimbals is finding the correct values of the PID parameters. A PID controller is a well known and often used method for calculating a new input value by measuring the difference between the current state and a target state, and applying a formula to the difference. In theory, after the calculation the target state would be reached immediately, but in reality it is not, because e.g. the motor is not indefinitely fast. So in the next iteration there is still an error, smaller but it exists, and an improved input value is calculated based on the new difference between actual and target states.
Due to this iterative approach the control loop can react precisely to any kind of distortions, but all sorts of bad things might happen if the formula is wrong. For example, the camera might look down by 15°, and our formula might be: motor power = 15° * 2 W/°. With this amount of power the motor will however rotate 30° upwards, instead of the requires 15°, and the camera will look up by 15°. Thus, in the next iteration, a motor power of -15° * 2 W/° is calculated, and the direction is reversed. The resulting effect would be a shaking of the motor and camera between the +15° and -15° positions. The formula used by a PID control algorithm is more advanced than in this example, and is optimized for quick reaction without overshooting the target position (too much). But even then, when the parameters are wrong, one gets all kinds of weird movement patterns.
See Wikipedia for further details on PID control.
Balancing the Gimbal
Before any tuning, the gimbal needs to be balanced. Balancing means to bring the center of gravity of the mounted camera into the center of all three gimbal motor axes (depending on the gimbal construction it is also part of the balancing to ensure that all three gimbal motor axes cross in one point). A quick test, which may be sufficient for larger cameras, is to move the camera by hand while all gimbal motors are turned off: The camera should remain in its position whenever you let it go, as demonstrated in the video below.
A perfectly balanced gimbal has many advantages:
- When the gimbal as a whole is accelerated, the camera would rotate out of position due to residual forces - see the image below.
- The motors need to apply more power to keep the camera in position.
- When turning the camera, e.g. with the RC stick, the center of gravity would change its positions with respect to the center of the gimbal motor axes.
- The PID control actions on different axes get correlated.
- Vibrations in the gimbal are more easily induced.
Balancing not only brings advantages, a certain degree of balancing is in fact mandatory for the gimbal and controller to function at all. It's as simple as that: The better the balancing the better the gimbal performance. This holds true especially for a 3-axis gimbal.
You will always have to compromise, because e.g. the gimbal does not allow for infinitely precise adjustments, or because of friction in the motors, and so on. Hence take considerable effort in balancing the gimbal as good as possible, but at some point one of course has to let go.
The picture below shows a badly balanced situation. The center of gravity is quite below the pitch motor axis. At first this might actually look like a good idea, since the camera gets "self-stabilized" by gravity. However, consider now the gimbal being accelerated to the right. Because the center of gravity is below the pitch axis, where would be a force on the camera and it would tilt downwards. The PID controller would have to fight against that, which makes it much harder or even impossible for it to stabilize the camera.
The video shows a well balanced gimbal. Here it is possible to move the camera to any orientation and let it free, without it turning back to a prefered orientation.
Some further tips:
- It is better to physically disconnect the motors from the board, since then they can move more freely than just beeing disabled in the GUI.
- A more severe test to check balance is to heavily shake the gimbal, up and down, left and right, forward and backward. When balanced, the camera will stay in the position it was before the shaking started. Do this for different camera positions.
- A 3-axis gimbal requires a more precise balancing than a 2-axis gimbal. Especially the yaw axis needs attention.
- In general, the smaller the camera the more important is the balance.
Tuning Procedure
The tuning of one axis might impact the other axis, so it is best to tune one axis after the other. Accordingly, the first step in tuning a brand new gimbal is to disable all motors except of the pitch motor, and find the proper tuning parameters for it. Then the roll motor is enabled and the corresponding PID parameters are tuned. Finally, the yaw axis is done.
Our goal in the PID tuning is to find the highest value for each of the P, I and D parameters which still work stably. The higher the values the better distortions can be compensated, and the more accurate the camera will be hold in position. If a value however is too large, then the PID controller will overcompensate, and we will notice oscillations, noise, or even erratic behavior in the worst case.
To find the sweet point we will start with a low value, increase it until the gimbal starts to misbehave, and move back until it works again. This will be done first for D parameter, then the P, and last but not least the I term.
Before that, we will have to set the Motor Vmax parameter, which also affects the tuning. Fortunately, it is relatively easy to adjust and not too critical (unless the gimbal tends to vibrationsat certain gimbal postions).
The procedure is illustrated below also by videos.
Further tips:
- One may turn the motors by hand into all allowed positions. This has less to do with the PID regulation by itself, but is a test if the current parameter values work well in all positions. If the gimbal and camera would be balanced perfectly, then there wouldn't be a need for that. But, reality ...
The Starting Point
Set the P, I and D values to zero.
Also, ensure that:
- All three axes should be in hold mode, i.e., in the [Pan] tab the parameters Pitch Pan, Roll Pan and Yaw Pan should be set to zero, or the Pan Mode Default Setting set to "hold hold hold".
- Voltage Correction should be set to 0%.
- The battery should neither be fully charged nor nearly discharged, i.e., have a voltage of ca 3.7 V per cell.
Setting Motor Vmax
The Motor Vmax parameter, or Vmax in short, determines the amount of energy applied to the motor. It should be large enough, such that the motor has enough strength to hold the camera in position, but on the other hand should not be that large that the motor overheats.
To determine the required motor power, turn the motor by hand against the motor's momentum and predict how much force will be needed to hold the camera in a steady position at any time. In the example video below, the starting value for Vmax is 190, and the motor shows a clear resistance to any manual movement. With the value reduced to 55, the motor can be turned almost freely. In fact, it does not even has enough power to keep the current position - so much about my gimbal is balanced perfectly, right? Finally the behavior is shown with Vmax set to the maximum value of 255.
In principle, using the maximum value would be okay, except that it is a waste of battery power and the motor might get hot. Also, with larger Vmax stronger micro motions of the motor are produced and, depending on the gimbal, the gimbal may more easily develop vibrations.
Therefore the advice is to define a useful low Vmax value.
Comment: A common misconception is that the motor needs to work only against the forces/torques due to an improperly balanced gimbal, and that one thus can get away with smaller motor power or motors if only the gimbal is very well built. However, if one wants to move the camera with the stick or wants the camera to follow the gimbal (pan mode), then the motor has to work also against the mass momentum of the camera. Unpredictable dynamic forces such as wind and so on come in in addition. Keep all of that in mind when estimating the amount of force the motor should apply to the camera.
The D Parameter
With P and I set to zero, there is no position correction at all, that is the motor will simply hold its current position.
The Derivative term of the PID control loop is not directly related to the movement of the camera. It is a high frequency correction looking ahead, in order to dampen what in future could become oscillations. If the D value is too high, then the frequency of the correction gets visible and/or audible. Therefore, by keeping P and I zero and just increasing D, one can find a point at which an audible high-frequency noise, produced by the gimbal motor, appears. The D value should be as large as possible without any noise occuring. Once a good value is found, one should move the motor by hand to doublecheck that no noise appears for any gimbal position which may ever occur. If a D value is working great in almost all positions except one, then that would be indication of an imperfectly balanced gimbal. Go then back to start.
An example tuning is illustrate in the video. Listen to it (switch on audio). Initially D = 0.17, and the gimbal is shaking like mad, with a low frequency and high amplitudes. Then the value is reduced to D = 0.10, and the camera position becomes stable, but a high-frequency noise can clearly be heard. With D = 0.05 the frequency gets even higher. We want the frequency to be that high that no noise is audible. At D = 0.04 the noise is suddenly gone.
Before the video was taken, the following actually happend. First D = 0.04 was picked, and everything was fine. With increasing it to 0.05, everything was still fine. At D = 0.06 heavy vibrations were visible, hence the previous D = 0.05 value was set, but now the vibrations were still there! In this situation one could manually move the motor into a different position and the vibrations would go away. What happened? At D = 0.06 the resonance frequency of the control loop was hit, but with a slight decrease to 0.05 the frequency remained very similar and the control loop was not able to get out of it by itself. So, to be on the safe side D = 0.04 was choosen, as for this value the shaking stopped by itself. The message is that it's quite natural to observe a hysteresis, that is that when coming from large D values one needs to go to smaller D values to stop a vibration than the other way around. Choose the D value, at which the vibrations stop.
Comment: In the GUI you can move the slider also using the the cursor keys. Click on the slider handle with the mouse, and hit the left/right key to change the value by its minimal step width. Very useful, especially for adjusting D.
The P Parameter
Now set the [I] value to 5, which is the lowest non-zero value and start tuning the [P]roportional term of the PID controller. This constant is multiplied with the positional error to get the correction amount. Exactly like in the example in the introduction at the top of this page. The higher the factor is the higher the calculated correction amount will be. If it is too high we will have the tendency of overshooting the target position and if it is way too high we would get even totally erratic movements. Hence our goal is to have a very high value here but a smooth movement in all motor positions.
The video below shows the procedure. After five seconds the [P] and [I] are set to values greater than zero and the Gimbal moves into a level position automatically. Then the [P] value is increased and we keep seeing the same behavior. Once P = 15 there are some weird shakes when the motor is released from a tilted position, which gets worse and worse and with P = 23 the camera does shake for a while even. Only once the [P] value is down at 13.0 a smooth movement from all positions is achieved again.
The I Parameter
Now we want to set [I] to the maximum value possible without introducing any side effects. If you look carefully at the last few seconds of the previous video, when [I] was at 5 still, the camera could not be kept level when the gimbal itself was moved. The [I]ntegral term (integral over the time) is responsible for this part of the movement.
In the video below the [I] value is increased to 480 initially and in comparison you can see the same movement with I = 5. Perfect movement now, fast speed, the camera remains horizontal, it truly is horizontal, everything fine. But maybe we can increase it even further. At 700 the same situation, everything looks nice. But at I = 1200 you can see that the camera no longer is horizontally aligned, the "time" aspect of the control loop starts to overcompensate. If you look carefully at the yellow cable of the IMU connector, it is vibrating - sorry, not very visible in the video. So 1200 is a too high value for sure. There were slight vibrations in some positions of the camera at 700 even, so [I] got set to 620 at the end.
Repeat for all Axes
The above procedure should be started with the pitch axis, and then repeated for the roll axis, and finally for the yaw axis.
The yaw axis has to handle the largest weight. Accordingly, the motor power needs usually to be higher than for the pitch and roll axes, that is either the Yaw Motor Vmax value is higher, or a larger motor is used.
Next Step - RC Inputs
With these settings we have a self-leveling gimbal. No matter what movements the gimbal support is undergoing, the camera remains stable in position. While this might be perfectly sufficient for basic operation, normally the gimbal shall also be moved via a RC stick or a joystick, or functions such as switching between hold and pan modes or releasing the shutter of the camera remotely are desired.
You can learn about these possibilities in the next chapters; continue with Configure the RC Input.