### Getting information out of the /scan topic

I would like to know the distance to the nearest obstacle in 8 wedges around the robot, i.e. N,E,W,S,NE,NW,SE,SW. My robot is a Turtlebot3 with just a Lidar but this question is general.

What I've done so far to see how far it gets is taking the mean value in each of the wedges and treating that as the distance of the nearest obstacle. So essentially for each scan I get back 8 numbers. I ignore values that are below or above the respective thresholds as well as infinity and NaN.

This is not good enough because of severe noise in the results of the scan (or bugs in my code. For now I am assuming noisy sensors.)

In consecutive scans I may get radically different vectors of 8 values (fake example data following:)

```
[0.5, 0.4, 0.3, 1.2, 1.3, 1.4, 2.0]
[2.5, 1.4, 0.3, 1.3, 2.3, 1.4, 2.0]
```

Now remember that each of those numbers is a mean of 360/8 Lidar Readings. So there is some smoothing based on angle already happening. But it looks like I need smoothing over time too. Before I go reinventing the wheel I am looking for advice.

There's a nice laser_filters packages which looks very relevant but I am not sure its what I ~~need. ~~need.

### Followup

An idea suggested below by @Geoff goes like this:

- Compute the vector of 8 values at time t. This can be done by for example taking the median +/- std dev or just the average of values in the second and third quartile.
- Have time based filter by having a simple sliding window average or do something fancier with a Kaman filter.

Thoughts?