# Offboard mode set velocity not working

**URL:** <https://discuss.px4.io/t/offboard-mode-set-velocity-not-working/30104>\
**Category:** PX4 Autopilot\
**Created:** [December 16, 2022, 2:40pm UTC](https://discuss.px4.io/t/offboard-mode-set-velocity-not-working/30104 "2022-12-16T14:40:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![elanius](https://discuss.px4.io/letter_avatar_proxy/v4/letter/e/db5fbb/32.png) [@elanius](https://discuss.px4.io/u/elanius)\
**Post date:** [December 16, 2022, 2:40pm UTC](https://discuss.px4.io/t/offboard-mode-set-velocity-not-working/30104/1 "2022-12-16T14:40:58Z")

</div>

Hi.  
I am communicating with a drone in offboard mode with the ROS2 node. So setting a specific position works well. However, now I am trying to do some simple teleoperation. When I set velocity in `/fmu/in/trajectory_setpoint` while publishing `/fmu/in/offboard_control_mode` set to `velocity` (others are false), I am getting weird behaviour.  
It looks like even velocity is set drone behaves according to a position.  
e.g. setting Z velocity to -0.5 doesn’t result in constant ascend, but the drone stabilized its position at -0.5m.

 ![Screenshot_position_instead_of_velocity](https://discuss.px4.io/uploads/default/original/2X/4/49797163e298d63b8eec8b5882be16cece1e3e6d.png)

Am I missing something, or is it a bug?

---

<div class="post-metadata">

**Author:** ![Benja](https://discuss.px4.io/user_avatar/discuss.px4.io/benja/32/11872_2.png) [@Benja](https://discuss.px4.io/u/Benja)\
**Post date:** [December 16, 2022, 5:46pm UTC](https://discuss.px4.io/t/offboard-mode-set-velocity-not-working/30104/2 "2022-12-16T17:46:26Z")

</div>

The meanings of the flags of `offboard_control_mode` is a bit misleading as the position controller module (which control the tracking of position AND velocity setpoints) is enabled if (not only if) `offboard_control_mode` has `velocity` or `position` enabled.  
Therefore just setting `velocity=true` and `postion=false` does not stop the position controller from controlling both position and velocity.  
You have to set to `nan` the position setpoints.  
In your case the vehicle stops at `-0.5` as a result of combining a `0` z-reference and a `-5` vertical ascend.

---

<div class="post-metadata">

**Author:** ![elanius](https://discuss.px4.io/letter_avatar_proxy/v4/letter/e/db5fbb/32.png) [@elanius](https://discuss.px4.io/u/elanius)\
**Post date:** [December 16, 2022, 9:32pm UTC](https://discuss.px4.io/t/offboard-mode-set-velocity-not-working/30104/3 "2022-12-16T21:32:12Z")

</div>

Thank you very much. Now it works almost perfectly. But I still have some issues with `yaw` and `yawspeed`. Only these values behave absolutely. e.g. I have yaw velocity 1.0, and when I set it to `yawspeed`, it turns the drone about the absolute position and doesn’t go further. So what is a proper way to set `yaw`?

This was a handy piece of information. Are there some sources which describe this? Or do I have to read the code of PX4 autopilot?

Here is my function, which handles position and velocity.

```auto
    def _keep_flying(self):
        ts: TrajectorySetpoint = None
        if self._desired_position is not None:
            ts = TrajectorySetpoint(
                timestamp=int(self._current_tick.nanoseconds / 1000),
                position=[self._desired_position.x, self._desired_position.y, self._desired_position.z],
                yaw=-3.14
            )
        elif self._desired_velocity is not None:
            ts = TrajectorySetpoint(
                timestamp=int(self._current_tick.nanoseconds / 1000),
                velocity=[self._desired_velocity.xv, self._desired_velocity.yv, -self._desired_velocity.zv],
                position=[None, None, None],
                acceleration=[None, None, None],
                jerk=[None, None, None],
                yaw=0.0,
                yawspeed=self._desired_velocity.yaw_v
            )

        if ts is not None:
            self._trajectory_setpoint_pub.publish(ts)

            self._offboard_mode_pub.publish(OffboardControlMode(
                timestamp=int(self._current_tick.nanoseconds / 1000),
                position=self._desired_position is not None,
                velocity=self._desired_velocity is not None
            ))

```

---

<div class="post-metadata">

**Author:** ![Benja](https://discuss.px4.io/user_avatar/discuss.px4.io/benja/32/11872_2.png) [@Benja](https://discuss.px4.io/u/Benja)\
**Post date:** [December 18, 2022, 6:19pm UTC](https://discuss.px4.io/t/offboard-mode-set-velocity-not-working/30104/4 "2022-12-18T18:19:17Z")

</div>

> [@elanius](#):
>
> So what is a proper way to set `yaw`?

I’m not sure I understood. Do you want to control the `yaw` value or the `yawspeed`? Try `yaw=None` in the second scenario.

> [@elanius](#):
>
> Are there some sources which describe this? Or do I have to read the code of PX4 autopilot?

I red the code 😅

---

<div class="post-metadata">

**Author:** ![elanius](https://discuss.px4.io/letter_avatar_proxy/v4/letter/e/db5fbb/32.png) [@elanius](https://discuss.px4.io/u/elanius)\
**Post date:** [December 18, 2022, 9:36pm UTC](https://discuss.px4.io/t/offboard-mode-set-velocity-not-working/30104/5 "2022-12-18T21:36:37Z")

</div>

`yaw=None` is not working because there is a check for float value. Therefore, it must be set as a float.

I need to control yawspeed the same way I control the velocity of `xv` and others.  
My goal is to implement teleoperation. So when I press some key drone should move according to this key. It is working for x, y and z. But controlling rotation is not working. When I press, e.g. left arrow key drone turn round but only to a fixed value. It doesn’t continue in rotating. I think the absolute yaw value is considered, and a drone spins only to this value and not further, even though the key is still held.

---

<div class="post-metadata">

**Author:** ![Benja](https://discuss.px4.io/user_avatar/discuss.px4.io/benja/32/11872_2.png) [@Benja](https://discuss.px4.io/u/Benja)\
**Post date:** [December 19, 2022, 1:58am UTC](https://discuss.px4.io/t/offboard-mode-set-velocity-not-working/30104/6 "2022-12-19T01:58:18Z")

</div>

You could check how the `position` mode is implemented: from RC to setpoints for the position controller module, after all in position mode the the RC controls the yawrate.

Or, do something like `yaw = yaw + yawspeed * controllerSamplingTime`

---

<div class="post-metadata">

**Author:** ![elanius](https://discuss.px4.io/letter_avatar_proxy/v4/letter/e/db5fbb/32.png) [@elanius](https://discuss.px4.io/u/elanius)\
**Post date:** [December 20, 2022, 2:26pm UTC](https://discuss.px4.io/t/offboard-mode-set-velocity-not-working/30104/7 "2022-12-20T14:26:59Z")

</div>

I did it as you suggested. So now my teleoperation code works.

---

<div class="post-metadata">

**Author:** ![Benja](https://discuss.px4.io/user_avatar/discuss.px4.io/benja/32/11872_2.png) [@Benja](https://discuss.px4.io/u/Benja)\
**Post date:** [December 22, 2022, 9:23pm UTC](https://discuss.px4.io/t/offboard-mode-set-velocity-not-working/30104/8 "2022-12-22T21:23:07Z")

</div>

Great!  
Please, mark the post as solved then 😊
