-
Notifications
You must be signed in to change notification settings - Fork 509
Implemented use of optical flow for terrain estimation #597
Conversation
EKF/terrain_estimator.cpp
Outdated
} | ||
|
||
// Calculate observation matrix for flow around the vehicle y axis | ||
float Hy = -vel_body(0) * t0 /((_terrain_vpos - _state.pos(2)) * (_terrain_vpos - _state.pos(2))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard against division by zero
Replay log for flat terrain: Replay log for flight over hill: NOTE
|
c8fe96d
to
b9f909b
Compare
This is a replayed log file of when the plane was flying over a hill: |
EKF/terrain_estimator.cpp
Outdated
@@ -55,7 +55,10 @@ bool Ekf::initHagl() | |||
_terrain_var = sq(_params.range_noise); | |||
// success | |||
return true; | |||
|
|||
} else if (_flow_for_terrain_data_ready) { | |||
_terrain_vpos = _state.pos(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a guess unless we are on the ground. Might be better to set to height of origin as that is where terrain is most likely to be after takeoff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If on ground, using current position is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// rotate into body frame | ||
Vector3f vel_body = earth_to_body * vel_rel_earth; | ||
|
||
float t0 = q0*q0 - q1*q1 - q2*q2 + q3*q3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which derivation did you use to obtain this? If you have a Matlab file, add it here and provide a link to it in the documentation: https://github.com/PX4/ecl/tree/master/EKF/matlab/scripts/Terrain%20Estimator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@priseborough I added a python folder which has the script for the derivation.
float Hx = vel_body(1) * t0 /(pred_hagl * pred_hagl); | ||
|
||
// Cacluate innovation variance | ||
_flow_innov_var[0] = Hx * Hx * _terrain_var + R_LOS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add protection against Hx * Hx * _terrain_var being less then zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many places in code that touch _terrain_var and it is not forced to the non-negative immediately prior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
float Hy = -vel_body(0) * t0 /(pred_hagl * pred_hagl); | ||
|
||
// Calculuate innovation variance | ||
_flow_innov_var[1] = Hy * Hy * _terrain_var + R_LOS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add protection against Hy * Hy * _terrain_var being less then zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_terrain_var being protected against being negative above so should be OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Signed-off-by: Roman <[email protected]>
Signed-off-by: Roman <[email protected]>
…rain height estimation) Signed-off-by: Roman <[email protected]>
@priseborough I addressed your comments. |
This PR allows optical flow measurements to be used for terrain estimation. I see the following two cases when this could be useful:
@priseborough already did this in another project and I believe he had good success with the pmw3901 optical flow sensor.
Flow measurements will only be fused in the terrain estimator if no range data is being fused and if the primary EKF is not fusing flow.
So far this has only been tested in SITL using iris_opt_flow model. Two logs are being provided, one where the terrain estimate is initialized to 50m on the ground in order to see if the filter recovers.
The second log shows a normal flight in position control over a flat surface. As the vehicle starts to move the terrain height becomes observable and the estimated terrain variance decreases. When the vehicle holds position the terrain variance increases again.
Terrain initialized to 50m
Normal flight over flat ground
Logs:
Terrain initialized to 50m:
https://logs.px4.io/plot_app?log=e47c69ed-125c-4a82-a1df-dc0553904b63
Normal flight:
https://logs.px4.io/plot_app?log=a3864090-d60c-42af-8fc8-f8465ded7790
How to test:
Currently this feature can only be tested if optical flow in the main filter is deactivated and if no range data is available. Therefore, the following two steps are required for testing:
Required action items: