Setup "Plane Follow" in ArduPlane

I am using master version of Ardupilot, I used mav_sysid of target plane 11 and then foll_sysid of 11 in follower plane
Whenever I start the script using rc 7 2000. It start showing these messages.

@timtuxworth Sir please help, followed all your methods, it has been three days to make it working

After consulting with ChatGPT I removed this concatenation, just one line. Still when I start the script it doesnot follow vehicle 11 (target). It first says LOST, then keeps on repeating - no target 11
What could be the issue, What am I missing to make it working

Whole procedure is described below

python3 ~/leader_follower/ardupilot/Tools/autotest/sim_vehicle.py -v ArduPlane -I 0 --sysid 11 --console --out=udpout:127.0.0.1:14550 (Target)
python3 ~/leader_follower/ardupilot/Tools/autotest/sim_vehicle.py -v ArduPlane -I 1 --sysid 12 --console --out=udpout:127.0.0.1:14550 (Follower)

(SCR_ENABLED
FOLL_ENABLED
FOLL_SYSID 11
set some offsets)

Console Window of Follower Plane
Mode INITIALISING
AP: Barometer 1 calibration complete
AP: Barometer 2 calibration complete
AP: Airspeed 1 calibration started
AP: ArduPilot Ready
AP: AHRS: DCM active
AP: PID Controller 4.7.0-001 module loaded
AP: MAVLink Attitude 4.7.0-009 module loaded
AP: Throttle failsafe off
Time has wrapped
pre-arm fail
Mode MANUAL
AP: Airspeed 1 calibrated
Got COMMAND_ACK: SET_MESSAGE_INTERVAL: ACCEPTED
AP: GPS 1: probing for u-blox at 230400 baud
AP: GPS 1: detected u-blox
AP: EKF2 IMU0 MAG0 initial yaw alignment complete
AP: EKF2 IMU1 MAG0 initial yaw alignment complete
AP: EKF3 IMU0 initialised
AP: EKF3 IMU1 initialised
AP: EKF3 IMU0 tilt alignment complete
AP: EKF3 IMU1 tilt alignment complete
AP: EKF3 IMU0 MAG0 initial yaw alignment complete
AP: EKF3 IMU1 MAG0 initial yaw alignment complete
AP: EKF2 IMU0 tilt alignment complete
AP: EKF2 IMU1 tilt alignment complete
Got COMMAND_ACK: SET_MESSAGE_INTERVAL: ACCEPTED
AP: EKF2 IMU0 origin set
AP: EKF2 IMU1 origin set
AP: EKF3 IMU0 origin set
AP: EKF3 IMU1 origin set
AP: Field Elevation Set: 584m
AP: EKF3 IMU0 is using GPS
AP: EKF3 IMU1 is using GPS
AP: AHRS: EKF3 active
pre-arm good
Flight battery 100 percent
AP: Plane Follow 4.7.0-073 script loaded

AP: AHRS: EKF3 active
pre-arm good
Got COMMAND_ACK: COMPONENT_ARM_DISARM: ACCEPTED
AP: Throttle armed
AP: Armed AUTO, xaccel = -0.0 m/s/s, waiting 0.2 sec
AP: Triggered AUTO. GPS speed = 0.0
ARMED
Arming checks disabled
AP: Takeoff to 50m for 200.0m heading 353.0 deg
AP: Autoland direction= 353
AP: Plane Follow 4.7.0-073 script loaded
height 17
Got COMMAND_ACK: DO_SET_MODE: ACCEPTED
Mode GUIDED
height 28
Got COMMAND_ACK: REQUEST_MESSAGE: ACCEPTED
AP: EKF2 IMU0 is using GPS
AP: EKF2 IMU1 is using GPS
Got COMMAND_ACK: REQUEST_CAMERA_INFORMATION: UNSUPPORTED
AP: PFollow: enabled
AP: PFollow: lost prior target
AP: PFollow: no target
AP: PFollow: follow failed for sysid 11.0

