# Drone keeps moving left when in position hold mode with optical flow

**URL:** <https://discuss.px4.io/t/drone-keeps-moving-left-when-in-position-hold-mode-with-optical-flow/7832>\
**Category:** Flight Testing & Log Analysis\
**Created:** [September 17, 2018, 7:29am UTC](https://discuss.px4.io/t/drone-keeps-moving-left-when-in-position-hold-mode-with-optical-flow/7832 "2018-09-17T07:29:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyuhyong\_You](https://discuss.px4.io/user_avatar/discuss.px4.io/kyuhyong_you/32/2210_2.png) [@Kyuhyong\_You](https://discuss.px4.io/u/Kyuhyong_You)\
**Post date:** [September 17, 2018, 7:29am UTC](https://discuss.px4.io/t/drone-keeps-moving-left-when-in-position-hold-mode-with-optical-flow/7832/1 "2018-09-17T07:29:31Z")

</div>

Hi all,

I have been testing position control using pmw3901 optical flow sensor.  
Flight log about local position shows very good position hold however, it keeps moving towards left.  
Here is the log.  
[https://logs.px4.io/plot\_app?log=81cb8ced-59ba-4bc2-839b-088ee64b2785](https://logs.px4.io/plot_app?log=81cb8ced-59ba-4bc2-839b-088ee64b2785)

And here is the integral of raw optical flow sensor data.

 ![](https://discuss.px4.io/uploads/default/original/2X/8/8052d3a99398b2ad41b4fd40c01724d889b594d5.png)  
Above plot is time integration of flow sensor int x and y.  
Calculated speed is approximately 0.01 m/s while there is no significant movement in forward/backward direction.

It looks like somewhere in position controller yields small errors is body x frame.  
How can I solve this problem? or any suggestions on this issue?

//Added video below

[![](https://img.youtube.com/vi/ePyY8f7sXtQ/maxresdefault.jpg "PX4 position hold with optical flow") ](https://www.youtube.com/watch?v=ePyY8f7sXtQ)

Kyu

---

<div class="post-metadata">

**Author:** ![Kyuhyong\_You](https://discuss.px4.io/user_avatar/discuss.px4.io/kyuhyong_you/32/2210_2.png) [@Kyuhyong\_You](https://discuss.px4.io/u/Kyuhyong_You)\
**Post date:** [September 20, 2018, 3:17am UTC](https://discuss.px4.io/t/drone-keeps-moving-left-when-in-position-hold-mode-with-optical-flow/7832/2 "2018-09-20T03:17:58Z")

</div>

So I decided to manually compensate errors in optical flow to local position estimate.  
To do that, I need to transform flow int x, y in body frame to NED frame as shown here.  
 ![](https://discuss.px4.io/uploads/default/original/2X/7/77b321a2e8e3b21c26fa0f8afcd483920e41b75c.png)

in mc\_pos\_control\_main.cpp  
the rotation matrix \_R being updated every att update as here

> <https://github.com/PX4/PX4-Autopilot/blob/5f8c08db7958ea3ff0762e8f3d1b52ee8a648403/src/modules/mc_pos_control/mc_pos_control_main.cpp#L674>

and by subscribing the optical flow orb message, I can get int\_x and int\_y and put it into  
`matrix::Vector3f _flow_int;`

My question is, in order to transform, simply multiply them would work?

> matrix::Vector3f flow\_ned = \_flow\_int \* \_R;

---

<div class="post-metadata">

**Author:** ![knolle](https://discuss.px4.io/letter_avatar_proxy/v4/letter/k/a9adbd/32.png) [@knolle](https://discuss.px4.io/u/knolle)\
**Post date:** [September 27, 2022, 3:44pm UTC](https://discuss.px4.io/t/drone-keeps-moving-left-when-in-position-hold-mode-with-optical-flow/7832/3 "2022-09-27T15:44:32Z")

</div>

Hey, have you found any solution for this, yet?
