How to connect APM Power Meter to Cleanflight and INAV

This topic was eluding me for some time now. It’s time fix the problem and finally present a short tutorial how to connect 90A APM Power Meter for flight controller boards like Naza32, SP Racing F3 or any other running Cleanflight / Betaflight / INAV software and equipped with Current Meter ADC input.

I will not show where to connect APM Power Meter to flight controller, since this differs from board to board. Some boards have dedicated pins, on some boards PWM input pins are used for Current Meter ADC. You have to refer FC documentation and / or flight controller software documentation.

Continue reading “How to connect APM Power Meter to Cleanflight and INAV” »

Read More

Programming ESP8266 with Arduino IDE

One of the best things about ESP8266 ESP-01 WiFi modules is that they can be programmed
using popular and well known Arduino IDE and act as stand alone board with WiFi
capabilities. Thanks to ESP8266 group process of integrating ESP8266 and Arduino IDE
is pretty simple.

First step is to add http://arduino.esp8266.com/stable/package_esp8266com_index.json to Additional Boards Manager URLs in Configuration in Arduino IDE.

Continue reading “Programming ESP8266 with Arduino IDE” »

Read More

Using PCA9685 with INAV

One of the hardware limitations of flight controllers that usually multirotor users ignores is a number of PWM outputs. To fly a quadcopter you need “only” 4 PWM outputs. Since most FCs have 6 outputs and 90% of multirotors are quadcopters, there is no problem.

In case of airplanes, this is not that simple. 6 PWM outputs is an absolute minimum to fly a classic airplane using MultiWii and derivatives (Baseflight, Cleanflight, INAV): 2 outputs reserved for motors, 2 ailerons, elevator, rudded. Suddenly, 6 outputs barely meets the requirements. If you want flaps, gas engine, pan & tilt or anything else, you are missing some outputs.

For some time INAV tries to address this issue by supporting external PWM driver: PCA9685.

Continue reading “Using PCA9685 with INAV” »

Read More

INAV: Launch mode video tutorial

One of the best new features of INAV 1.4 was Launch assistant mode (NAV LAUNCH). It greatly simplified the process of hand launching a fixed wing. All you had to do was to throw it into the air. INAV detected the throw, engaged motor(s) and stabilized flight and kept constant climb rate in the initial flight phase. INAV 1.5 will make it even better: it will also allow swing launch!

Since INAV 1.5 should be release in next 2 days, and there is very little info on INAV Launch mode, I’ve decided to create a short video showing how to do it.

Read More

INAV: how to setup asynchronous gyro

Together with version 1.4, INAV introduced asynchronous gyroscope processing. What is async gyro and why it is useful to have it, you can read here. In short worlds: data from gyroscope is read and filtered faster than PID controller updates motor and servo output.

When it is worth to enable asynchronous processing

In general, async gyro can be enabled when:

  • Flight controller does not ave enough processing power to run control loop faster than 2000us (500Hz mode). This is the case for all SMT32F1 boards like Naze32, Flip32 or CC3D
  • Flight controller is powerful enough to process PID control loop faster than ESC protocol (PWM, Oneshot125, Multishot) transfer commands to ESC and servos. This is usually true in case of all STM32F4 boards
  • INAV is setup on a “racer” machine that requires the best gyro signal possible

Async gyro should not be enabled when gyro and control loop frequency are the same. For example, 1kHz gyro and 1kHz control loop would give worse results than 1kHz synchronous processing. Continue reading “INAV: how to setup asynchronous gyro” »

Read More

INAV Advanced Accelerometer Calibration: why and how

One of the most often forgotten tasks required to bring the most of INAV, is good accelerometer calibration. Why? While flight controller software like Cleanfligth and Betaflight use accelerometer only to compute UAV’s body inclination (Angle and Horizon modes as well as artificial horizon), INAV uses it also for position estimation.

Cleanfligt has to only know where “down” is. For this, simple accelerometer calibration is fully enough: place UAV on a level surface and hit “Calibrate accelerometer” button. Few seconds and done.

INAV not only has to know where bottom is. It also has to know where all other directions are, and how fast UAV is accelerating in those directions to be able to estimate its position. For this, advanced, or 6 point accelerometer calibration is required.

How to perform Advanced Accelerometer Calibration [AAC]

