Follow mode, loiter with IRLock

I configured a cube orange on a quad with IRLock, beacon on the ground and lidar. IRBeacon is mounted on a rover driving around, the quad is supposed to follow. It works. But I experiebce the quad making drasric moves when the rover is moving. So seems that PID tuning is to improve. The quad itself flyes very good. What parameters do I have to change that the quad is moving, following smooth?

A few questions. First, how fast is the rover moving? Second, at what rate would you estimate the locations updates are reaching the copter?

If you have a rover or other target moving at roughly walking speed (1-2 m/s) and you have a copter following it in Guided mode with a cruise speed set to substantially higher than that and your location-update rate is around 1Hz, then the copter will tend to jerk as it moves, since it’s essentially cruising to the new location from its current location at its configured cruise speed and acceleration settings. At best, you’ll see a visible “twitch” as the copter follows. At worst, it looks ridiculous as the copter flails around.

A trick to make this smoother is to flood the copter with very tiny location updates when following at low speeds. I have some code in place that sets a 20ms timer. It receives location updates from the source at whatever input rate (eg 1Hz). Each update, it remembers the last location it had and computes the heading from the last one to the current one, and the speed (distance from last to current/time since last location). It generates a string of location updates from the last location to the current one at 50Hz along the heading from last-to-current such that the jump distance for each one is what it would be if locations were arriving at 50Hz (20ms timer handling location updates at 1Hz). It’s essentially predicting the path of the target based on where it’s known to be currently going and how fast. This results in a ton of really tiny updates of a few cm each. These are sent to the copter, which follows. Since the rate is so high, the copter doesn’t have time to accelerate toward the new location before it gets another location and heads toward that one. The effect is that at low speeds (slow walking, etc) the copter will float along at the desired speed without jerking. The fact that it’s having location updates shoved down its throat at fire-hose rates isn’t noticeable. If the target changes heading, there will be a short pause (interval is whatever the real location update rate is) before the copter changes direction to follow. In that instance, sometimes it will jerk, but it’s better than doing so constantly. This approach works at higher speeds as well, since the generated locations are more “spread out” as the target speed increases. The “Follow me” code in Solex works like this. When you turn it on you can see the blue “I am here” marker on the map, and there’s also a black one that follows the same path, but more smoothly. That’s the one being updated by the code I describe above, and it’s these locations which are being sent to the vehicle.

A variant of this can be seen in the Solo’s follow code, if memory serves. It works.

Hi, what parameters can we adjust in the pixhawk or IRlock to achieve this?

The rover is controlled manually and is going really slow.
I would like to avoid having additional code as it is always a pain when updates come up. Aren’t there some parameters to check and to adjust?

I have done this before (drone following a person holding a beacon) and it worked well with Copter 3.5.7. I did not have to make any adjustment to parameters. Are you using PLND_EST_TYPE = 1 or 0?

PLND_EST_TYPE is set to 0 (Raw Sensor)

You should be able to make the position corrections less aggressive by changing the Position Control parameters:
PSC_POSXY_*
PSC_VELXY_*

Also, if you are using Precision Loiter mode, then the Loiter parameters might also affect it (not sure):
LOIT_ACC_MAX
LOIT_BRK_*

Probably the most important parameters are PSC_VELXY_*. You might only need to change these.

These are PIDs that is set for PSC_VELXY_*. Should I follow the PID tuning method to change the paramters?

PSC_VELXY_D 0.5 0.00 1.00
PSC_VELXY_D_FILT 5 Hz 0 100
PSC_VELXY_FILT 5 Hz 0 100
PSC_VELXY_I 1 0.02 1.00
PSC_VELXY_IMAX 1000 cm/s/s 0 4500
PSC_VELXY_P 2 0.1 6.0
PSC_VELZ_P 5 1.000 8.000

Try cutting VELXY_P and VELXY_I in half. That will probably produce a noticeable effect and will give you an idea if changing these parameters is the right thing to do.

Hi, So I tried reducing the PSC_VELXY_P and I values in small steps almost to the lowest possible values. The jerk movements were less but only for a brief moment and after couple of seconds they appear again. Increasing them from the default values made it worse. I have uploaded the log files of the flight. Any suggestions?

https://drive.google.com/drive/folders/1ORaoWPaoc-Cj9CT1lQQkH4XibHhy6hHO?usp=sharing

Thanks

Does the jerky motion only happen when the beacon is moving, or does it also happen when the drone starts following a stationary beacon?

The jerk happens when the copter is following the beacon. We saw that when beacon is stationary and the copter is just hovering on top of it, it wobbles(like an untuned copter). When the precision loiter is deactivated on the switch then it is steady again.

I see the problem. It’s your rangefinder.

Your rangefinder outputs a distance of 5 meters most of the time when your copter is flying much higher than that. This means the copter thinks it needs to roll/pitch more to move over the beacon because the angle between the drone and beacon is larger. But because the distance is wrong, it overshoots the roll/pitch angle and rolls back, resulting in oscillation:

Fix your rangefinder and this problem should go away.