Design of Rolling Ball Control System Based on Image Recognition

Aiming at the problem of light interference affecting image recognition, this paper designs a rolling ball control system based on image recognition. The system consists of the main controller Mega 2560, OpenMv image processing module, steering gear execution module, display module, and mechanical structure test bench. The system realizes that the small ball only relies on adjusting the tilt of the flat plate, completes the function of auto-interference, and quickly restores a stable static state. The system has good stability. The use of image recognition to identify and locate the ball has a good effect, and the control effect of the PID control algorithm on the ball has been debugged to achieve a good effect of stability, smoothness and high accuracy.


Introduction
The combination of image recognition technology and automatic control system has now been widely used in intelligent robots, as well as some automatic control sites that use image processing. Since the image recognition process is easily affected by light changes, the accuracy of image recognition affects the control accuracy of the control system. Aiming at the problem of light interference affecting image recognition, this paper designs a rolling ball control system based on image recognition. The research content of this system involves image processing, automatic control, motion control, machine vision, etc. Its theoretical results can be widely used in practical engineering applications such as industry, agriculture, and aerospace, so its research has far-reaching significance. At present, the research of rolling ball control system mainly focuses on trajectory tracking algorithm.

Overall system design
This design includes the main controller module, image processing module, display module, button circuit, power supply module and mechanical mechanism, etc. The overall system design scheme is shown in Figure 1.
When the information of temperature, humidity and smoke concentration exceeds the normal range, the buzzer alarm system is activated, and the indoor environment is controlled automatically by the switching state of the corresponding devices of heating, cooling, dehumidification, fan and window. The system uses relays to simulate the switches of various household appliances, and keys to set the range of temperature and humidity.
In addition, the LED lamp is used to simulate the indoor lighting, and the human infrared sensing module and keys are used to control the working status of the LED lamp. The overall design block diagram of the system is shown in Figure 1.
Arduino Mega 2560 is the main controller of the rolling ball system. It needs to receive the coordinate position of the ball from the OpenMv-H7 module, and then perform PID calculation on the position and speed of the ball to obtain the output that controls the rotation of the steering gear, and then control the rudder The machine rotates; at the same time, the button status is scanned in real time, and the main parameters are output to the display screen. The OpenMv-H7 module mainly performs real-time image recognition and coordinate positioning of the ball, and at the same time transmits the recognized ball position to the Arduino Mega 2560 controller. The Mega 2560 controller combines the position information of the ball and uses the PID algorithm to adjust the rudder Machine output; control the tilt of the plate through the transmission mechanism to complete the purpose of controlling the staying position and movement trajectory of the ball. The steering gear and the connecting components are combined to form a transmission mechanism, which converts the rotation angle of the steering gear into the inclination degree of the plate, and controls the staying position and movement track of the ball by controlling the tilt of the plate. The button circuit is an external input, which plays a role of on-site adjustment, adjusting the parameters of the system and switching operation modes. The display shows the main parameters, and the power module provides stable power for the control chip and the steering gear.

Main controller
The main controller of the system uses the Mega 2560 of the Arduino microcontroller series. This microcontroller has high performance and low power consumption, rich I/O ports and expansion functions, fast running speed, simple programming, a large resource library, and easy to use. As the main controller, the Arduino Mega 2560 plays a major control role in the entire system. It needs to scan the trigger status of the button circuit in real time, drive the OLED display to output key information, receive coordinate information from the OpenMv-H7 camera module, The PID algorithm calculates the deviation of the position and speed of the ball, and controls the rotation of the two steering gears. The I/O port wiring diagram of the main controller and each module is shown in Figure 2.

Image processing module
The image processing module adopts the OpenMv-H7 camera of Xingpu Technology, which is a module dedicated to visual inspection and image processing. It takes the STM32H7 chip as the core, integrates the OV7725 camera chip, has its own IDE compilation environment, and uses efficient and simple python language programming, making it fast and efficient in image processing algorithms. In this design, its main task is to capture an image through a camera, and perform a colour block recognition algorithm on the captured image to identify the goal of the ball. On the other hand, mark the centre position of the ball, and continuously obtain the relative position of the ball on the tablet by establishing a plane coordinate system in the acquired image field of view, and transmit the position coordinates of the ball to the Mega 2560 controller through the serial port.

Display module
The display module uses a 0.9-inch OLED display, which is a display made of organic light-emitting diodes, which has the characteristics of high contrast, thin thickness, and fast refresh rate. The module is available in three colours: single white, single blue, yellow and blue. The screen resolution is 128*64, driven by the 4-wire serial SPI protocol. In the rolling ball control system, the display module needs to display key information, such as the current operating mode, timing time, adjustment parameters, etc. Although SPI communication is used, only the module needs to output the display data, without reading the data. Driven by SPI protocol, fast data transmission and stable image display.

Display module
The button module is the input adjustment link of the system, and has the function of adjusting the system function parameters on site. This time the button uses a touch button, the circuit is a matrix button with 2 rows and 3 columns, and the 6 buttons are respectively connected to the digital I/O ports 43, 45, 47, 49, 51, and 53 of the main controller as the system enter. One of the buttons is responsible for switching the operating mode, one button controls the start and stop of the steering gear, and the remaining 4 buttons correspond to the functions of the corresponding operating mode, which play the role of on-site adjustment of system operating parameters and control of the movement of the ball.

Power module
In terms of power supply, a 12v large-capacity lithium battery is used to step down to 5.5V to power the two steering gears separately. The purpose is to avoid excessive current generated by the steering gear when reversing, causing the current to flow back and burning the controller chip. , Arduino controller and OpenMv camera use USB port to provide 5V power supply. This time the step-down module uses the HW-316E adjustable step-down stabilized power supply module. The module has a current of up to 5A and a power of up to 75W. It is equipped with a digital tube pressure measuring circuit, which can display the input voltage or output after the step-down in real time. The voltage value is easy to view and provides a guarantee for the power supply of the steering gear.

Mechanical structure
In terms of mechanical structure, two square acrylic plates with a side length of 20cm are placed in parallel, and the height difference is 15cm. The installation position of the two steering gears and the support rod in the centre of the plate form a three-dimensional coordinate system, using a universal joint and the upper plate Fixed connection, using a combination of bearings and connectors to convert the rotation angle of the steering gear into the inclination angle of the X-axis and Y-axis of the plate.
Seven circular areas are evenly distributed on the used plate, each area is a circular area with a diameter of 4 cm, and the number corresponds to 0-6. The distribution map of each area on the plate is shown in Figure 3.
By establishing a plane rectangular coordinate system on the image screen captured by the camera, the position coordinates of the center of each circular area on the tablet can be obtained, as shown in

Programming
The colour of the camera is used to identify the position information of the ball and send it to the main control module to determine whether the position of the ball is consistent with the expected position. If the desired position is not reached, the PID algorithm is used to control the rotation of the steering gear so that the ball enters the desired position quickly and stably. The system program is written in modularity, and the system flowchart is shown in Figure 5.

Conclusions
The design is mainly composed of the main controller, camera module, display module, and power supply module. The software and hardware tests have been completed to realize free control of the stay position and movement trajectory of the ball, and the expected goal of the design has been achieved. This design is a combination of image recognition technology and control system. Many of the algorithms involved provide certain research value for machine vision processing and balance control, and can be widely used in practical engineering applications such as industry, agriculture, and aerospace.