01 Intelligent Transport
01 Intelligent Transport
In this section, miniAuto will use the ESP32-S3 vision module to recognize and
follow the red line. If a green block is detected, the miniAuto will transport it.
1. Program Flowchart
1
process the image and transmit it to other devices through I2C communication.
3. Program Download
3.1 ESP32-S3
1) Connect the ESP32-S3 to the computer with a Type-C cable.
2) Open the file “flash_download_tool_3.9.7.exe” stored in the “2.Software
Tools/4.Firmware Flashing Tools”.
3) Select the Chip Type as ESP32-S3, keep other settings unchanged, and
then click “OK”.
After opening the tool, click to select the program’s bin file. Then, follow
2
4) Select the COM port number corresponding to the port occupied by the
vision module in the device. Do not select COM1, or the firmware may fail to be
flashed.
5) Click "ERASE" first to erase the previously downloaded firmware. This step
is essential. Then, click "START" to download the newly selected firmware.
3
6) Wait for the download to complete.
The Bluetooth module must be removed before downloading the program, otherwise
Please turn the switch of the battery box to “OFF” when connecting the Type-B
download cable in case the download cable touches the power pin of the expansion board
2)Connect the Arduino to the computer with the UNO cable (Type-B).
3)Click the “Select Board”, and the software will automatically detect current
Arduino serial interface. Then click to connect.
4
4)Click to download the program to the Arduino, and then wait for the
download to complete.
4. Program Outcome
After powered on, the miniAuto will recognize and follow the red line. If the
green block is detected during the line following, it will transport the block.
5. Program Analysis
The name of this program is “clear_roadblock.ino”. The implementation logic of
the program can be referred to the following flowchart:
5
5.1 Import Library File
Import the necessary timer, tracking action, servo control, motor, and ESP-S3
vision module communication header files for the game.
The calibration parameters for line loss is used to record the position of the
block. This facilitates the judgment and processing when the line is lost. The
line coordinate parameters store the coordinate values of the line. The
obstacle coordinate parameters store the coordinate values of the block.
6
5.3 Initial Settings
1)Initialize related hardware equipment in “setup()” function. The first is serial
interface, which sets the baud rate of communication to 115200.
2)Initialize each module. Timer1 starts counting with a single time unit of 20ms.
1. “ticksFuncSet(ticksGetFunc)”: Binds the system's preset function
“ticksGetFunc” which is for obtaining the current system time to the
“platFormTicksFunction” function. The “platFormTicksFunction” function is
called to obtain current system time.
2. “Motors_Initialize()”: Initializes the motors.
3. “hw_cam.Init()”: Initializes the ESP32-S3 vision module.
4. “Controller_Init()”: Initializes the computing unit for the robot’s motion control
parameters.
5. “myServo.attach(servoPin)”:Initializes the PWM servo.
6. “set_servo(60)”:Sets the servo angle to 60.
7. “timerStart(&timer1, 6000, timerPIDCalculateCallBack, "60ms cycle PID
calculate")”: Timer1 starts working. The callback function
“timerPIDCalculateCallBack” is triggered and called 60ms later. It passes
"60ms cycle PID calculate" as a parameter to the callback function.
7
5.4 Loop Call Sub-function
After initialization is complete, the program enters the “loop” function. The
"timersTaskRunning" function is called in a loop. It traverses and processes the
timers in the timer list that have reached their trigger time. The interrupt
functions are executed.
Then, the “Velocity_Controller(set_angle, set_speed, set_rot,
SIMULATE_PWM_CONTROL)” function is called to control the robot's
movement speed.
It judges the recognized color. If the line is recognized, it will perform line
following and save the line coordinate to a variable.
8
If an obstacle is detected, it will stop line following. Start timer2 to transport the
block.
If the car is currently in the transport state, it may deviate from the line. The
position needs to be corrected to make the car return to the line.
9
5.7 Position Calibration Callback Function
“timerPositionCalibrationCallBack”
The “Linepatrol_Data_Receive” function is called to obtain the color
information recognized by the visual module.
Otherwise, execute the position calibration callback task. Judge the saved
block position to set the corresponding line speed, angular velocity, and motion
angle. Then, restart the position calibration callback task until the line is
recognized again.
This function is used to initialize the motor pins. Call the “pinMode” function in
a “for” loop to set the motor IO port to output mode. Then, the
“Velocity_Controller” function is called to set the robot to stop.
10
5.9 Robot Velocity Control Function
The function sets the speed of each wheel of the robot. By analyzing the
kinematics of the robot's Mecanum wheels, the speed of each wheel can be
calculated. The calculated speed variables can be used as input parameters
for the “Motors_Set” function to adjust the motor speed and control the overall
movement of the robot. Please refer to relevant tutorials to learn about
kinematic analysis.
11
5.10 Motor Setting Function
This function adjusts the speed and direction of each wheel of the robot based
on the input parameter values. In the “for” loop, the robot's steering is adjusted
based on the calculated results. The “map” function maps the calculated
values from “0 to 100” to the range of “pwm_min to 255”. Next, the “digitalWrite”
and “analogWrite” functions sets the motor direction and speed.
6. FAQ
Q:Since the code was upload, the color can not be recognized.
A:Please check that you have connected the 4-pin cable to the I2C
interface.
Q:Why is the color recognized by the camera inaccurate or even incorrect?
A:Please try to minimize the complexity of the background. You can use a
single color or a simple environment as the background.
12