mTECS

This page describes the mtecs library which implements a total energy control system (tecs). The mtecs library is used by the app fw_pos_control_l1

Purpose

The tecs controls the airspeed and altitude of the airplane. Given an altitude or flightpath angle setpoint and an airspeed setpoint the tecs calculates the necessary throttle and pitch setpoints. Hence the output of a tecs library call (= control signals) are the throttle and pitch setpoint.

Modes

mTECS can operate in the following modes (developers: see value of enum tecs_mode). Depending on the mode different parameters are active:

  • NORMAL: all standard parameters apply
  • UNDERSPEED: triggered if airspeed falls below FW_AIRSPD_MIN: all MT_USP_* parameters apply and override the corresponding parameters of the normal mode
  • TAKEOFF: active if flying towards a takeoff waypoint: all MT_TKF_* parameters apply and override the corresponding parameters of the normal mode.
    • MT_TKF_PIT_MIN: this is the minimal pitch during takeoff. The value can be overridden by the corresponding field in the qgc waypoint UI
  • LAND: activated through a landing waypoint and when the flare altitude (FW_LND_FLALT) is passed. All MT_LND_PIT_* parameters apply and override the corresponding parameters of the normal mode.
  • LAND_THROTTLELIM: activated through a landing waypoint, when the throttle limit altitude (FW_LND_TLALT) is passed. All MT_LND_THR_* parameters apply and override the corresponding parameters of the normal mode.

Structure

The tecs consists of an inner control loop and an outer control loop. Also have a look at the diagram at the bottom of this page as a reference while reading this page.

Outer Control Loop

The airspeed control block is a PD controller with the airspeed derivative setpoint as output. The altitude control block is a PD controller with the flight path angle (angle between horizontal and vertical velocity) as setpoint.

The airspeed and altitude setpoints are provided to the mTECS library by the fw_pos_control_l1 app. The altitude setpoint is typically set with a waypoint or the navigator app sets it to be the current altitude when loiter is activated on the remote control. The airspeed setpoint is set to FW_AIRSPD_TRIM. During landing 1.3 * FW_AIRSPD_MIN is used.

Developers: If the desired flight path angle is already known, one can can also provide the flight path angle sp (omit this control block)

Inner Control Loop

The input to the inner control loop (large grey shaed box in the diagram) are the outputs of the outer loop and the airspeed derivative. The inner loop controls the 'total energy rate' nad the 'energy distribution rate' and hence the input values are first converted to energy rates. The total energy rate control block and the energy distribution rate control block are both PI controllers with a feedforward gain.

Reading the logs/plots

The TECS field contains most of the information needed for tuning mTECS. See sdlog2 for more information on how to generate plots.

Outer Loop

The relevant fields are:

  • ASp: altitude setpoint
  • A: altitude
  • AF: altitude filtered
  • FSp: flight path angle setpoint
  • F: flight path angle
  • FF: flight path angle filtered
  • AsSP: airspeed setpoint
  • As: airspeed
  • AsF: airspeed filtered (with cutoff frequency set by the param MT_A_LP)
  • AsDSP: airspeed derivative setpoint
  • AsD: airspeed derivative
  • M: mode (corresponding to value ofenum tecs_mode)

Inner Loop

The relevant fields are:

  • TERSP: total energy rate setpoint
  • TER: total energy rate
  • EDRSP: energy distribution rate setpoint
  • EDR: energy distribution rate

Tuning

Attitude control has to be tuned first before you can start to fly autonomous and tune the TECS. This means that you are able to fly with good performance in seatbelt mode.

Make sure the airspeed sensor (differential pressure) is calibrated. You can calibrate the sensor with qgrouncontrol

Types of parameters

You can refer to the diagram at the bottom of this page to understand which parameter has an effect on which control block. In general:

  • FF: Feed Forward gain: maps setpoint to control signal directly
  • P: Proportional gain: maps the error to the control signal
  • I: Integral part: maps the error integral to the control signal, increase to remove steady state error
  • D: derivative gain: maps the error derivative to the control signal, a higher value increases damping (reduces oscillations)
  • LP: lowpass cutoff frequency in Hz (a lower value filters more)
  • MIN and MAX: lower and upper limits of the control signal (output of the block)
  • OFF: Offset in the control signal, a constant value that is added to the control signal

