Thrust control law for improved vertical stability and hover

Firmware/software/electronics/mechanics
Post Reply
donpepe
Beginner
Posts: 4
Joined: Wed Aug 07, 2013 9:25 am
Location: France

Thrust control law for improved vertical stability and hover

Post by donpepe »

My ability with my PS3-like controller is quite poor (I admit not being a gamer). The analog controls are dreadful: the dead band around neutral is way too large, the controls saturate half way up to the maximum (or minimum) and the effective range for controlling the thrust is tiny. On top of that, the controls are spring-loaded so as to return to zero in the absence of force.

Because of the controller limitations, I find the crazyflie thrust control very difficult with regards to vertical stability: small inputs put the copter in orbit and, as soon as I release the force... say 'hello' to the earth again! Besides, the spring-loaded controls means that you have to maintain a constant force very precisely if you want to get a constant thrust. The ability to maintain a near-constant thrust is a key requirement for hovering. In fact, the interest for a hover mode in the forum probably indicates that other crazyflie pilots are enduring the same frustrations than me.

I am also very interested in the development of a hover mode. However, a little modification in the "thrust control law" might significantly improve the vertical stability. My thrust control law (implemented in PC-client input.py) is the following:
  • The joystick lever angle commands a "rate of change" for thrust.
  • Lever forward increases thrust and lever backward decreases it.
  • The rate of increase/decrease is proportional to the lever angle.
  • Lever at zero (the spring-loaded neutral) commands "no thrust change".
If the thrust is well trimmed with the lever at neutral, the crazyflie hovers (or, at least, the vertical control is improved). The crazyflie is much more stable and my piloting technique has improved: many less impacts on the ceiling and now I am able to land on one square meter of land ;-)

I'd love to have your opinion on this hack and your ideas for improvement. You may find it in my repository
SuperRoach
Member
Posts: 96
Joined: Fri May 03, 2013 2:06 pm

Re: Thrust control law for improved vertical stability and h

Post by SuperRoach »

Very interesting take on throttle control, I'll be interested to try it out when I get home - thanks for the write up about it!
molecular
Beginner
Posts: 3
Joined: Mon Aug 19, 2013 12:21 pm

Re: Thrust control law for improved vertical stability and h

Post by molecular »

The joystick lever angle commands a "rate of change" for thrust.
Lever forward increases thrust and lever backward decreases it.
The rate of increase/decrease is proportional to the lever angle.
Lever at zero (the spring-loaded neutral) commands "no thrust change".
That's pretty much what I did (by modifying input.py, here's pastebin: http://pastebin.com/08gmYCQr)

here's the most relevant part:

Code: Select all

if self.relativeThrust:
              self.thrust += raw_thrust * 0.015;
              
              if self.thrust < 0: self.thrust = 0.0
              if self.thrust > 1: self.thrust = 1.0
                
              thrust = self.thrust * 65535;
              if thrust > self.maxThrust: thrust = self.maxThrust
This approach has a few problems: Most importantly it's still very hard and time-consuming to achieve good hoover (stable altitude) and it still keeps me from having enough time for positional controls (mind overwhelmed). So one of the main problems I have (maintaining altitude while flying around simulatneously) is still unsolved. Another problem is that I tend to crash harder.

One problem is solved, though: I can actually use the yaw control (I have it together with throttle on one stick) without totally screwing up throttle, since I don't have to hold throttle in a certain position but can keep it at center for at least short periods of time.

I'm going to try to play with the bolded part and make the throttle change depend non-linearly on the throttle input (raw_throttle). Why? Because when fine-tuning hoover you need miniscule adjustments and when taking off or "emergency-landing", you need quite fast adjustments. Thinking to use:

I currently have:

Code: Select all

self.thrust += raw_thrust * 0.015;
and will try:

Code: Select all

self.thrust += pow(raw_thrust, <exponent>) * <some factor>;
with <exponent> something between 1 and 3 or so.

But first I'll have to fix my crazyflie (motor holder broke)
donpepe
Beginner
Posts: 4
Joined: Wed Aug 07, 2013 9:25 am
Location: France

Re: Thrust control law for improved vertical stability and h

Post by donpepe »

Funny to see that my crazyflie is not the only one being severely tortured: I hope your crazyflie gets well soon!

Here is my solution so far: http://pastebin.com/4U8TJv6b (only the most relevant lines)

I have chosen a linear law instead of a polynomial (or exponential) one because humans are more comfortable with it. However, there are 2 different slopes:

- "fine tuning" mode. Lever close to the neutral: the slope is shallow. Thrust changes are small. I manage to adjust the altitude relatively well.

- "oh-my-god-here-comes-the-ground-again" mode: Lever close to the limits: the slope is steep. Thust changes are significant, allowing an easy takeoff and ceiling-avoidance maneouvers.

The kill switch has been my friend during most of my emergency landings: you really want to cut the thrust off once you are on the ground in an awkward attitude. But I guess that the right way to solve this is to have a "crash detection" function that resets thrust to 0: any idea how to do this?

Another consideration: if I forget to reduce thrust to 0 upon radion link failure, the motors jump up to the selected thrust as soon as the copter is reconnected: crazyflie in orbit again! I still have no code for resetting the thrust upon crazyflie connection, but perhaps that is not very difficult.
legalnonsense
Beginner
Posts: 9
Joined: Sun Jul 21, 2013 5:30 pm

Re: Thrust control law for improved vertical stability and h

Post by legalnonsense »

