How to control thrust or flight velocity?

I want to be able to slow down or speed up during flight using PX4. Is there any implementation for that? This gives clue but a python implantation would be helpful.

Hi @mtawfiqc ,
Do you really want to use offboard for this? Otherwise you can use MAVSDK to send a MAV_CMD_DO_CHANGE_SPEED MAVLink command.
See Missions · MAVSDK Guide

@bresch Thanks for the comment. Does your comment mean this mavlink command cannot be used in offboard mode?

Hi @bresch,

As you propose, I’m currently using the MAV_CMD_DO_CHANGE_SPEED to control the airspeed of a glider. At the moment, I’m not restricting the frequency of speed change request. I was wondering if the MAV_CMD_DO was compatible with high frequency request?

When using offboard, that command is ignored because you’re in charge or sending the setpoints to the controllers; so just send the desired velocity if you want to use offboard.

To be clear:

  • offboard: you design the trajectories and send the setpoints
  • not offboard: the autopilot generates the setpoints based on the mission waypoints and follows the desired speed set by MAV_CMD_DO_CHANGE_SPEED or by default the cruise speed parameters

I don’t know, but it’s better not to send it too frequently to avoid overloading the link.

Thank you @bresch this is helpful:

Is there a way to control the drone’s speed when using position setpoints? Sometimes we want to fly to some lat, long, alt at a slow speed like 2 m/s.

And in my use case, we need the ability to quickly interrupt the drone’s motion. It might be flying to a “waypoint,” and some external information might arrive and the drone needs to immediately do something else (maybe it needs to stop or maybe it needs to calculate a brand new waypoint on the fly). We expect the drone to be “interrupted” often. And in case it’s generating its behavior on the fly, it will refine it’s behavior as it flies and gains information (some of this external information comes from another program or system).

Offboard mode seems like the best tool for this. With missions we’d need to build, upload, and start a new mission to invoke the novel behavior. This seems like a lot of overhead, when we’re making minor changes many times per second. With offboard mode, we can just send a new setpoint. And since the program sends setpoints many times per second, we just send our “best guess” for the waypoint. And we update what we consider our “best guess” as we go. Offboard mode seems like a good fit.

But if it’s not possible to set a speed, it seems like we will need to use velocity setpoints when far away and position setpoints when near the waypoint (so as to maximize the value we get from the flight controller). And we could do that. Though I want to make sure I’m not missing something because a parameter to control the speed would be great.

Either way, thank you for your helpful comments.

Is there a way to control the drone’s speed when using position setpoints?

Simply move the position setpoint at the desired speed towards the final goal and the drone will follow at the desired speed. Again, in offbard you have a lot of freedom and it is your task to generate the adequate trajectory; don’t send the final position to the controller (this produces a really jerky behavior), but design your own guidance algorithm to make the drone move the way you want.

That’s a great idea! Thank you. Yes, I suppose we could “animate” the position setpoint in time. That’s a powerful tool and it gives me lots of ideas for how I might draw out an exciting path for the drone to follow. It does feel like a lot of freedom now that you mention it. (Seems like the best mode on the system :laughing:).

Later this year, I might also want to do something like that with a fixed wing. Though I expect additional considerations will limit the kinds of paths we can fly. (trying to do this with a fixed wing seems like a big can of worms; but I haven’t tried anything yet).

Thanks again! This info is very valuable to me.

Thanks for the sharing.
For offboard and position,
Could I inquire whether we need to add as many waypoints as we can, when we want to fly at low speed?
On the other hand, if we wants to fly at high speed, we just set one destination waypoint. Then, the drone will arrive at the destination at the fast speed.

We find the python code (position control and yaw rate) in the Github: PX4-Autopilot/integrationtests/python_src/px4_it/mavros at main · PX4/PX4-Autopilot · GitHub

Because of the yaw rate control code, we are thinking whether there is position control with speed? Thank you very much

There is a good solution by a_jegourel.
He/She used MPC_XY_VEL_ALL (resp. MPC_Z_VEL_ALL) to set a limit to the maximum overall horizontal (resp. vertical) velocity.

import rospy
import mavros_msgs.srv

def set_horizontal_velocity(max_velocity):
    rospy.wait_for_service('/mavros/param/set')
    try:
        max_hor_vel = rospy.ServiceProxy('/mavros/param/set', mavros_msgs.srv.ParamSet)
        max_hor_vel(param_id="MPC_XY_VEL_ALL", value=mavros_msgs.msg.ParamValue(real=max_velocity))
    except rospy.ServiceException as e:
        print("Service max_horizontal_velocity (MPC_XY_VEL_MAX) call failed: %s" % e)

I have same problem with fixed wing in Gazebo. I would like to use in mission mode and control to flight speed. When I set speed on QGroundControl it is not taken into account.