Offboard Control using ROS2. How to achieve velocity control?

Goodmorning,
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;

offboard_control_mode_publisher_->publish(msg);

}

and then setting

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

trajectory_setpoint_publisher_->publish(msg);

}

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.

2 Likes

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.