Setting up 2 vehicles in SITL can be tricky, especially if you want them to have different parameters (for this you do) but also communicate with each other. There may be better ways, but here’s how I do it:

  1. create separate directories for each plane (I call them plane1 and plane2)
  2. create a script for each plane that will start a different instance of arduplane in each directory
  3. create a scripts directory in plane1 → this is where you copy the plane_follow.lua and it’s modules
  4. when you start the arduplane instances you need to make sure they can communicate with each other by passing –serial0 mcast: to both of them
  5. then after you start both copies of ardupilot, I start mavproxy.py to communicate with each vehicle.

I think there might be a way to do this using the –instance option to sim_vehicle.py, but I use this way to get it to work for me.

So I have a script to start plane1, something like this dual_plane1.sh:

cd $ROOTDIR/plane2

PLANE_DEFAULTS="$ROOTDIR/Tools/autotest/models/plane.parm"

$ROOTDIR/build/sitl/bin/arduplane  --instance 1 --model plane --serial0 mcast: --defaults $PLANE_DEFAULTS


Then a script to start plane2 something like this dual_plane2.sh:

cd $ROOTDIR/plane1

PLANE_DEFAULTS="$ROOTDIR/Tools/autotest/models/plane.parm"

$ROOTDIR/build/sitl/bin/arduplane --instance 2 --model plane --serial0 mcast: --defaults $PLANE_DEFAULTS

Then I have a. “master” script that starts the 2 planes and runs mavproxy. Something like this:

# assume we start the script from the root directory of the git clone we are using

export ROOTDIR=$PWD

PLANE=$ROOTDIR/build/sitl/bin/arduplane

WINDOW=$ROOTDIR/Tools/autotest/run_in_terminal_window.sh

($WINDOW ArduPlane1 dual_plane1.sh) &

($WINDOW ArduPlane2 dual_plane2.sh) &



mavproxy.py --retries 10 --console --map --master=tcp:localhost:5772 --out=udp:localhost:14551 --out=udp:zenbook-ts:14550 --streamrate=-1

I adapted my code from the example of setting up 2 vehicles for aerobatics which you can find in git under libraries/AP_Scripting/applets/Aerobatics/FlxedWing/RateBased

Once you have the two vehicles running you can switch between them using mavproxy using the “vehicle” command … “vehicle 11”, “vehicle12” … where the 11 and12 are the MAV_SYSID of the vehicle to connect to.

Hope this helps.

1 Like

Looking at what you’ve done here, this might work, but you have a problem with your –out on both vehicles is using the same port which for sure won’t work.

2 Likes

Instance argument shifts ports by 10.

3 Likes

@timtuxworth First of all Thank you very much sir for helping, by following your steps I do able to enable Follow mode

(Target: 11, Follower: 12)

Now its just That I am unable to follow my target plane, I didn’t understand what could be the reason
When I write link in follower plane, it only show 1 link, Do I need to have 2 links?
Can you check what could be wrong, I can paste whatever you need to debug

Initial starting Windows

Follower Plane Parameters

Link to the video: What happens when I enable the script

1 Like

I don’t know why this happens, but you need to leave the “vehicle x” set to the follow vehicle. I guess this is 12 in your example.

If you set vehicle to 11, 12 will stop following in SITL. If you set vehicle 12, then the follow will start following. This doesn’t happen in the real world, only in SITL. You can change the direction of vehicle 11 by switching to it but always switch back.

If you don’t want to have to keep switching back and forth, put a mission on vehicle 11 and set it in auto mode.

Also - no need to set Vehicle 12 to guided. the script (rc 7 2000) automatically sets the vehicle to guided.

Other than that - it looks like you have everything right. Yes you only have one link, thats correct and actually important because it means the mcast: is working. If you had 2 links the vehicles would not be communicating.

I did not know that - that explains a lot, thanks!