Using rangefinder and optical flow

In the docs about optical flow, it’s suggested that a rangefinder and LOITER be used instead of Optical Flow.

I have a HereFlow I’d like to incorporate on a copter. I also have a LightWare LW20 on the shelf.

Since the LW20 has a short range lidar, I’m not exactly sure what the is being recommended.

Should I install both my HereFlow and LD20 - facing the LD20 downward - and then use LOITER?

If I do this - will ArduCopter somehow incorporate the optical flow data with GPS to loiter at a fixed position? If this is true - what parameters are required? And can I assume that indoors, with no GPS signal, optical flow will still provide position data in LOITER mode?

Or since the HereFlow has a short range lidar - is the LD20 necessary at all?

Or if a rangefinder and LOITER is recommended - is the HereFlow necessary at all?

I’ve been told that the HereFlow does an excellent job. I don’t recall if the doc and video mentions the optical flow sensor being used that doesn’t perform well. Maybe the HereFlow resolves that issue.

Here’s a link to the doc I’m referring to. FlowHold Mode — Copter documentation

The rangefinder of the hereflow is only good until 2m indoors. Outdoors you maybe get a reading until 30cm, so it is not useful for outdoor computation of flow data. Definitely use the Lightware and just forget about the sensor on the Hereflow.

When setting up the hereflow the important thing is to log some data and make sure flowX follows IMUgyroX and for Y the same. It is easy to get the orientation of the flow sensor wrong.

FlowHold mode works for me and its impressive to see a position hold only from the flow sensor. In this mode it optically senses height and does not use rangefinder data. So the performance is very limited.

Loiter fuses flow data and rangefinder data, no need to do much further. So the flow data improves position estimates in conjunction with a good rangefinder, especially if GPS signal is not good.

1 Like

This is really helpful. Especially about the orientation. I just found the orientation info in the CubePilot docs. Here Flow - CubePilot

What procedure do you recommend for logging and checking the IMUgyroX and Y values?

Regarding loiter - that makes sense - but there’s no documentation about it that I’ve ever found. Randy MacKay’s video and notes in the ArduCopter docs on optical flow, makes mention of using Loiter - but doesn’t have the detail you’ve provided here.

Let me check please, to see if I understand the situation properly:

  1. Using the HereFlow and LD20 lidar, the ArduPilot will somehow merge the two lidar inputs - or maybe just ignore the lidar from the HereFlow.

  2. With a HereFlow and LD20 installed, then LOITER will automatically use the optical flow data for staying in position in the horizontal plane.

  3. With a HereFlow and LD20 installed, then FLOW-HOLD - will work using HereFlow input only - with it’s associated limitations.

Do I have this about right?

Two more questions if I may -

  1. Do you know if Loiter will use the LD20 lidar to help maintain vertical position?
  2. The docs for the LD20/lidar note a parameter for distance from the sensor to the ground - which can be useful for precision landing. Do you know if some similar parameter has to be set for the HereFlow?

Thanks a million Snakeeater! I’ll report back when I get it hooked up to let anyone who’s interested how things work out.

1 Like

I got the orientation according to the doc wrong, probably because the sensor is upside down. For me the main CAN connector is facing to the right side of the vehicle with the lens facing down. Then you can just start logging and tilt the copter back and forth in the x axis and then in the Y axis, then download the log, graph IMUgyroX and flowX and flow should track gyro and not be inverted or something. If its inverted turn the sensor 180 degrees. If X is tracking Y then turn the sensor 90 degrees and try again until it is right.

The term LD20 is not very clear, lets refer to the hereflow rangefinder as TOF and the other one is the Lightware LW20 or so. The third thing we kind of have is an arbitrary visual altitude estimate from the optical flow sensor itself.

For x/y flow data to be useful you always need a correct distance information which the flow data refers to. Only then it can be used for navigation.

In FlowHold the ragefinders are not used. It uses visual altitude information which is not very precise and usually not used in other flight modes like Loiter. FlowHold is more of a demo-mode I think, practically you can forget about it.