What about setting a shoulder button to lock the current throttle, and while that button is depressed the thrust control analog only increases or decreases the current thrust for fine tuning. Once the button is released, throttle control returns to normal (perhaps with a slight delay to avoid it zeroing out immediately). This would allow the pilot to find a thrust close to hovering, lock it, and fine tune without removing the ability to make quick changes.
molecular
Beginner
Posts: 3
Joined: Mon Aug 19, 2013 12:21 pm

Re: Thrust control law for improved vertical stability and h

Post by molecular »

legalnonsense wrote:What about setting a shoulder button to lock the current throttle, and while that button is depressed the thrust control analog only increases or decreases the current thrust for fine tuning. Once the button is released, throttle control returns to normal (perhaps with a slight delay to avoid it zeroing out immediately). This would allow the pilot to find a thrust close to hovering, lock it, and fine tune without removing the ability to make quick changes.
Not a bad idea. After "releasing" the button (I would prefer it to exhibit toggle behaviour so it doesn't have to be pressed all the time), the "hold value" could be gradually faded over into the absolute raw_thrust value to avoid all-too-sudden change (you have to find the correct throttle value at that point).

But fist I'll try to check out hover-mode: http://forum.bitcraze.se/viewtopic.php?f=6&t=273 (didn't have much success on first try).
SuperRoach
Member
Posts: 96
Joined: Fri May 03, 2013 2:06 pm

Re: Thrust control law for improved vertical stability and h

Post by SuperRoach »

The trigger to lock throttle seems like a great way to get a usable yaw with practice - it would likely only be slowly shifting up or down while doing it.
In practice it will likely be shifting down as the center of mass is moved though.
donpepe
Beginner
Posts: 4
Joined: Wed Aug 07, 2013 9:25 am
Location: France

Re: Thrust control law for improved vertical stability and h

Post by donpepe »

The "trigger to lock thrust" looks a good idea. From a certain point of view it is a kind of "thrust trim" (another possible implementation could be 2 shoulder buttons -trim up and down-). But yet I am not sure that it solves my initial concern.

Let me call TFH to the "thrust necessary for hovering": the thrust at which, if the copter was initially hovering, it remains hovering. In other words, TFH = copter weight, and when thrust equals TFH, the vertical acceleration is zero.

Once you fly stabilised (your current thrust being roughly equal to THF) it is an excellent idea to lock that thrust and use the thrust lever for fine-tuning. However, due to the limitations of my joystick, or me as a pilot, I am not precise enough so as to reach the THF in stabilized flight: I will never have the opportunity of engaging the lock-thrust toggle!

The bottom line is that you need a very sensitive thrust control most of the time but, from time to time, you want to recover an aggressive (and full range) thrust control for certain maneovers: takeoff, ceiling/floor avoidance, shutdown after landing/crash, orbital launch...

I have posted in youtube (http://www.youtube.com/watch?v=13Wn4Z-NMkM) a short film displaying the crazyflie flying with the modified thrust control law. Although the sound is poor, you may notice that the engine noise remains quite stable (that is a good sign!). By the end of the film there is also a little display of flying on aerodynamic ground effect: the thrust setting is just slighly below TFH so the copter descends and meets the ground effect, where it needs less thrust to fly: TFH is lower and, as thrust did not change, now it is enough to keep the copter hovering some centimeters above the ground: amazing!
legalnonsense
Beginner
Posts: 9
Joined: Sun Jul 21, 2013 5:30 pm

Re: Thrust control law for improved vertical stability and h

Post by legalnonsense »

donpepe wrote:Once you fly stabilised (your current thrust being roughly equal to THF) it is an excellent idea to lock that thrust and use the thrust lever for fine-tuning. However, due to the limitations of my joystick, or me as a pilot, I am not precise enough so as to reach the THF in stabilized flight: I will never have the opportunity of engaging the lock-thrust toggle!
To this point, which I know is minor, I've found it helpful to set the thrust at about 35 and 75, which gives you much greater control over the amount of trust. I can actually hover in place pretty reliably. I am sure there are more ideal numbers.

I've been looking at your repository but I am not a programmer and it takes me a long time to hack through code so I am still trying to get a general orientation on everything. I remember I told my wife my idea for a better control scheme a few days ago and then I saw your post and both sadly and happily announced someone had already already done most of it.
donpepe
Beginner
Posts: 4
Joined: Wed Aug 07, 2013 9:25 am
Location: France

Re: Thrust control law for improved vertical stability and h

Post by donpepe »

legalnonsense wrote: I've found it helpful to set the thrust at about 35 and 75, which gives you much greater control over the amount of trust. I can actually hover in place pretty reliably. I am sure there are more ideal numbers.
Thank you for your hint on the thrust range. I just have flight-tested it with the original thrust control law and you are right: the copter is more stable. With its current weight, it does not need more than 75% thrust to climb at an acceptable rate. Let me know if I can be of any help when trying my code. I am not a programmer either, so it is taking some time to get used to the crazyflie programming environment yet.

I have been thinking these days about additional hacks to the flight control laws (not only for thrust). I have noticed that the copter control laws are kind of "direct": when you select a thrust through the joystick, the command is sent to the copter as-is. It might be possible to modulate that command as a function of the current status of the copter (by status I mean the current flight parameters: speed, altitude, acceleration, etc). A trivial example is the following: preventing sending thrust-increase commands if the copter has crashed. Less trivial examples could be an automatic thrust-increase when you command high bank or pitch, to compensate for the lift loss due to copter attitude (in other words, maintain altitude when in turn, for example).

But I am still on the code exploration phase. I have just receive my busblaster and I am willing to start hacking into the firmware. I am looking for help and/or ideas, by the way!
Post Reply