Editing WPNAV_SPEED Parameter Midflight with LUA Scripting?

I am trying to edit WPNAV_SPEED parameter mid-flight to control aircraft speed during waypoint and survey missions however it seems to not work.
I am able to edit LOIT_SPEED mid-flight and changes have immediate effect. I can see the aircraft is slowing or speeding up as my lua script changes the parameter. I tried to debug it by using param:get() function and it seems like lua script is actually changing the wpnav_speed parameter but changes doesn’t take any effect on the actual speed. On arducopter 4.1.0 it says changing WPNAV_SPEED param now takes immediate effect. What am i doing wrong?

That is a missing feature, you will need to wait until it gets implemented.

Thank you for letting me know. Is there any other way to slow down the aircraft during waypoint missions? I’m trying to slow down the aircraft by reading distance data from a custom sensor through lua scripting. As it approaches towards an obstacle, i want aircraft to gradually slow down.

If you want the vehicle to slow down while on an auto mission, you can probably do a “set_item” mission command DO_CHANGE_SPEED from a lua script. I have never tried this before but should work hopefully

Inserting a DO_CHANGE_SPEED mission item works, but it’s very clunky

Recommend the vehicle:set_desired_speed() binding.

1 Like

I dont really know how binding works. But i guess it requires me to build the ardupilot code?

I couldn’t find any documentation on how set_item works. Can you explain it a bit more? I’m quite new to ardupilot and lua.

No, you don’t have to do any of that. In your script, wherever you want to change the speed, simply insert a line that looks like this (this example would change the speed to 2.5 meters per second):


1 Like

Less elegant, but might get you by in a pinch, is you can use the transmitter tuning function. Transmitter Based Tuning — Copter documentation

Set TUNE, 10 (WPNAV_SPEED), and then TUNE_MIN and TUNE_MAX to your speed range (in CM/S, so M/S x 100). You can then use RC6 on a slider or pot to manually adjust the speed of the drone during missions.

Thank you so much! I will try that tomorrow and let you know.

I’m trying to make distance sensor do all the hard work for me. Using transmitter defeats the purpose.


Does this binding works with arducopter 4.2.2? And is there any difference between set_desired_speed and set_speed_xy?

Not sure where you’re seeing set_speed_xy() as a Lua function, but set_desired_speed() works in 4.2.

1 Like

Have done some flight tests today (arducopter 4.2.2 running on cubeOrange) and wanted to share the results. You actually can change the wpnav_speed parameter during flight. I uploaded a lua script that runs every 10 seconds and changes wpnav param from 5m/s to 1m/s and i was actually able to see it changing the parameter and the effects immediately. vehicle:set_desired_speed(speed) also works. Aircraft performs extremely well during loiter mode but it still performs quite badly during auto mode i later discovered rangefinder readings was extremely sluggish during auto mode.I’m trying to find out why and any help is appreciated! It still works in auto mode but aircraft is unable to slow down in time since rangefinder readings doesn’t work the way i want it and sometimes rangefinder doesn’t see anyting at all. I know my sensors are sending data because i have a bluetooth module connected to the sensor that sends distance data to my phone. I will be uploading my log files tomorrow, i dont have access to the aircraft right now.

1 Like