Tuning crazyflie for smooth, stable and responsive flight

Firmware/software/electronics/mechanics
hittstick
Beginner
Posts: 27
Joined: Thu Apr 06, 2017 7:26 am

Re: Tuning crazyflie for smooth, stable and responsive flight

Post by hittstick » Fri May 05, 2017 7:08 pm

So, just to be clear, if we want to modify the PID values based on our own preferences, can we just adjust the values in this file:

~/projects/crazyflie-firmware/src/modules/interface/pid.h

...and flash the firmware again?

I feel as though my yaw rate is extremely slow, even in advanced mode.



arnaud
Bitcraze
Posts: 2134
Joined: Tue Feb 06, 2007 12:36 pm

Re: Tuning crazyflie for smooth, stable and responsive flight

Post by arnaud » Mon May 08, 2017 10:23 am

Yes if you want the new values to stay between reboot you can modify the pid.h file. If you want to test values you can connect your Crazyflie with the client and modify the parameters, the new values will be applied directly but lost at reboot.

hittstick
Beginner
Posts: 27
Joined: Thu Apr 06, 2017 7:26 am

Re: Tuning crazyflie for smooth, stable and responsive flight

Post by hittstick » Tue May 09, 2017 3:57 am

Thanks @arnaud

My crazyflie has a tendency to flip over when I mix yaw with pitch, any ideas that can correct this behavior?

Also, is advanced mode = rate mode = acro mode? This has been a bit confusing...

theseankelly
Expert
Posts: 153
Joined: Mon Dec 28, 2015 3:23 pm
Contact:

Re: Tuning crazyflie for smooth, stable and responsive flight

Post by theseankelly » Tue May 09, 2017 4:35 am

Hey -- how hard do you have to push yaw & pitch to get the flip to happen? Are you flying indoors or outside?

"advanced mode" in the python UI means the advanced features in the pane below are unlocked -- things like the ability to increase max angle setpoints. The copter will still be in level mode.

You can enable acro mode in two ways:
1) There are parameters for the roll and pitch PID mode (RATE and ANGLE where rate == acro and angle == level). This doesn't persist across a reboot.
2) You can modify the source crtp_commander_rpyt.c, line 70 and 71 (https://github.com/bitcraze/crazyflie-f ... rpyt.c#L70) to change the default and rebuild

If you're interested in flying acro I suggest checking out a devo Tx running deviation -- I recently added a commander protocol that can transmit up to 14 channels and made one of them map to switching between acro and level, and added support for this in the deviation code. Which reminds me: I need to write a wiki on that...
http://www.thejumperwire.com
Tips, tutorials, and science about DIY electronics, drones, and embedded software.

hittstick
Beginner
Posts: 27
Joined: Thu Apr 06, 2017 7:26 am

Re: Tuning crazyflie for smooth, stable and responsive flight

Post by hittstick » Fri May 12, 2017 6:07 pm

theseankelly wrote:Hey -- how hard do you have to push yaw & pitch to get the flip to happen? Are you flying indoors or outside?

"advanced mode" in the python UI means the advanced features in the pane below are unlocked -- things like the ability to increase max angle setpoints. The copter will still be in level mode.

You can enable acro mode in two ways:
1) There are parameters for the roll and pitch PID mode (RATE and ANGLE where rate == acro and angle == level). This doesn't persist across a reboot.
2) You can modify the source crtp_commander_rpyt.c, line 70 and 71 (https://github.com/bitcraze/crazyflie-f ... rpyt.c#L70) to change the default and rebuild

If you're interested in flying acro I suggest checking out a devo Tx running deviation -- I recently added a commander protocol that can transmit up to 14 channels and made one of them map to switching between acro and level, and added support for this in the deviation code. Which reminds me: I need to write a wiki on that...
Looks like I have some more saving to do. Which Devo transmitter are you using, specifically, @theseankelly? Did you need to implement a receiver as well or can it connect to the signal from the stock antenna?

All of my flying has been indoors, so far. The flip happens when I try to perform an orbit and start speeding up, and also when I attempt to change direction quickly. When I can I'll try to get some video uploaded to better illustrate this.

For the first method for non-persistant acro mode, are you changing those values from within the client?

I definitely see the benefit to a controller where the thrust stick doesn't snap back to center.

Thanks a lot for the information!

theseankelly
Expert
Posts: 153
Joined: Mon Dec 28, 2015 3:23 pm
Contact:

Re: Tuning crazyflie for smooth, stable and responsive flight

Post by theseankelly » Sun May 14, 2017 11:19 pm

Hey hittstick -- yes, a transmitter with proper gimbals/sticks will make a huge improvement. I was shocked how much better I could fly when I first moved to a real Tx (the crazyflie was my intro to the hobby -- had zero RC experience prior). I started out on the Devo7e, which does a good job for the price. I'm now on the Devo10 (the white one) and I strongly recommend it. I think the Devo 7e is fine for flying the crazyflie nano around in level mode, but you'll quickly outgrow it if you want to fly a larger quad due to range of the stock transmitter (if you're using spektrum or other external receivers) and precision of the sticks. I personally wish I didn't waste my money on the 7e and just saved longer for the 10 (It's like $120 instead of $60).

Either way, to fly untethered, you do need a transmitter mod. Tobias has a post on the mod -- it's not a very hard modification. You're basically soldering the radio used on the crazyradioPA to the SPI pins inside the devo. Make sure you get a NRF42L01PA+ (pa stands for power amp) radio with an external antenna -- the PCB antennas are junk. The ceramic antenna will be a bit better, but not as good as the external dipole (and I even managed to fit the dipole wifi-style antenna inside my devo7e by taking the plastic cover off and getting creative. On my devo10, I mounted it externally).

You also have the option of flying tethered to a computer via USB -- most transmitters (devo, FrSky Taranis, Spektrum) also support a mode where they'll enumerate as a USB controller, and you can configure the crazyflie python client to use those. You still need to lug the computer around, but you'll get the better stick precision.

Yes, for the non-persistant acro mode, I'm changing the values from within the client. It's good for playing around with, but it's ultimately a bit of a pain. I did recently implement a "cppm passthrough" commander type that emulates a standard multi-channel transmitter, and I decided channel 5 to switching between rate/level mode. I only implemented the transmitter side in the devo firmware, though. You could totally implement that in the python client and map a button on your controller to toggle modes if you're feeling adventurous :)

Would love to see that video. I've experienced something similar when flying in crosswinds. I haven't nailed it down yet but I suspect it's due to one of a few things:
1) accel code not filtering out external forces and overcompensating for things like wind
2) IMU loop isn't tightly synchronized to the motor output -- this can easily lead to oscillations, but I'm not positive it would be bad enough to cause an all-out flip.
3) PID values aren't good -- I suspect this is the problem, specifically, I think the 'd' term on the rate PID is to blame. I added it to eliminate some oscillations from the 'i' term, but I was always worried it was too high. Theoretically, it could slow the PID down significantly on rapid changes like a change-in-direction, which would cause destabilization of the system like you, I, and others have seen.

