# Drift in Velocity Control using SITL

**URL:** <https://discuss.px4.io/t/drift-in-velocity-control-using-sitl/37813>\
**Category:** PX4 Autopilot\
**Created:** [April 17, 2024, 9:10am UTC](https://discuss.px4.io/t/drift-in-velocity-control-using-sitl/37813 "2024-04-17T09:10:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jodok](https://discuss.px4.io/user_avatar/discuss.px4.io/jodok/32/16154_2.png) [@Jodok](https://discuss.px4.io/u/Jodok)\
**Post date:** [April 17, 2024, 9:10am UTC](https://discuss.px4.io/t/drift-in-velocity-control-using-sitl/37813/1 "2024-04-17T09:10:53Z")

</div>

Dear Pixhawk Community,

We have been trying to get the iris-drone to fly stable in px4-SITL with velocity commands for two weeks now, but we have not yet succeeded.  
Our Project outlines:

- Ubuntu 20.04.6
- ROS Noetic
- PX4-Autopilot 1.14.0 as SITL
- Gazebo 11.14.0
- mavros 1.18.0
- Simulating the IRIS Drone
- QGroundControl 4.3.0

We followed these two guides: [Ubuntu Dev. Env.](https://docs.px4.io/main/en/dev_setup/dev_env_linux_ubuntu.html) and [ROS with Gazebo Sim.](https://docs.px4.io/main/en/simulation/ros_interface.html) to set up the SITL Simulation.  
Then we use ROS to connect to the drone, get it into _Offboard-Mode_ and to control it with poses and velocities.  
For the position estimation we later are going to use _Optitrack_. To simulate it we extract the ground truth pose from gazebo ([like described here](https://www.sauravag.com/2017/06/how-to-get-ground-truth-pose-data-in-ros-gazebo/)) and publish it to the `/mavros/odometry/out` topic.

Now, controlling the drone with poses (`/mavros/setpoint_position/local`) works perfect. But when we send velocities (`/mavros/setpoint_velocity/cmd_vel_unstamped`) the drone is always drifting up. Especially when sending only angular velocities (neg. or pos., doesn’t matter) the iris-drone is always going up in the beginning (see image), after some time it starts to go down/up/down/up.  
Where could this come from? We also did a rosbag and you can see the corresponding graph in the second image.

We believe that our problem sits (in front of the Computer, of course) somewhere in the EKF and the used sensors but we can’t figure out where. We turned off all (?) the other Sensors that the EKF uses: _Barometer_, _Magnetometer_, _Range-Finder_, _GNSS/GPS_. And turned on the _Extrennal Vision Sensor Aiding_ except for the _3D Velocities_ option, because with this option the drone went completely nuts for angular velocities, probably because of some wrongly oriented reference frames. And also turned on _Vision_ for the _EKF2\_HGT\_REF_ parameter.

Turning off the _EKF2\_IMU\_CTRL_ helped to reduce the drone’s upward drift, but we are still not satisfied with the behaviour of the drone. Could it also be possible that the IMU and Accelerometer is messing with us?

Thank you very much in advance for everyone who takes time looking at our problem!

  
That is what happens when the drone should just rotate in two meters hight around the Z-Axis:

 ![rviz_traj](https://discuss.px4.io/uploads/default/original/3X/9/c/9ceacb447ff4ba63da66f20c65150511e9e91405.png)

#### For the graph:

🟠 Orange = ground truth velocities by gazebo  
🔵 Blue = assumed velocities by px4  
🟢 Green = desired velocities we are sendig to px4

 ![graph](https://discuss.px4.io/uploads/default/original/3X/8/7/877f2152bccc2de77078dad46870ce5d4c40cd58.png)
