Color tracking

Note: The virtual machine, ROS-wifi image transmission module and ESP32 communication board ROS_DOMAIN_ID need to be consistent, and both need to be set to 20. You can view [ESP32 communication board parameter configuration] to set the ESP32 communication board ROS_DOMAIN_ID, and view the tutorial [Connecting MicroROS Agent] to determine whether the ID is consistent.

Before running the experiment, please make sure that the microros balance car and ROS-wifi image transmission module have correctly enabled the agent on the virtual machine (linux with humbleROS2 system)

1. Program function description

MicroROS balance car color tracking has the ability to identify multiple colors at any time, and independently store the currently identified color, and control the car to track and detect the identified color left and right.

MicroROS balance car color tracking can also realize the function of HSV real-time control. By adjusting the high and low thresholds of HSV, the interfering colors are filtered out, so that the blocks can be identified in complex environments. If the effect of color picking is not ideal, the car needs to be moved to different environments for calibration at this time, so that it can recognize the color we need in complex environments.

2. Program code reference path

Mainly complete image processing, calculate the center coordinates of the tracked object, and calculate the car's movement speed data for the chassis based on the center coordinates and depth information of the tracked object.

3. Program startup

3.1. Startup command

Input in terminal,

If the camera image is inverted, you need to see 3. Camera image correction (select) document to correct it yourself, this experiment will not be described.

Taking tracking red as an example, after the program is started, the following screen will appear,

image-20240123183119781

Then press the r/R key on the keyboard to enter the color selection mode, and use the mouse to frame an area (the area can only have one color),

image-20240123183339911

After selection, the effect is as shown below,

image-20240123183443531

Then, press the space bar to enter the tracking mode, move the object slowly, and you can see that the robot will track the color block left and right.

Press the space bar to see the speed calculated by pid.

3.2, Dynamic parameter adjustment

image-20250110100942227

After modifying the parameters, click the blank space in the GUI to write the parameter value, and press the R key to take effect and reset. Or directly modify the source code, and then recompile and update. As can be seen from the above figure,

4, Core code

4.1, colorTracker.py

This program has the following functions:

Some core codes are as follows,