During AAC, each side of flight controller has to be positioned “down” during calibration. Order is not important with one exception: during first step, top of flight controller has to positioned up. This is impotrant: we are calibrating accelerometer, not whole UAV. Even is FC is mounted upside-down, during first step, FC has to to positioned upwards.

  1. Prepare stable surface that will allow to keep FC stable in all required positions. Angles does not have to be super precise, even few degrees should be enough, but flight controller has to be motionless during calibration
  2. Plug-in USB and connect to INAV Configurator
  3. Position flight controller facing up and hit “Calibrate acccelerometer” button. Wait for success message
  4. Rotate FC 180 degrees so it is bottoms-up and hit “Calibrate acccelerometer” button. Wait for success message
  5. Rotate FC so its rear edge is facing down and hit “Calibrate acccelerometer” button. Wait for success message
  6. Rotate FC so its right edge is facing down and hit “Calibrate acccelerometer” button. Wait for success message
  7. Rotate FC so its front edge is facing down and hit “Calibrate acccelerometer” button. Wait for success message
  8. Rotate FC so its left edge is facing down and hit “Calibrate acccelerometer” button. Wait for success message
  9. Disconnet and power down
  10. Advanced accelerometer calibration is done. If is succeeded, acczero_x, acczero_y and acczero_z should different than 0, while accgain_x, accgain_y and accgain_z should be different than 4096

Advanced accelerometer calibration

Worth remembering: calibration values can be restored via CLI when flight controller firmware is updated. It is hardware, not software dependent. Calibration should be executed when new hardware is used.

Read More

How to install and configure Betaflight 3

Latest Betaflight 3.0 is a new quality for flight controller software. It brings many new, cool, features comparing to previous versions. If you fly mini-quad or micro-quad, you have to check what Betaflight 3 has to offer.

This tutorial will show how to install Betaflight 3 and how to configure it so mini-quad can go into the air in under 20 minutes.

To play with Betaflight 3.0 you will need latest Betaflight Configurator! Install or update to latest version.

Flashing

Open Betaflight Configurator

Betaflight Configurator

Continue reading “How to install and configure Betaflight 3” »

Read More

How to tune PID I-term on a quadcopter

With this entry I want to initiate short series of articles showing how to tune multirotor / quadcopter PID controller. Let’s call it a continuation of Blackbox series, but this time I will not relay only on Blackbox data. Yes, I will show few examples how given scenarios looks on Blackbox logs, but all steps will be doable without Blackbox.

Before we proceed, you much understand how PID controller works and what Kp aka. P-gain, Ki aka. I-gain and Kd aka. D-gain are responsible for. There are many sources: Wikipedia, my “What is PID controller article”, great video from Bruce and many many others.

How to tune I-term of PID controller

Most PID tuning tutorials suggests to start with P tuning and then move to I. Why? Probably because it’s simpler to get UAV in flyable state. Or because P is first letter on PID. Or I have no idea. Starting with I has some advantages:

  • tuned I-term will not affect much more important Pterm tuning
  • it is simpler to tune I than P if proper method is used
  • tuned I-term will probably not change during P and D tuning

Before we proceed, a reminder of what I-term is used for and short characteristic of it:

  • I-term is responsible for correcting long time error accumulated in the past: non-even thrust from motors, wind, etc.
  • I-term should not be affected by short events like few degrees attitude correction
  • I-term should should react fast in special conditions like upside-down phase of rolls and flips
  • bigger I-gain not only means that correction will be stronger. What is more important, it also determines how fast I-term would change!
  • too low I-term causes multirotor unable to keep desired attitude. UAV will bank on its own, be sensitive to wind
  • too much I-term will introduce overshot, visible low frequency oscillations, wobble on descend
  • gentle, smooth flying for aerial photography requires much lower I-gain than aggressive acrobatic flight
  • better UAV balance (center of thrust close to center of gravity) results in lower required I-gain
  • usually, due to weight distribution, pitch axis requires more I-gain than roll axis

There are two methods of manual I-gain tuning:

  • Tuning for smooth, aerial photography, flying with bigger drones
  • Tuning for acrobatic flying with smaller drones (250 size and smaller)

How to tune I-term for smooth flying, aerial photography style