Approach

  1. Throttle offset: set MT_THR_OFF to the typical throttle you need for cruise flight when flyin in seatbelt (typically between 0.5 and 0.8)
  2. Check all MIN and MAX parameters. Make sure that none of the limits interfere with your tuning.
    1. MT_FPA_MIN/MT_FPA_MAX: these params limit flight path angle (in degrees) which the TECS wants to fly to correct altitude. The values depend on your airframe. For a larger and relatively less powerful aircraft you have to choose smaller values than for a small overpowered plane.
    2. MT_ACC_MIN/MT_ACC_MAX: set to large values or don't change default
    3. MT_PIT_MIN/MT_PIT_MIN: pitch limits: set to sane values but make sure that you don't limit too much. Typically +-30 to 45 deg.
    4. MT_THR_MIN/MT_THR_MAX: set to 0 and 1 unless your aircraft is really overpowered.
  3. Set cruise airspeed FW_AIRSPD_TRIM (m/s)
  4. Prepration:
    1. Set a simple waypoint course, for example a square around your position. First at constant altitude, later for fine tuning at different altitudes.
    2. Make sure that you can observe altitude and airspeed in the ground control station
    3. Also be ready to takeover in seatbelt/manual at any time.
  5. Switch to manual and observe airspeed and altitude. If one of them is quickly diverging (eg. quickly diving or stalling) first try to correct that issue before further tuning.
    1. Airspeed: Increase MT_ACC_P (outer loop) slowly to large values. Stop when oscillations start or when you are at a really large number. (E.g. 5)
    2. Altitude:Increase MT_FPA_P (outer loop) slowly to large values. Stop when oscillations start or when you are at a really large number. (E.g. 5)
    3. If increasing the outer loop params does not help (eg. no reaction on large errors) increase MT_THR_FF and MT_THR_P. Initially you can leave MT_THR_P at zero and only play around with MT_THR_FF. MT_THR_P should be kept significantly smaller than MT_THR_FF
    4. If you see the aircraft correcting only with throttle for altitude and speed errors increase MT_PIT_FF and MT_PIT_P. Initially you can leave MT_PIT_P at zero and only play around with MT_PIT_FF. MT_PIT_P should be kept significantly smaller than MT_PIT_FF

Symptoms

Short pitch down and full throttle movements

This could be the underspeed protection triggering. You can clearly see this in the plot if you look at airspeed and the tecs mode field. Lower FW_AIRSPD_MIN and refly. Maybe you need to increase airspeed filtering by lowering MT_A_LP.

Pulsing / Oscillating Throttle

If the throttle is oscillating quickly (1 to 2 hz or faster) this is probably because of the very noisy airspeed signal.

  1. So your first step should be to increase filtering by lowering one of these params: MT_A_LP, MT_AD_LP, MT_ACC_D_LP
  2. If that does not help you can go on to make airspeed control less aggressive: lower MT_ACC_P, higher MT_ACC_D (you can get it to the point where it should not control airspeed anymore).
  3. the flight path angle estimate could be the source of the problem as well (check the logs): so try to filter it more by lowering MT_FPA_LP
  4. If throttle is still pulsing (and especially if you lowered the gains in step 2 until no airspeed control is observable) try adjusting the 'total energy rate controller' to be less agressive: lower MT_THR_FF, MT_THR_P, MT_THR_I
  5. If it is still pulsing it can also be because your altitude control gains are too high. (The altitude estimate comes from the estimator and therefore this signal is much smoother.) Try to set the altitude controller less aggressive: lower MT_FPA_P, higher MT_FPA_D, lower MT_FPA_D_LP

Diagram

