Trimming your Drone

Each drone is built a little differently. Due to differences in the weight distribution and other factors, the drone will tend to initially drift in a particular direction.

Problem 1: Preload the Throttle

First tune throttle_low.init_i in pid_class.py. This is the initial value of the I term for the throttle, which controls altitude. The default value is 100. What happens when you set it to 50? What happens when you set it to 150? Describe the drone’s behavior in each case.

Problem 2: Trim

Next you will set the trim on roll and pitch. When flying the drone over a textured surface, observe what happens. Does the drone stay still or move? How much does it move, qualitatively?

Repeat this experiment five times. Each time make sure that you

  • Place the battery in the same place each time as much as possible so the weight is distributed the same.
  • Tape or velcro the battery so it does not move.
  • Plug the flight controller while the struts are fully engaged and the drone is level, so the gyros are well calibrated.
  • Calibrate the accellerometer.

Our controller is a dual I term PID controller. The high-rate I term changes quickly, allowing fast response to changes. The low-rate I term changes slowly, allowing the drone to adjust to systemic sources of error such as poor weight distribution or a damaged propeller. In the next part of the course we will go into more detail with this structure. For now we are just asking you to be responsible for the intuition.

  1. Name a source of static error that the low-rate I term can correct for.
  2. Name two sources of dynamic error that the high-rate I term can. correct for.

Problem 3: Set the Trim

First change pid_class.py to print out roll_low._i, roll._i, pitch_low._i and pitch._i. Note that you may need to repeat this process periodically, for example after a crash or the like. Always place the drone so that the camera is closer to you and the skyline is farther away. Then roll controls sideways movement. Pitch controls forward and backward movement.

Make sure the battery is secured with velcro and placed in the same position to control for weight distribution.

Next perform one flight. After the drone takes off, do not give it movement commands but allow it to drift. (Don’t allow it to hit anything though! You might have to kill or take over if it drifts a lot.)

  1. Which way does it drift? How much does it drift? (Or in other words, how long could you stay within a square meter of where you started?)
  2. What are the low frequency I terms for roll and pitch after your flight? Where they moving up or down?

  3. At the end of the flight, the low rate I terms will have moved. Set `self.roll_low._i` `self.pitch_low._i` to the values that you reached and repeat the process until you converge. Note that differences in the battery placement will cause enough change in the weight distribution to need very different initial values. You might need three or four flights until you converge. Typical values range between -10 and 10.

  4. Which way does it drift? How much does it drift? (Or in other words, how long could you stay within a square meter of where you started?)
  5. Once you have good values, try changing them to see if you can inject drift. What values make it move forwards (when velocity is zero?). What values make it move backwards?

Problem 4: Position Control

Once you have achieved good trim, you can try position control. Try to fly your drone for an entire battery without touching the controls! Do not try this until your I term preloads have been tuned as described above.

This video demonstrates the drone doing a zero velocity hover and drifting in the scene. Then we turn on position hold (you can tell because it drops the throttle as it takes over, and holds its position for several minutes.

Then we turn off the positon hold so you can see it drift again, and then turn it on again at the end and land. You can tell when it is turned on because we move the drone back to the center of the flight area before each hold.

Engage position control in two steps. First you have to tell the drone to “remember” a frame. You can do this using the “r” key. This will save the frame at the drone’s current location. Next you have to engage or disengage position control. You can toggle this mode with the “p” key. So the procedure is to first save a frame (target location for the position hold) using “r” and then shortly after (before drifting too much) type “p”.

Position hold works best over a textured surface with lots of visual contrast. Even when doing position hold, always be ready to kill in case of a mishap. Especially be careful when looking at other windows

  • be prepared to quickly tab back to the Javascript interface and kill the drone.
  1. Engage position hold using the procedure decribed above. Observe the drone's behavior. How is it different from velocity mode?
  2. How long are you able to hold position? Ideally you should be able to do this in one spot for an entire battery. If not, try retuning your I term preloads above.
  3. Look in the vision tab in the screen. You should see it printing max_first_counter (and some other stuff). Pay attention to max_first_counter and observe whether/when it is seeing the first frame. Lower is better! Typical values are around 100, but a very good run might be 30 or 40 frames. Report your best times!
  4. Turn off position hold with "p" and observe how the drone's behavior changes with position vs. velocity hold.
  5. Try flying in velocity mode over a blank white posterboard. (There is one in 121.) Be careful! How does the drone's behavior change?
  6. Now try over a uniform textured surface such as the floor in 121. Try a position hold. How well does it work? How long is it able to hold position?