I took a brief detour into the betaflight/cleanflight world because I was curious how the hardware performs on the 'state of the art' flight controller software -- I wanted to rule hardware out (is the copter too heavy? are the motors/props strong enough?) before spending a ton of time tuning/optimizing the software. Turns out the hardware flies great on betaflight, so I'm going to start looking in to improving the things I've mentioned in this post hopefully in the next couple of weeks!
http://www.thejumperwire.com
Tips, tutorials, and science about DIY electronics, drones, and embedded software.

hittstick
Beginner
Posts: 27
Joined: Thu Apr 06, 2017 7:26 am

Re: Tuning crazyflie for smooth, stable and responsive flight

Post by hittstick » Fri Jun 23, 2017 11:21 pm

@theseankelly When you say to change lines 70 and 71 and rebuild, what exactly do you mean? I changed the values and reflashed the firmware, but I have a funny feeling I'm being a silly goose about this and that I need to recompile something, I'm just not sure exactly how to go about it :/

Thanks in advance for any sage advice you bestow!

theseankelly
Expert
Posts: 153
Joined: Mon Dec 28, 2015 3:23 pm
Contact:

Re: Tuning crazyflie for smooth, stable and responsive flight

Post by theseankelly » Fri Jul 07, 2017 4:25 am

hittstick wrote:@theseankelly When you say to change lines 70 and 71 and rebuild, what exactly do you mean? I changed the values and reflashed the firmware, but I have a funny feeling I'm being a silly goose about this and that I need to recompile something, I'm just not sure exactly how to go about it :/

Thanks in advance for any sage advice you bestow!
Sorry for the delay! Yeah, you need to recompile after changing the source. Check out this wiki page for how to use the VM and eclipse to build and flash. Or better yet, the README.md found on GitHub.
http://www.thejumperwire.com
Tips, tutorials, and science about DIY electronics, drones, and embedded software.

theseankelly
Expert
Posts: 153
Joined: Mon Dec 28, 2015 3:23 pm
Contact:

Re: Tuning crazyflie for smooth, stable and responsive flight

Post by theseankelly » Fri Jul 07, 2017 4:33 am

I haven't done a whole lot with this effort in a while now -- I got a bit sidetracked getting betaflight and cleanflight running on the quad, and then some other life stuff took up most of my time for a while. But I'm back now, and ready to dive back in to improving performance and stability.

I'm going to first focus on E2E latency between the IMU and the motor output, since the more that can be minmized, the tighter the PID loop can be tuned. I took a first pass at measuring the latency between when the IMU data is read over I2C to when the motor outputs are set. The results are interesting:
IMU_Latency_Before.PNG
I think that the spikes and the non-constant latency would produce some weird behavior out of the PID loop, and should be addressed before attempting to reduce overall latency. In other words, I think a constant, higher latency is better than a fluctuating lower latency.

I believe the constant downward trend from 2ms to 1ms is due to the fact that the sensors loop is not directly synchronized to the stabilizer loop, and they drift over time.

I suspect the high spikes are a pre-emption thing -- for example, the task priorities for the stabilizer and sensors tasks are both set to 4, but the syslink task is set to 5. That means syslink data can pre-empt the stabilization of the crazyflie.

I'll try out some changes to test these ideas and report back!
http://www.thejumperwire.com
Tips, tutorials, and science about DIY electronics, drones, and embedded software.

tobias
Bitcraze
Posts: 1911
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Tuning crazyflie for smooth, stable and responsive flight

Post by tobias » Fri Jul 07, 2017 7:55 am

That is not good for stabilization at all, good find!

The intent has always been to have the stabilizer the highest priority but I found this commit which increases the syslink prio. To fix the issue I think we need to implement DMA for the syslink uart rx. I will add a github ticket for that.

Post Reply