General rule for I-gain tuning for smooth flying on bigger machines (8″ or bigger propellers, > 1kg) is to keep I as low as possible. Multirotors like these are not designed for acrobatics, or aggressive flying. Their main purpose to to be stable in hover or cruise and do not wobble on descend. Higher I-gain, due to bigger (sometimes huge) inertia of both body and propellers will result in overshooting, wobbles and oscillations.

  1. Start with weight balance. Center of gravity should be as close as possible to point of thrust. Simple procedure looks like this:
    1. For pitch and roll axis find a line that crosses the frame between two point lying in the middle between motors opposing this line
    2. Try to lift multirotor using two fingers catching centerplate where line crosses it
    3. If frame tilts forward, move some weight (usually battery) back, if frame tilts left, move some weight right, and so on
    4. This does not have to perfect, but the closer you will get, the better flight performance you will have
  2. Tune roll and pitch separately. Ignore yaw for now, this can be tuned much later and usually it is not required to tune yaw at all!
  3. Tuning has to be done in Acro/Rate mode, without self leveling!
  4. Start with default PID gains. In most cases they are good enough for hover. If drone is able to take off and does not wobble on its own, you are good to go. If it is sluggish, wobbles, tilts on its own, increase P gain in 20% steps until it is hovering without much trouble. Remember, we are not tuning P yet. We just want it to be flyable.
  5. Throttle up and do a fast ascend for few meters. Then cut throttle to about 25% and descend fast. Observe what is happening to a drone. Three things can happen:
    1. If drone is unable to keep attitude and tilts is any directions, I gain on this axis is too low. Increase I gain and repeat experiment
    2. If drone keeps attitude, but wobbles on descend, I gain is too high. Decrease I gain and repeat
    3. Try to keep I gain lower than higher. That means you should concentrate on finding a spot closer to a point where UAV is unable to keep attitude that to the point where wobble appears
    4. If drone keeps attitude and does not wobbles on descend, I gain is tuned
  6. Confirm I-gain tune by doing forward-backward and left-right fast flights. If multirotor is able to keep angles, does not slowly drift or slowly wobbles during braking, congratulations, you tuned I-gain for smooth flying!

On a Blackbox log, wobble during fast descend might look like this: too much I gain during descend

Both axises: roll and pitch were affected in this case, but bigger wobble appeared on pitch axis, up to 45degrees per second! If you take a look at pitch PID graphs, you would see that I-term moved from more positive, to negative and then to positive again. P term tried to compensate, but it had to fight not only with changing conditions, but also with changing I term after original movement has been canceled out. This might not a be a perfect example, but shows general principle.

This example show what is happening in similar situation when I gain is much lower. I term stays more less flat, most of the work is done by P term.

not too much I gain during descend

How to tune I-term for acrobatic flying

If you would tune I gain using procedure from previous paragraph and went doing some rolls and flips, you would notice something bad: when copter crosses 90 degrees and begins upside-down phase, single wobble, a strong jerk, appears. Like I mentioned before, I gain does not only determines correction force. It also determines allowed speed of change when conditions changes. Imagine a copter that is slightly tail heavy. That means motors in the back have to spin slightly faster than those in the front to compensate for weight imbalance. I term does that very moment you take off and it works as long as you do not try to bring everything upside down very fast. If rear motors would still bring more trust that forward motors when drone is inverted, it would not compensate for weight imbalance. It would make thing worse than better. Our imaginary tail heavy multirotor needs less thrust in the back when flying inverted.

Flips, rolls and all other rapid maneuvers requires higher I gain to allow for faster I term change. If I term is unable to follow strong changes, single wobble or multiple wobbles would appear when passing magical 90 degrees inclination.

Another problem with method from previous paragraph is that small machines are much more wobble on descent resistant than big ones. Smaller, faster rotating propellers, less inertia, more agile. One would really have to push I gain very high to see strong wobble during descend. And it still not would do good for acrobatics. This is why, on those machines, try the following

  1. Balance multirotor like above
  2. Start with default PIDs
  3. Use only Acro/Rate mode
  4. Tune each axis separately
  5. Take off and check UAV stability during fast ascends and descends
    1. If it keep attitude but wobbles, lower I gain
    2. If it does not wobbles, but does not keep inclination, rise I gain
    3. If it does not wobbles and keeps attitude, we can move forward
    4. This step does not have to be very precise. As long and it keep inclination, you are good to go
  6. Go high. If you have FPV, this helps a lot. If not, just pay attention to drones behavior
  7. Do a fast single roll. If during transition to inverted flight (around 90 degrees) multirotor jerked, I gain is too low and I term is unable to follow the change. Raise I gain on axis and try again. The hardest thing here is to decide which axis is responsible for jerk. Sometimes it is single axis, sometimes both roll and pitch together: FPV helps a lot with this. If you really do not know, rise both. Repeat this step until roll is smooth, without visible wobble
  8. Do the same during flips. If you did everything right in previous step, this is only to confirm everything works like expected
  9. Confirm there are no wobbles during fast descends. If they appear try lowering I gains a little

Small note: I gain that allows for smooth transition to inverted flight flight depends on rotation speed and imbalance. The bigger imbalance and faster the rotation, the higher I gain would be required. So if you change rates, you might want to repeat I term tuning.

Read More