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 !