Electronic – Position of the LIDAR inside a box

raspberry pisensor

I am trying to get the position and uncertainty of my LIDAR sensor inside a box. For position: x, y values in mm and angle in degree, for uncertainty: σx, σy values in mm and σθ in degree. I am using RaspberryPi with RPLIDAR A2 and programming with C++. I want to get the position of the LIDAR inside the parent box.

Update 1: I am getting data (distance and angle) from the LIDAR and plotting in Matlab. But I need to find the position of the LIDAR in the box. I don't need exactly codes, just steps through it can help me.

Update 2: Here's the plot from Matlab (this reading isn't from inside a box though).enter image description here Currently the sensor is always at the center if I move it. I want to get the position of the sensor as the box is in a fixed position the thing moving is the sensor itself.

Best Answer

Ultimately, it's about maths, not Electrical Engineering.

So far as the LIDAR is concerned, it is at the centre of the universe, and it defines a zero degree axis. All the coordinates it returns are relative to that centre and that axis.

It probably returns polar coordinates (r, θ), where r is range and θ is angle relative to the axis. It should be a simple bit of trig if you would prefer them converted to (x, y).

Your task is to perform a rotation and translation on those coordinates to align them with what you have chosen to be the centre of the universe - the box. The tricky bit is working out what that translation and rotation is.

If you are in a box, you should find that the points neatly fall into straight lines. You will need to work out some way to determine which points are in which lines. Perhaps use a Hough transform. Or just pick a group of sequential points from the LIDAR and determine whether they are close enough to forming a straight line.

Once you know where the lines are, relative to the LIDAR, you can work out the rotation to turn the lines to where you want them, then the translation to move everything relative to the centre of the box.

Be aware that if the box is a simple rectangle or square, then there is always some ambiguity. If some sneaky person turns the LIDAR off for a moment, rotates the whole thing 180° and turns it on again, you will have no way to know.