Tuning Recipe: Difference between revisions

From STorM32-BGC Wiki
Jump to navigation Jump to search
(Created page with "One of the most important steps is of course the proper tuning of the gimbal. However, it is also - unfortunately - the least straight-forward and most debatable step. No uniq...")
 
No edit summary
 
(97 intermediate revisions by 3 users not shown)
Line 1: Line 1:
One of the most important steps is of course the proper tuning of the gimbal. However, it is also - unfortunately - the least straight-forward and most debatable step. No unique or universal tuning recipe seems to have emerged yet, and tuning remains an experimental process of trial-and-error. The following can hence only attempt to give some ideas. It is also necessarily very subjective, i.e. based on individual experiences on specific gimbals. Furthermore, a basic understanding by the operator is unavoidable, and the following is accordingly explanatory in parts.
<span style="font-size:88%">''by Yang/wdaehn, with edits by OlliW''</span>


If your experience has led you to different tuning rules please feel free to share them (the [http://www.olliw.eu/storm32bgc-wiki/index.php5/Talk:Tunning_Guide Discussion] page could be a good place for that).
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 is applied, 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.


== Tuning the PID Controller of one Axis ==
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 rotate 30° upwards, instead of the desired 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.


=== Preliminaries ===
See [http://en.wikipedia.org/wiki/PID_controller Wikipedia] for further details on PID control.
The PID controller is the part of the firmware which controls the orientation (attitude) of the camera by using the measured attitude for driving the motors such that the camera stays put. It is assumed that the reader understands the basics of PID controllers; many introductions are available on the web. At this point the first, and maybe most important comment is at place:


'''The PID tuning rules given in (essentially) all texts on PID controllers do NOT apply to brushless direct-drive gimbals!'''
Below a relatively simple and straight forward tuning technique is suggested, which often works surprisingly well, and has a theoretical foundation. However, it may also fail. In fact, it is important to realize that some gimbals might not be tunable at all, because of e.g. too weak or too strong motors, too high friction, improper balance, and several other reasons. As a rule of thumb: When you don't get a good tuning within 10 min (per axis) then chances are that something is wrong with the gimbal design. There ain't no such thing as a hard to tune gimbal. There are just well and badly designed gimbals.


So, the situation for brushless gimbals is somewhat different to that for the "usual" systems, and this obviously affects the tuning practice. Furthermore, although maybe termed PID in all cases it seems that the implemented PID controllers differ somewhat in their working; one probably should distinguish as follows:
== Balancing the Gimbal ==


* AlexMos 2.3 and below, [http://www.rcgroups.com/forums/showthread.php?t=1978860 EvvGC]: These firmwares implement basically PD controllers, with a "weak" I term.
Before any tuning, the gimbal needs to be balanced. Balancing means to bring the center of gravity (COG) 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 someone points). 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.
* [http://sourceforge.net/projects/brushless-gimbal-brugi/ BruGi], [http://www.rcgroups.com/forums/showthread.php?t=2059364 BGC32], AlexMos 2.4, o323bgc/STorM32bgc: These firmwares implement "full" PID controllers.


'''''Comment:''' The AlexMos codes are of course not available, one can hence only speculate, however the various available descriptions/tutorials are telling.''
A perfectly balanced gimbal has many advantages. Otherwise you will get artefacts, such as:
* 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.


The good message is that the PID controllers in the second category of firmwares work by the very same basic principles, which means that the tuning recipes given for any of them may be used to tune STorM32-BGC gimbals (be aware however that this doesn't mean that PID values can be carried over; the units generally are different!). The less good message is that there seem to be two different tuning strategies, which may be called "low-PWM" and "high-PWM" tuning, and neither of them avoids experimenting. The "low-PWM" tuning resulted from experience for Gopro and larger gimbals; the "high-PWM" tuning has been described for micro gimbals. At this point it's not clear which one is generally better, or if any is the best at all.  
Balancing not only brings advantages, a minimum 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.  


As a general tuning rule, consider:
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.


Don't overdo it. Better be a bit conservative.
The picture below shows a very 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 first sentence is supposed to mean that while it's true that a proper tuning can lead to enormous performance gains and is mandatory for optimal operation it's also true that it is meaningless to adjust the parameters to their last digit. The second sentence reflects the fact that a PID controller which is aggressively tuned for a certain condition (e.g. battery voltage) is also very sensitive to changes in these conditions, i.e., is less robust.
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 preferred orientation.


Finally, although it may be obvious and may appear a bit smart ass, it cannot be over emphasized that:
Please also consider these tips:
* It is {{WARNING|'''important'''}} to electrically disconnect the motors from the board, since then they can rotate more freely than just being disabled in the GUI.
* A much 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 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.


The key to a good performance of the gimbal is a perfect mechanics and balance.
::[[File:DSC_7111.jpg]]


Inspection of the various threads immediately confirms this point.
::{{#ev:youtube|4Mq2NTyiBf8}}


=== Basic PID Parameters ===
== Tuning Procedure ==
The basic PID controller parameters are {{GUI|P}}, {{GUI|I}}, {{GUI|D}}, and {{GUI|Vmax}}.
The parameter {{GUI|Vmax}} is known in other firmwares as the motor PWM or motor power.


The o323bgc firmware provides also the parameters {{GUI|Pan}}, {{GUI|Voltage Correction}}, and {{GUI|Hold To Pan Transition Time}}. These are however not relevant for the basic tuning, and {{GUI|Pan}} should in fact be deactivated for tuning.
{{COMMENT|T-STorM32 users please refer to the article [[Getting Started with T-STorM32]]}}.


[[File:1main.png|480px]]
The tuning of one axis might impact the other axis, nevertheless 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.


=== Coarse Tuning Settings ===
Our goal in the PID tuning is to find the highest value for each of the {{PARAMNAME|P}}, {{PARAMNAME|I}} and {{PARAMNAME|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.
For the basic tuning, the advanced tuning parameters should be deactivated.  


* {{GUI|Pan}} MUST be set to zero (or the hold mode ensured by other means, such as via the {{GUI|Pan Mode Control}} settings)
To find the sweet point we will start at a low value, increase it until the gimbal starts to misbehave, and lower it until it works again. This will be done first for the {{PARAMNAME|D}} parameter, when the {{PARAMNAME|P}} value, and last but not least the {{PARAMNAME|I}} term.  
* {{GUI|Voltage Correction}} should be set to 0%
* the battery should neither be fully charged nor nearly discharged (i.e. have a voltage of around 3.7 V per cell)


The first step is to obtain a basic, working tuning of all axes (coarse tuning). One should tune first the pitch axis, then roll, and then yaw. Ideally one would block the roll and yaw axes while tuning the pitch axis, and the yaw axis while tuning the roll axis. In any case make use of the {{GUI|Roll Usage}} and {{GUI|Yaw Usage}} parameters to avoid uncontrolled motion or even damage to the gimbal.  
Before that, we will have to set the {{PARAMNAME|Motor Vmax}} parameter, which also affects the tuning. Fortunately, this parameter is relatively easy to adjust and not too critical (unless the gimbal tends to vibrations at certain gimbal positons).


Once the gimbal is coarsely tuned, one may proceed with fine tuning, which is entirely trial-and-error and no tuning recipe exists at all. Here the Data Display is most useful.
The procedure is illustrated below also by videos.
<!--
Further tips:
* A parameter setting may be double-checked by turning the motors by hand into all allowed positions. This has less to do with the PID regulation by itself, but tests whether 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 to do that, but, reality ...  


=== "Low-PWM" Tuning ===
::[[File:Storm32-wiki-imu-pid-01.jpg|480px]]
The "low-PWM" tuning strategy starts from the recommendation to set {{GUI|Vmax}}, or motor power or PWM, as small as possible.
--><!-- this simulator isn't a PID simulator!
=== The Online PID Simulator ===
If you want to know more about the PID control loop, there is a [[PID online simulator]] page showing the effects in a diagram and let you play with the various parameters.-->


The motor power should of course also be as large as needed to overcome the motor's cogging torque, friction or imperfections in the balance. This sets a lower limit to {{GUI|Vmax}}. Typical tuning guides are
=== The Starting Point ===


* [http://sourceforge.net/p/brushless-gimbal-brugi/wiki/PIDtuningguide/ http://sourceforge.net/p/brushless-gimbal-brugi/wiki/PIDtuningguide/]
Set the {{PARAMNAME|P}}, {{PARAMNAME|I}} and {{PARAMNAME|D}} values to zero.  
* [https://bradatech.com/xPedRobo/shop/download/uploading_software_martinez_board.pdf https://bradatech.com/xPedRobo/shop/download/uploading_software_martinez_board.pdf], page 10
* [http://www.multi-rotor.co.uk/index.php?topic=2945.0 Quick how to tune guide for BRUGI/martinez brushless gimbals]
* [http://blgwiki.com/index.php?title=A_Tuning_Guide A Tuning Guide - Brushless Gimbal Wiki]
* PLEASE ADD HERE


As said before, this recipe has emerged from the experience by several authors on Gopro and larger gimbals, and in this sense may be considered as "proven". Generally, the motor power must not be too small:
Also, ensure that:
* All three axes should be in hold mode, i.e., in the {{GUI|Pan}} tab the parameters {{PARAMNAME|Pitch Pan}}, {{PARAMNAME|Roll Pan}} and {{PARAMNAME|Yaw Pan}} should be set to zero or alternatively the {{PARAMNAME|Pan Mode Default Setting}} set to {{PARAMVALUE|hold hold hold}}.
* {{PARAMNAME|Voltage Correction}} should be set to {{PARAMVALUE|0%}}.
* A 2nd IMU should be deactivated, i.e., in the {{GUI|Setup}} tab the parameter {{PARAMNAME|Imu2 Configuration}} should be set to {{PARAMVALUE|off}}.
* The battery should neither be fully charged nor nearly discharged, i.e., have a voltage of about 3.7 V per cell.


The value of {{GUI|Vmax}}, or motor power or PWM, should not be below 65 or 25%.
=== Setting Motor Vmax ===


Lowering the {{GUI|Vmax}} value also diminishes the available angle resolution, and if it's too small the gimbal can't correct smoothly anymore.
The {{PARAMNAME|Motor Vmax}} parameter, or {{PARAMNAME|Vmax}} in short, determines the amount of energy applied to the motor. <!--The firmware has the option to increase the motor power when the battery voltage drops, depending on the {{PARAMNAME|Voltage Correction}} percentage. This however adds another variable, and hence should hence be set to zero for now.--> 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.  


=== "High-PWM" Tuning ===
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, the starting value for {{PARAMNAME|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 {{PARAMNAME|Vmax}} set to the maximum value of 255.  
The "high-PWM" tuning strategy starts from the recommendation to set {{GUI|Vmax}}, or motor power or PWM, as large as possible.


The rational in this tuning is that a larger motor power makes the system react faster (allowing in principle a faster correction and hence smaller error angles) and be more robust against disturbances such as cogging torque, frictions, wind gusts and so on.
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 {{PARAMNAME|Vmax}} stronger micro motions of the motor are produced and, depending on the gimbal, the gimbal may more easily develop vibrations.


The upper limit for {{GUI|Vmax}} is mainly determined by the heat produced in the motors. Obviously, the motors should not get too hot. In practical terms, one should be able to touch the motors for several seconds (10 sec or more). The motor heat is however not the only factor which determines the proper {{GUI|Vmax}} value. As with the other parameters, one needs to experiment. It may e.g. happen that with a too large {{GUI|Vmax}} one can't achieve a vibration free, good tuning, and a somewhat lower {{GUI|Vmax}} is much better.
Therefore the advice is to define a useful low {{PARAMNAME|Vmax}} value.  


As regards {{GUI|P}}, {{GUI|I}}, {{GUI|D}}, these two procedures seem to work:
{{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 additionally. Keep all of that in mind when estimating the amount of force the motor should apply to the camera.}}
*'''Procedure A:''' Set {{GUI|I}} to a small value. Increase {{GUI|D}} and {{GUI|P}} alternately, step by step. The gimbal should not start to oscillate. Since it are only two parameters one will quickly find the best balance of large {{GUI|D}} and large {{GUI|P}}. Now turn up the {{GUI|I}} value until the gimbal starts to oscillate, and back off by some 10 %. Finally, experiment with all three values. The general goal should be to get a large {{GUI|I}} value.


*'''Procedure B:''' Set {{GUI|P}} to zero or avery small value, and first adjust {{GUI|I}} and {{GUI|D}}. That is, increase {{GUI|I}} until the gimbal oscillates, then increase {{GUI|D}} to damp the oscillation. Repeat until neither increasing {{GUI|I}} nor {{GUI|D}} stops gimbal oscillations. Now also use {{GUI|P}}, and experiment with all three values until the result is satisfying. The general goal should be to get a large {{GUI|I}} value.
::{{#ev:youtube|wq6e38EWjWE}}


'''''Tip:''' Vibrations or oscillations of the gimbal can be nicely seen in the DataDisplay's accelerometer panel.''
=== The D Parameter ===


== Voltage Correction ==
With {{PARAMNAME|P}} and {{PARAMNAME|I}} set to zero, there is no position correction at all, that is the motor will simply stay in its current position.
The voltage correction mechanism in o323bgc attempts to compensate the effects by a varying battery voltage on the PID controller tuning. It does it by modifying the actual motor power. i.e. {{GUI|Vmax}} values proportionally to the voltage change. The proportionality factor is given by the parameter {{GUI|Voltage Correction}}.


For instance, with a {{GUI|Voltage Correction}} of 100%, a drop in the battery voltage by 25% leads to an increase of the actually used Vmax value by 25%. With a {{GUI|Voltage Correction}} of 50%, a voltage drop by 25% leads to a 12.5% increase in Vmax, and so on.
The {{PARAMNAME|D}}erivative 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 {{PARAMNAME|D}} value is too high, then the frequency of the correction gets visible and/or audible. Therefore, by keeping {{PARAMNAME|P}} and {{PARAMNAME|I}} zero and just increasing {{PARAMNAME|D}}, one can find a point at which an audible high-frequency noise, produced by the gimbal motor, appears. The {{PARAMNAME|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. If a {{PARAMNAME|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.


The mechanism can significantly reduce the dependence of the gimbal performance on the battery voltage. It can however not accomplish what could be achieved with a truly constant (regulated) voltage.
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 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.


== Tuning the Pan Speed ==
Before the video was taken, the following actually happened. 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 vibrations were still present! 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 chosen, 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 smaller D value, at which the vibrations stop.
For the STorM32-BGC the pan (follow) mode is in some ways independent on the PID controller. The PID tuning must thus be done with the pan mode deactivated. However, on the other hand, once the PID controller is tuned, the pan speed can be easily adjusted without having to touch the PID controller any further. This is probably one of the appealing features of the STorM32-BGC. Accordingly, the discussion of the hold and pan modes is deferred to a later chapter.  


== Understanding the Parameters ==
{{COMMENT|In the GUI you can move the slider also using 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.}}


Maybe useful references (from the German FPVC forum):
::{{#ev:youtube|voxJ9IAcaQg}}
* http://fpv-community.de/showthread.php?20795-Brushless-Gimbal-Controller-SOFTWARE&p=382163&viewfull=1#post382163
* http://fpv-community.de/showthread.php?20795-Brushless-Gimbal-Controller-SOFTWARE&p=381584&viewfull=1#post381584
* http://fpv-community.de/showthread.php?20795-Brushless-Gimbal-Controller-SOFTWARE&p=381513&viewfull=1#post381513


== Next step - RC Inputs ==
=== The P Parameter ===


With these settings we have a self leveling gimbal. No matter what movements the gimbal support is undergoing, the camera remains stable. While this might be perfectly sufficient for basic operation, normally the gimbal shall also be moved via a RC stick or, on a hand-held gimbal, via a joystick, or functions such as switching between hold and pan modes or releasing the shutter of the camera remotely are desired.
Before starting the tuning of the {{PARAMNAME|P}}roportional term of the PID controller, set the {{PARAMNAME|I}} parameter to a low value, for instance 5, which is the lowest non-zero value.
 
The {{PARAMNAME|P}} constant is multiplied with the positional error to get the correction amount, exactly as in the example discussed in the introduction. The higher the {{PARAMNAME|P}} factor is the larger the calculated correction will be. If it is too high, then the PID controller will have the tendency to overshoot the target position, and when it is much too high it even produces totally erratic movements. Hence, the goal is to have both a high {{PARAMNAME|P}} value and a smooth movement in all motor positions.
 
The video shows the procedure. After five seconds, {{PARAMNAME|P}} and {{PARAMNAME|I}} are set to non-zero values and the gimbal moves into a level position. Then the {{PARAMNAME|P}} value is increased. Once P = 15 is reached, some weird shakes start to appear when the motor is released from a tilted position, which get worse and worse, and with P = 23 the camera shakes for a while even. Only once the {{PARAMNAME|P}} value is set back to 13 a smooth movement from all positions is achieved again.
 
::{{#ev:youtube|O_FC6S_Lpgs}}
 
=== The I Parameter ===
 
Now the {{PARAMNAME|I}}ntegral term can be adjusted. The goal is, similar to the other parameters, to find the largest possible value without introducing negative side effects.
 
In fact, the {{PARAMNAME|I}} term plays a much more important role for the stabilization accuracy than the {{PARAMNAME|D}} and {{PARAMNAME|P}} parameters. In practical terms this means, that it is more important to set a large {{PARAMNAME|I}} value, or vice versa, that one doesn't loose too much if {{PARAMNAME|D}} and {{PARAMNAME|P}} are not at their highest possible values. So, it is actually not a bad idea to lower {{PARAMNAME|D}} and {{PARAMNAME|P}}, if this increases e.g. the reliability of the PID controller behavior.
 
When you look carefully again at the last few seconds of the previous video, where {{PARAMNAME|I}} was 5, you'll see that the camera could not be kept level when the gimbal was moved. The {{PARAMNAME|I}} term is responsible for this part of the movement.
 
In the video, the {{PARAMNAME|I}} value is initially set to 480. I in comparison to the behavior for I = 5, a perfect movement is now obtained: fast speed, the camera remains horizontal, it truly is horizontal, everything is fine. Maybe one can increase {{PARAMNAME|I}} even further. At I = 700 the same situation, everything looks nice. At I = 1200, however, the camera isn't horizontally aligned, and - if you look carefully at the yellow cable of the IMU connector - you see that it is vibrating (sorry, not very visible in the video). So, I = 1200 is too high for sure. There were slight vibrations in some positions of the camera even at I = 700, so {{PARAMNAME|I}} was set to 620 at the end.
 
::{{#ev:youtube|kGFhd7Q4vgw}}
 
== 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 {{PARAMNAME|Yaw Motor Vmax}} value is higher, or a larger motor is used.
 
You might find that then you tune e.g. the roll axis, that the pitch axis doesn't perform as well as with disabled roll motor. This is common. It is mainly due to imperfect balancing, but it's essentially impossible to avoid. Simply "down-tune" the pitch axis, i.e. reduce the PID values a bit until things are good again. Similar holds obviously when tuning the yaw axis.
 
== Next Step - RC Inputs ==
 
You should have now a self-stabilizing gimbal. No matter what movements the gimbal support is undergoing, the camera remains stable in position.  
 
If so, you may want to set the yaw axis back to pan mode. In the {{GUI|Pan}} tab set the {{PARAMNAME|Yaw Pan}} value to a non-zero value (default is 2.0) and the {{PARAMNAME|Pan Mode Default Setting}} to "hold hold pan".
 
While the current setting 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 a pan deadband are desired.


You can learn about these possibilities in the next chapters; continue with [[Configure the RC Input]].
You can learn about these possibilities in the next chapters; continue with [[Configure the RC Input]].

Latest revision as of 15:47, 21 January 2023

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 is applied, 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 rotate 30° upwards, instead of the desired 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.

Below a relatively simple and straight forward tuning technique is suggested, which often works surprisingly well, and has a theoretical foundation. However, it may also fail. In fact, it is important to realize that some gimbals might not be tunable at all, because of e.g. too weak or too strong motors, too high friction, improper balance, and several other reasons. As a rule of thumb: When you don't get a good tuning within 10 min (per axis) then chances are that something is wrong with the gimbal design. There ain't no such thing as a hard to tune gimbal. There are just well and badly designed gimbals.

Balancing the Gimbal

Before any tuning, the gimbal needs to be balanced. Balancing means to bring the center of gravity (COG) 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 someone points). 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. Otherwise you will get artefacts, such as:

  • 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 minimum 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 very 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 preferred orientation.

Please also consider these tips:

  • It is important to electrically disconnect the motors from the board, since then they can rotate more freely than just being disabled in the GUI.
  • A much 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 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.
DSC 7111.jpg

Tuning Procedure

Comment: T-STorM32 users please refer to the article Getting Started with T-STorM32.

The tuning of one axis might impact the other axis, nevertheless 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 at a low value, increase it until the gimbal starts to misbehave, and lower it until it works again. This will be done first for the D parameter, when the P value, 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, this parameter is relatively easy to adjust and not too critical (unless the gimbal tends to vibrations at certain gimbal positons).

The procedure is illustrated below also by videos.

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 [GUI:Pan] tab the parameters Pitch Pan, Roll Pan and Yaw Pan should be set to zero or alternatively the Pan Mode Default Setting set to “hold hold hold”.
  • Voltage Correction should be set to “0%”.
  • A 2nd IMU should be deactivated, i.e., in the [GUI:Setup] tab the parameter Imu2 Configuration should be set to “off”.
  • The battery should neither be fully charged nor nearly discharged, i.e., have a voltage of about 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, 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 additionally. 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 stay in 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. 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 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 happened. 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 vibrations were still present! 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 chosen, 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 smaller D value, at which the vibrations stop.

Comment: In the GUI you can move the slider also using 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

Before starting the tuning of the Proportional term of the PID controller, set the I parameter to a low value, for instance 5, which is the lowest non-zero value.

The P constant is multiplied with the positional error to get the correction amount, exactly as in the example discussed in the introduction. The higher the P factor is the larger the calculated correction will be. If it is too high, then the PID controller will have the tendency to overshoot the target position, and when it is much too high it even produces totally erratic movements. Hence, the goal is to have both a high P value and a smooth movement in all motor positions.

The video shows the procedure. After five seconds, P and I are set to non-zero values and the gimbal moves into a level position. Then the P value is increased. Once P = 15 is reached, some weird shakes start to appear when the motor is released from a tilted position, which get worse and worse, and with P = 23 the camera shakes for a while even. Only once the P value is set back to 13 a smooth movement from all positions is achieved again.

The I Parameter

Now the Integral term can be adjusted. The goal is, similar to the other parameters, to find the largest possible value without introducing negative side effects.

In fact, the I term plays a much more important role for the stabilization accuracy than the D and P parameters. In practical terms this means, that it is more important to set a large I value, or vice versa, that one doesn't loose too much if D and P are not at their highest possible values. So, it is actually not a bad idea to lower D and P, if this increases e.g. the reliability of the PID controller behavior.

When you look carefully again at the last few seconds of the previous video, where I was 5, you'll see that the camera could not be kept level when the gimbal was moved. The I term is responsible for this part of the movement.

In the video, the I value is initially set to 480. I in comparison to the behavior for I = 5, a perfect movement is now obtained: fast speed, the camera remains horizontal, it truly is horizontal, everything is fine. Maybe one can increase I even further. At I = 700 the same situation, everything looks nice. At I = 1200, however, the camera isn't horizontally aligned, and - if you look carefully at the yellow cable of the IMU connector - you see that it is vibrating (sorry, not very visible in the video). So, I = 1200 is too high for sure. There were slight vibrations in some positions of the camera even at I = 700, so I was 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.

You might find that then you tune e.g. the roll axis, that the pitch axis doesn't perform as well as with disabled roll motor. This is common. It is mainly due to imperfect balancing, but it's essentially impossible to avoid. Simply "down-tune" the pitch axis, i.e. reduce the PID values a bit until things are good again. Similar holds obviously when tuning the yaw axis.

Next Step - RC Inputs

You should have now a self-stabilizing gimbal. No matter what movements the gimbal support is undergoing, the camera remains stable in position.

If so, you may want to set the yaw axis back to pan mode. In the [GUI:Pan] tab set the Yaw Pan value to a non-zero value (default is 2.0) and the Pan Mode Default Setting to "hold hold pan".

While the current setting 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 a pan deadband are desired.

You can learn about these possibilities in the next chapters; continue with Configure the RC Input.