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.

1 Like