Inverted Pendulum on a Racing Drone
I took this drone and dangled a mass under it with a winch to try to explain the complexity of the perseverance mars rover landing. Some interesting coupling of the two body system made it pretty hard to fly without active compensation in the control system, and i basically left it at that. A lot of people wanted to see my attempt at stabilizing this system, but i wanted to take a step further and go straight for the inverted pendulum case, so lets figure out how to do that. Music. Before we get my drone to balance the pendulum, we first need to understand what goes into balancing an inverted pendulum in the first place. You probably already know that its harder to balance a shorter rod compared to a longer rod. This is because the longer rod has higher moment of inertia, which can be thought of as a sort of rotational mass. A higher rotational mass makes the system less sensitive to inputs, meaning my finger movements dont have to be as precise or quick to keep it balanced. Adding more weight to the top further increases the moment of inertia and makes it even easier, though easy as a relative term. Here anyways my finger is exerting a force on the end of the rod to keep it stable, so we need a way to interface. The rod with the top of my drone, so it can do the same. My thought is to use some joysticks from an old transmitter to serve as a pivot point for the pendulum to attach to, and i can use the potentiometers in the joysticks to measure the relative angle for my control algorithm later, of course, im removing the spring so That the joysticks are free to move around and dont center themselves.
I think that would be considered cheating. I 3d printed a little mount to glue to the joystick and mount to the drone and then soldered up the potentiometers to the analog inputs on my teensy flight controller im running my own custom flight controller code, dreamflight, which runs on the teensy microcontroller on board. The drone and the beauty of that is its basically just a glorified arduino project so reading in these analog potentiometer values directly into the flight control code and then integrating the pendulum stabilization was a piece of cake i needed to scale the analog readings to make them Correspond to joystick angles, and then i added it to the measured drone angle so that no matter what orientation the drone is, zero degrees for the joystick measurement is pointing more or less straight up. The classic inverted pendulum on a cart problem. Stabilizes, the pendulum by horizontally, accelerating the cart to exert a corrective control torque on the pendulum. The actual acceleration needed is computed from the angle the pendulum makes from vertical. So a larger angle requires a larger acceleration to bring it back to level on a drone. We cant just horizontally, accelerate without first pitching the drone over, but we can assume that the horizontal force component from the propellers is proportional to the horizontal acceleration so, instead of commanding an acceleration to stabilize the pendulum, my controller is actually commanding a drone angle, but its Effectively the same, we can take it a step further and specify the desired angle.
We want the pendulum to track. I map this desired pendulum angle to my radio transmitter input, so i can use the pendulum angle to control the position of the drone. All right, i have no idea if this is going to work, but were going to give tuning my controller a shot here with this really long rod with a bit of mass attached to the end, just to give us the best chance of making this work. I had a few more videos of me trying to tune the controller, but unfortunately this was the only one that didnt get randomly corrupted, but all the attempts looked like this anyways Music kind of had a feeling. This wouldnt be that easy, so uh back to the drawing board im measuring the pendulum angle, from both the drones angle and the joystick angle and theres some error in both of those measurements, so their combined error is giving me basically unusable garbage for this use case. I thought i could get away with this approach, but what i really needed to do was just use a separate imu to directly measure the pendulum angle. Independent from the drones angle. Ill still use the joystick as my pivot point, but it wont do any of the measuring anymore. Remember: kids, dont, take shortcuts, or else youll probably end up doing it. The long way when the shortcut doesnt work, all right were going to try for take two now with the imu much more accurate angle.
Readings of the pendulum and ive also got a shorter stick, because i have a good feeling. This might work so lets give it a shot Music. Oh my god, its working wow its kind of working its kind of hard to fly. I nearly need to tune it better, but uh yeah lets do that. Look at that im, not cheating. I swear. It only took a little bit of tuning to get it flying reasonably well, and i can essentially control the position of the drone just through changing the desired pendulum angle and im doing that part manually through my radio. The pendulum controller itself is just managing the pendulum angle and its pretty good at rejecting disturbances. As you can see, im sure i could tune it a little better, but i was pretty happy to even work this well and i didnt want to waste too much time. Perfecting it its clearly not perfect, but thats, okay, Music. I definitely meant to do that perfect landing. All right. Peter thinks he can uh balance longer than a robot uh, and i know for a fact that peters not better than a robot, so lets put it to the test. Three go! Oh! No! Oh no! Oh god! Oh god! Oh god! Oh god! Oh god, all right! All right, i see how it is: okay, okay, okay, Music, okay, im using my oh, and just like that. My scrappy code beats peter, so that was a fun little demonstration, but you know exactly what im going to say.
Next, you know we have to do a power loop now that we we have to do it uh the controller its whats called its its linearized about the vertical position of the pendulum. So thats basically fancy talk for it. It dont work if the pendulum is not like, plus or minus 40 degrees from vertical. So what im gon na have to do is im gon na get it going and then im gon na flip it out of pendulum mode and into acro mode im gon na try and do like a power loop just the way. I would normally do it and then hopefully, at the bottom of the power loop, the pendulum is kind of vertical and then ill switch. The pendulum stabilization back on it probably wont work, but itll be fun to try so lets. Do it Music? Oh my god. Oh no power loop, oh it did a loop. I got to work on that beta flight tune all right. So what happened? I was flying along in pendulum mode, trying to keep up some speed and you can pretty much see the instant i flipped it into acro mode out of the pendulum stabilization. The pendulum just flops over and starts causing chaos in the air. At some point, i remember trying to turn the pendulum stabilization back on to regain some control, but i think the pendulum actually broke a prop in the air, so it was already a lost cause.
There cant say im surprised at the outcome, but also cant, say: im, disappointed, im, really happy with how this project turned out and its a great demonstration of how more advanced control algorithms can make drones do pretty interesting. Things definitely check out my previous video on the mars rover sky crane, because that was the initial inspiration for this project. If you have any ideas for projects youd like to see me tackle in the future, let me know in the comments and make sure to subscribe. So you dont miss the exciting new projects.