- A laptop
- A camera with USB
- A tripod would be useful
We need to build a 2WD robot car that will be controlled by an esp32c6
- esp32c6 devkit (has a built-in ws2812 LED)
- One extra ws2812 LED
- Jumper wires
- A motor driver (TB6612FNG) capable of driving 2 motors
- Chassis and two wheels
- A power-bank to supply power
- Optionally a small breadboard
- Camera in a fixed position (tripod) is connected to the laptop via a USB cable
- Laptop acts as a hotspot that accepts connections from the esp32c6
- Robot lies on the floor and exchanges data with laptop
The goal is to make the robot orient itself and move on the floor from the data extracted from camera.
To do that we must locate the robot in the screen from the camera.
In order to locate the robot we are going to recognize the color of the LEDs. One LED at the front of the robot, one LED at the center of the robot.
This way we can have both orientation and location of the robot.
Then we need to find the world coordinates of the robot on the floor.
Having the coordinates we can use a control law to make it move as we like.
All calculations will take place on the laptop because it is easier to debug. The esp32c6 will simply take the result of the control law and apply the appropriate PWM on the motors.
Floor is the
Camera is at position
Positive
The unit vector at the direction the camera is looking is
It is meaningfull to assume
The principal point (center of the image plane) is
Having a point on the image plane and the vector
The unit vectors on the image plane in world coordinates are
In OpenCV the screen origin is at the top left corner, and positive y means going down on the screen. We need to bring the origin at the center of the screen and make y positive in the up direction, for convenience.
A pixel in screen
Where
Note that in real world this is not a linear transformation since the lenses distort the image. For simplicity we consider it to be linear and accept the fact that we will have some error.
Having the
The position of the camera
The line equation is
We need to find the
Turns out that
So the world coordinates on the floor are
Two constraints arise
$-v \cos{t}+ d \sin{t} \neq 0$ $\lambda>0$
The first one is obvious since a denominator cannot be zero.
The second one comes from the direction of the line.
Here
It might actually be
$\lambda>1$ since the object must be in front of the image plane.
It is easy to measure
We need to find appropriate values for