tobias wrote:Hi Ian!
This is what we eventually want to do and we have done some brief testing. The problem flying in rate mode is that the gamepad sensitivity needs to be changed and preferable to a none linear response. This could be done in the client.
The rate mode setting is located in the
commander.c and is currently hard-coded.
Adding a parameter as a setting would be a first easy step to configure it on the fly.
Thanks heaps Tobias for your response!!!
Response 1: Mode Switcher
I have editted commander.c so that I just need to change one definition to switch between rate and attitude mode:
Code: Select all
if (!flightType) {
*rollType = RATE;
*yawType = RATE;
}
else {
*rollType = ANGLE;
*pitchType = ANGLE;
}
Rate = 0, Attitude = 1.
I don't think we have to modify the client since the mode is hard-coded anyway. I will work on some code to switch this on-the-fly using the client once i finish my assignments.
Response 2: PID Tuning
To do PID Tuning, I made a simple rig. Basically, just attach two strings on into the holes in the corner of the CF, and then attached that thread to two steady posts. I have attached a photo for reference.
Why do the tuning? Every CF will be slightly different. While out of the box it does fly very well, I noticed that I lacked a lot of control (partly because I am a n00b flyer

). The CF was slow to react and stabilisation could definitely have improved.
This also allows me to fly in both Rate and Attitude mode very well!

Note that I fly in X-Mode, so make sure your PC Client has "Client X-mode" enabled!
So to actually do the tuning, we need to isolate the Rate and Attitude mode.
First, here are the default values in case you ever lose or want to revert:
Axis Mode: [KP, KI, KD, iLimit]
Pitch Rate: [70.0, 0.0, 0.0, 100.0]
Roll Rate: [70.0, 0.0, 0.0, 100.0]
Yaw Rate: [50.0, 25.0, 0.0, 500.0]
Pitch Attitude: [3.5, 2.0, 0.0, 20.0]
Roll Attitude: [3.5, 2.0, 0.0, 20.0]
Yaw Attitude: [0.0, 0.0, 0.0, 360.0]
To PID tune Rate:
1. Tune the Rate mode first. This will mean hard-coding the firmware to make sure roll and pitch input are RATE.
2. In the code (pid.h), set KP, KI and KD to 0.0 for all the roll, pitch and yaw ATTITUDE. We only want Rate. (
PID_PITCH_KP etc)
3. In the same code (pid.h) set KI and KD to 0.0 for all roll, pitch and yaw for RATE. We only want to tune the proportional gain first. (
PID_PITCH_RATE_KP etc)
4. Flash this to the Crazyflie.
5. Now is the fun part. Load the client, and connect to the CF normally. Under View, go to Tabs, then choose Parameters. You can view your current PID settings here, and also update them live!!! I love that feature so much. Just remember that if you turn your CF off, then values set in the client are not saved.

6. Make sure your CF is secured to your rig. PID tuning will get
VIOLENT because we want to find the gain limits!!!
7. To tune the KP for roll, pitch and yaw, gradually increase roll and pitch KP until you notice oscillations. This means that the CF is overshooting lots and has reached instability. Physically, the CF will wobble a lot and rock around.
8. Once you reach the point of instability, tune it down 5-10 points. That shall be your proportional gain. You can repeat the same process for yaw as well.
9. Now we will tune KI. Tuning KI will allow your CF to hold an angle better because naturally with KP only, the CF will have a tendency to revert back to zero-attitude due to gravity/wind effects etc. From experience with tuning KK2.0 etc, a good start is to set KI to half of KP, and work your way up and down from there.
10. When KI causes instability, the CF will wobble and rock around, but on a lower frequency compared to KP instability. This is your critical KI, and so tune down 5-10 points.
11. Repeat for Yaw axis, except KI is usually around 80%+ of KP.
12. Note down all these values, and hard-code it into the pid.h.
Once this is done, pat yourself on the back!

Rate mode successfully tuned. Have a quick flying session to see how it goes.
NOTE: If you notice that your remote is not providing enough input to the CF, change the client to Advanced mode, and set a higher "Max angle/rate". I have mine at 200, and it is beautiful. Each person's control and settings will be different, so please be careful! Increase the max rate in the client slowly!
To PID tune Attitude:
1. First tune Rate.
2. Now head back into commander.c and change back to ANGLE type. That is, set the CF back into attitude mode.
3. In pid.h, change KI and KD for roll and pitch to 0.0 for ATTITUDE. Also, make sure all attitude KP KI KD for Yaw is 0.0 (
PID_PITCH_KP etc)
4. Flash this to the CF and then load up the client again to begin tuning.
5. Again, please make sure the CF is securely attached to your rig.
6. Start by having the KP for roll and pitch attitude at 3.5. Look for any instability such as oscillations. Keep increasing KP until you hit the limit.
7. If you find that KP is causes the CF to be unstable for anything higher than 4, consider slightly lowering the RATE KP and KI by 5-10 points. This allows you a bit more "freedom" with tuning attitude mode.
8. To tune the KI, again slowly increase KI for roll and pitch attitude. Instability again is the low-frequency oscillations.
In perfect tuning, the CF will level itself quickly, respond quickly, and will not wobble/oscillate. You may tolerate a tiny bit of oscillation, but that can quickly lead to flying disaster. Just personal preference here tbh.
Once done, hard-code the values and be proud! Your CF should be much easier to control and is much easier to fly now.
Here are my settings as a reference if anyone is interested:
Rate:
Pitch: [110.0, 50.0, 0.0, 100.0]
Roll: [110.0, 50,0, 0.0, 100.0]
Yaw: [100.0, 90.0, 0.0, 200.0]
Attitude:
Pitch: [3.5, 1.5, 0.0, 20.0]
Roll: [3.5, 1.5, 0.0, 20.0]
Yaw: [0.0, 0.0, 0.0, 360.0]
PC Client:
Flight mode: Advanced
Roll trim: 0
Pitch trim: 0
Client X-Mode enabled
When in Rate mode:
Max angle/rate: 200
May Yaw angle/rate: 200
Max thrust: 90.0
Min thrust: 0.00
SlewLimit: 50
Thrust lowering slew rate: 35
When in Attitude mode:
Max angle/rate: 60
May Yaw angle/rate: 200
Max thrust: 90.0
Min thrust: 0.00
SlewLimit: 50
Thrust lowering slew rate: 35
Sorry for the long post.

I just love the CF so much that I want everyone to be able to take full advantage of every feature the CF has to offer <3