7V1Zc+K4Fv41eQzlDRse0+kw03W7Z1KT3Lpzn7occMA1BFPGdNL960eydYS1YGQjeUmAKhaBt3OOPp3dV+7ty9tvabhdfUsW0frKsRZvV+7nK8fx/PEEveGRn8WIj7/hgWUaL4oh+zDwEP+KyKBFRvfxItoxf8ySZJ3FW3Zwnmw20Txjxp6TNXuIbbiE3R8GHubhWhz9X7zIVsXoxPEP479H8XIFh7H9afHLLvsJ+1hEz+F+nV3nQ+RaX0LYF7mqN6v4eu14EzL0kwzRc9gw338lyQszkEa7A7HI9cbkxMgun5J0EaXM0Dre/FMmnHuHmJcmCdoQf3p5u43WmIHAm2Kz2ZFf6bmm0YY59NENPLLJj3C9JycvUHCZJvvtlftpmYaLGO34NlknxVW4s9nnqU+5cTgq7DVKs4iIHisX4RPsPT9Bcna/RclLlKU/MUcoQ4IxYUgx4k4J6V4PEmGPCd9XJWmYEEkPCX2XdOcHgqAPhCbH6EPIUaJPGKe7bRQt8CSK0vhHmMU/IoFor6s4ix624Rx/f0VzEREQkyNG0n2zjpdYmrIEjz4nm+yBbGjXJDNlH09okaBlcjnjkVV+kL2UqedNR/60/CCHP4eajk12oiJtOVmKGQXYo3bptWUMeEwEDBCyTDAZhVxyVudRJDhNkd0q3OKP8UsOl1SMvoZP0fo+2cVZnGBxekqyDIPSETnLN79BopujMpa0EL48x29Inslf0PdVlqEtbvBlOLPX19fRfLcL99kqSUdzdAQ0tr1GRM4wN5zZfrtOwsUOfXIs20VvFrqoWb7+XN+uwjS7jv98CK6/oC2umR19H203yyt35k2en2xP5PFBXk6LN/kVcJXwUsJKQt8yJ2HsPE6SY5U4+Xh3+zC62RVMLXMUXQw69KeQ8GeOrhivCwLjXuLFAm+TT4YSHlgWnpGnJ0kTAhJJL5EMVkTdwu+TfVTJvgxGJQD52cZP9XWoYr1xXW69GZMpWqKI70lI4o010ARNH44k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cAkbkljPbZUOvp93B5bVGIG0GNL0pewgIMOW2w1oF97UQlH0o6wD3gAXhJoSy76wQzCwaXlXhUcDKjlnqQbWgEHHRoLTQjYJh7UaEzUIh6A656WvLeqHygYUB8YEM7t3tMmIIiGH/EfdIgH9enXIh7AKffNXuDwwG8xjQl5Ki94UNGTd0D2gqR7E8GDLjWEBhRsExEaByKMuhN91p0YQApsK4ig0hXnAyPCcCIMB5nkExs7hAMt0QVTcCDp1NkHOIDUG6irAS9MO3BwiS9UwAGVmCHAwZH4Ar65Tld40IB+LeKBSp+Z9vHAgugqOBThtt6nEg/10ORiMFTgAZWYAeAB+J0YTlo5JDze/dWl0dCAiiIqQDhV/wzoZZjB4tKSPCgdbQcVLnGGKlQYUJxB2huJokKHmKAj1GAOE3oZarC5hG1flopgDhMuoYYqTBhQqAGaMksw4e5zt5qCjoCDOVTopXvRhhytQ5+OFlEBauUuqCBFhQG5F6HcXo4KHWKCDh+jMUyARmK9wgShllpW9GMQExQsqo+LCVRihoAJMjuwwIRv3SFCAwq2iQgKNW8dIALcFhL8CdBPqx1EULCnPjAigMQMARFEK/Dm8eF+9LhK97usS9uhARXbRAWFuFsXqMDFIn1JaoI5VFCwpz4wKoDEDAAVJO0sc1S4j7P5qlNQqE9EY6CAvqZJgrY/1FljMfmGmgvhf/wL

Direct link to the above diagram.

Translations of this page:


Quick Links

QR Code: URL of current page