Enabling the control of altitude with joystick while being in follow me mode

Hi everyone !

I control my quadcopter with a joystick and I would like to have the control of the altitude (only Z channel) while being in follow me mode. I think it is possible since the yaw is still available in follow me mode so why not the altitude !

So first thing first I tried to do it in guided mode since follow me is based on guided.

Here’s what I wrote in guided :

if (!copter.failsafe.radio)
{
// get pilot desired climb rate
target_climb_rate = get_pilot_desired_climb_rate(channel_throttle->get_control_in());
target_climb_rate = constrain_float(target_climb_rate, -get_pilot_speed_dn(), g.pilot_speed_up);
pos_control->set_pos_target_z_from_climb_rate_cm(target_climb_rate);
pos_control->update_z_controller();
}

I copied/pasted that under each “// get pilot’s desired yaw rate” I found in the guided mode code, I declared “float target_climb_rate = 0.0f;” each time and I thought it would be okay. I thought that since it worked for yaw it would also for altitude.

At the beginning of the simulation I had the control of altitude and it seemed to be fixed

BUT

when the copter is close to the destination the code stops reading my altitude command and go to the destination’s altitude.

I am wondering if I should set the target’s altitude as the current altitude but I don’t know how to do this.

Does anyone has ideas on how to do this ? Or maybe there is a parameter to set somewhere that already allows this ?

Thank you advance for your patience and ideas. I appologies in advance for my mistakes in english.

Here is an idea.
Leave the firmware as it is.
Read the channel (which corresponds to your joystick input) and set the FOLL_OFS_Z parameter with it (of course needs some mapping :slightly_smiling_face:).
You can do this on a companion computer or with Lua scripting (I am suggesting this).
Although I never tried to set it on the flight, it will most probably work (it will be updated immediately).
You can try it in simulation first.

1 Like

First thank you for your quick answer !

I didn’t understood everything so I’ll try to follow,
image

I am in channel 4 for Z, so I’ve set the FOLL_OFS_Z = 4.

I didn’t know what was lua scripting, I’ve typed it in internet and understood that lua scripting was a programing language and I discovered the online site to try codes. How can I use it ? I’ve seen on the ardupilot website that I will have to add a Lua script on my APM.

Before, going with Lua, I ran my simulation again and did’nt see any changes, is it normal ? Is there anything else to set before ?

Because, …

FOLL_OFS_Z=4 means that follow leader vehicle with 4 meters less altitude relative to leader’s altitude. You need to programmatically change that.
Here is the lua script docs:
https://ardupilot.org/copter/docs/common-lua-scripts.html

Okey I’ll try this…

Thank you !

Well it took me some time but I finally feel confortable with lua and ardupilot sitl environment !

Now I wrote the script you advised me to :

“gcs:send_text(6,” !!! STARTING LUA SCRIPT !!!")

duree = 0
val = 5

function update ()
– on commence par lire le mode en cours :
if vehicle:get_mode() == 23 or vehicle:get_mode() == 4 or vehicle:get_mode() == 9 then
rc4 = rc:get_pwm(4)
gcs:send_text(6, "Mode guidé ou follow avec rc4 = " … rc4)
if rc4 > 1600 then
val = val + 1
if val > 100 then val = 100 end
param:set_and_save(“FOLL_OFS_Z”, val)
gcs:send_text(6, "PARAM FOLL_OFS_Z Set to " … val )
elseif rc4 < 1400 then
val = val - 1
if val < - 100 then val = 100 end
param:set_and_save(“FOLL_OFS_Z”, val)
gcs:send_text(6, "PARAM FOLL_OFS_Z Set to " … val )
end
end

return update, 1000
end

return update, 1000
"

However It is not working. I then realized that it was the foll_ofs_z that is not taken by arducopter… I opened an issue yesterday about this “Foll_ofs_z in follow not working with copter” so if you have an idea it would be nice.

Also I found your github about pymavlink and it helped me a lot so I wanted to thank you personally for this ! I can’t wait for you to share the lua codes for all you plan to share.

Thank you again for your help

Open your issues in here: Issues · ArduPilot/ardupilot · GitHub

1 Like