In Loiter outdoors the hereflow TOF sensor could probably only aid to check if the coper is on the ground or not. It will neither be useful to enable flow calculation, nor as an altitude source. So it is insufficient and should be deactivated by simply not reading its information if any better rangefinder is available.

Instead you should use a good rangefinder like the Lightware. In its practically effective range of for example about 50m the coper can compute the flow data with it. It will also use it as a vertical position source and aid with the on-ground detection. All that happens automatically once the sensors are installed and enabled.

According to my understanding, for precision landing some other hardware like IR beacon is needed plus a rangefinder to detect touch-down. This auxiliary function is what the doc refers the hereflow TOF to be useful for.
The flow sensor + rangefinder as mentioned above will definitely improve position during landing. However, it is not not a precision landing system, since it does not store a picture during take-off and later returns to exactly the same picture.

1 Like

Snakeeater -

My bad - indeed, the rangefinder on my shelf is a Lightware LW20/C - I feel like a moron for calling it a “LD20” - sheesh.

I’ve been going over the parameters in the docs for both the HereFlow and the LW20/C. Combined with your help - it’s starting to make sense.

One big note: The CubePIlot docs don’t include the numeric identifier for multiple rangefinders. Their docs state “RNGFND_xxx” instead of “RNGFNDn_xxx” where “n” is the numeric identifier for each rangefinder.

If I’m not going to enable the HereFlow’s rangefinder, maybe this identification doesn’t make any difference. As I read the docs, to enable the HereFlow, all I need to set are two parameters:

CAN_P1_DRIVER, 1 (to enable CAN bus)
FLOW_TYPE, 6 (specifies that the optical flow sensor as UAVCAN)

By not setting RNGFNDn_TYPE, RNGFNDn_MAX_CM and RNGFNDn_MIN_CM for the HereFlow, I’m guessing lidar on the HereFlow is simply ignored.

To enable the Lightware LW20/C, the docs say I need the following parameters:

RNGFNDn_TYPE, 7
RNGFNDn_ADDR, 102 (the default I2C address)
RNGFNDn_SCALING, 1 (no reason stated)
RNGFNDn_MIN_CM, 5
RNGFNDn_MAX_CM, 9500
RNGFNDn_GNDCLEAR, (set to cm from sensor to ground)

Notes and questions:

  1. There is a parameter RNGFND_FILT that’s set on my copter to “0.5”. This parameter with a range of 0 to 5 sets rangefinder smoothing. Without a rangefinder identifier, it appears to apply to all rangefinders on board. I have no idea why the default value of “0.5” is set.

  2. There are numerous rangefinder parameters that don’t appear until at least one rangefinder is enabled. For example: RNGFNDn_FUNCTION. (linear, inverted, hyperbolic). The docs explain most of these parameters pretty well. But I have no clue what the difference between these three values might be. And there are other parameters that are dependent on this setting. The default values are probably OK - but it would be helpful to have more information.

  3. I’m guessing that with the HereFlow’s lidar dis-abled, there’s no problem setting up the LW20/C as rangerfinder “1”. I’m wondering if I could set it to “2” anyway - in case at a later date I want to activate the HereFlow lidar.

That’s enough from me for now. I’d appreciate any comments this generates. I’d get my sensors installed and try them - then report back with success - or questions.

Thank you!

1 Like

I think you are on the right track and all will be clear soon. In the firmware you can enable several Rangefinders, that’s where the numbers come from. But in your case you will only use one. You could assign any rangefinder to any slot.
There are some rangefinder parameters you can set for each sensor in case your rangefinder is analog. If your rangefinder returns a digital reading, then no need to care about those.
The downward facing rangefinder will be the “sonar” used for flow. Others can for example be used as proximity sensors in other directions.

RNGFND_FILT will smooth the desired sonar altitude DSalt if I understand this parameter correctly. Somebody may correct me if I’m wrong about this.
However the effect will be that the copter doesn’t make an altitude jump every time it flies over a small obstacle. So setting this low will let the copter try to follow every up/down detail of the terrain aggressively. Setting it higher will delay altitude adjustments a bit and make the copter follow terrain more gradually and smoothly. This you need to test according to your terrain and liking.

2 Likes