# FW Terrain following

**URL:** <https://discuss.px4.io/t/fw-terrain-following/43008>\
**Category:** PX4 Autopilot\
**Created:** [December 23, 2024, 10:42am UTC](https://discuss.px4.io/t/fw-terrain-following/43008 "2024-12-23T10:42:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xdwgood](https://discuss.px4.io/user_avatar/discuss.px4.io/xdwgood/32/5429_2.png) [@xdwgood](https://discuss.px4.io/u/xdwgood)\
**Post date:** [December 23, 2024, 10:42am UTC](https://discuss.px4.io/t/fw-terrain-following/43008/1 "2024-12-23T10:42:34Z")

</div>

Currently PX4 does not support terrain following in fixed-wing mode? Does anyone know what I should do to support terrain following in fixed-wing mode? thank you

---

<div class="post-metadata">

**Author:** ![farhang](https://discuss.px4.io/user_avatar/discuss.px4.io/farhang/32/17881_2.png) [@farhang](https://discuss.px4.io/u/farhang)\
**Post date:** [December 23, 2024, 3:04pm UTC](https://discuss.px4.io/t/fw-terrain-following/43008/2 "2024-12-23T15:04:44Z")

</div>

Hey,  
Probably you have come up with this old thread:

> [@Mode "terrain following" with a fixed wing](https://discuss.px4.io/t/mode-terrain-following-with-a-fixed-wing/20819/2):
>
> Hi @Mael_Forestal , IIRC, terrain following is not available for fixedwing yet. I guess it should probably be implemented here: [https://github.com/PX4/PX4-Autopilot/blob/835e3258ed941458c95c295c7746d9ad5a07ead0/src/modules/fw\_pos\_control\_l1/FixedwingPositionControl.cpp#L494](https://github.com/PX4/PX4-Autopilot/blob/835e3258ed941458c95c295c7746d9ad5a07ead0/src/modules/fw_pos_control_l1/FixedwingPositionControl.cpp#L494) You can simply use the dist\_bottom field from the [vehicle\_local\_position](https://github.com/PX4/PX4-Autopilot/blob/835e3258ed941458c95c295c7746d9ad5a07ead0/msg/vehicle_local_position.msg#L53-L58) topic to get the estimate of the distance below the drone (using a range finder or an optical flow sensor). Good luck!

@sfuhrer May have any idea?

---

<div class="post-metadata">

**Author:** ![xdwgood](https://discuss.px4.io/user_avatar/discuss.px4.io/xdwgood/32/5429_2.png) [@xdwgood](https://discuss.px4.io/u/xdwgood)\
**Post date:** [December 24, 2024, 1:10am UTC](https://discuss.px4.io/t/fw-terrain-following/43008/3 "2024-12-24T01:10:47Z")

</div>

@farhang thanks for your replay

As you said, that link is too old, and the current fixed-wing controller can’t find the relevant content. My idea is to realize this function by changing the parameters of EKF, which only fuses lidar data.

---

<div class="post-metadata">

**Author:** ![bresch](https://discuss.px4.io/user_avatar/discuss.px4.io/bresch/32/2343_2.png) [@bresch](https://discuss.px4.io/u/bresch)\
**Post date:** [January 3, 2025, 2:37pm UTC](https://discuss.px4.io/t/fw-terrain-following/43008/4 "2025-01-03T14:37:10Z")

</div>

The EKF is driven by the IMU and the IMU cannot sense the terrain height change. Tweaking the EKF to achieve terrain following it taking the problem the wrong way around. It’s fine if you need something to work right now for a demo tomorrow but it will never work nicely.

I can’t tell you exactly how to do it but it should probably manipulate this [height rate setpoint](https://github.com/PX4/PX4-Autopilot/blob/f1a339e7c66acba3067668d38a9182ef56fb948b/src/modules/fw_pos_control/FixedwingPositionControl.cpp#L2203) or maybe directly adjust this [altitude setpoint](https://github.com/PX4/PX4-Autopilot/blob/f1a339e7c66acba3067668d38a9182ef56fb948b/src/modules/fw_pos_control/FixedwingPositionControl.cpp#L2223).

Any better idea @sfuhrer ?  
(talking about terrain following in manual modes here, not auto)
