Offboard Control using ROS2. How to achieve velocity control?

I am trying to achieve velocity control using ROS2. I have been trying to modify the offboard control example (this one: ROS 2 Offboard Control Example | PX4 User Guide, provided in px4_ros_com/src/examples/offboard/offboard_control.cpp), obtaining poor results.

As I have understood, it is possible to control velocity only while reaching the specified position. I don’t have problems in controlling the position.

I tried different approaches, as:

set only msg.velocity to true

void OffboardControl::publish_offboard_control_mode() const {
OffboardControlMode msg{};
msg.timestamp = timestamp_.load();
msg.position = false;
msg.velocity = true;
msg.acceleration = false;
msg.attitude = false;
msg.body_rate = false;



and then setting

void OffboardControl::publish_trajectory_setpoint() const {
TrajectorySetpoint msg{};
msg.timestamp = timestamp_.load();
msg.vz = -5.0;



However the quadcopter stops rising at a certain altitude, and I don’t understand why. Can someone help me? Thanks in advance.

In the end I solved the problem by setting msg.x, msg.y of TrajectorySetpoint equal to NaN, in this way I was able to control in speed.


can you share your complete example? i am trying to have both position and velocity control at teh same time, but cant seem to get it to work.

Have you found out how to do this? I’m trying right now to implement this on my project.

I would also like to see the example because I’m also trying this for some time.

How did you set NaN in the message?

Hi, for people that come across this question and don’t know how, you can set a value to NaN by using the C++ nan constant, or in Python using float("nan") (source).