Abstract: Motion control of mobile robots mainly involves controlling the robot's motion platform and providing a control method. This paper studies mobile robots and implements the design of an ultrasonic ranging module based on the time-of-flight method, providing a simple and convenient obstacle distance detection solution for the robot. This paper primarily focuses on the design of the main control board controller software, the motor drive controller software, and the ultrasonic ranging software, enabling the development system to serve as a general development platform for mobile robot research.
Keywords : robot; motion control; software design; ultrasonic ranging
Intermediate Classification Number : TP 9 Document Identification Code: B
0 Introduction
With the rapid development of technologies such as computers, networks, mechatronics, information, automation, and artificial intelligence, mobile robot research has entered a new stage. Simultaneously, the development and utilization of space and marine resources provide vast opportunities for the development of mobile robots. Currently, research in fields such as intelligent mobile robots and unmanned autonomous vehicles has entered the application stage. As research deepens, higher demands are being placed on the autonomous navigation capabilities, dynamic obstacle avoidance strategies, and obstacle avoidance time of mobile robots. Path planning for ground-based intelligent robots is a crucial component of fully autonomous robot systems operating in complex and dynamic natural environments, and the research on fully autonomous technology for ground-based intelligent robots across all terrains is a challenging problem facing the academic community both domestically and internationally.
Intelligent mobile robots are a type of robotic system capable of sensing their environment and their own state through sensors, enabling autonomous movement towards targets in obstacle-filled environments to perform specific functions. Mobile robot technology research integrates technologies such as path planning, navigation and localization, path tracking, and motion control. It involves various external sensors, including distance detection, video capture, temperature and humidity sensors, and audio-visual sensors, which serve as input information for the mobile robot. Motion control of mobile robots primarily involves establishing the robot's motion platform and providing a control method. A high-performance mobile robot motion control system is the foundation for mobile robot operation and serves as a general development platform for mobile robot research.
Mobile robot technology research integrates knowledge from multiple disciplines, and key technologies can be categorized into path planning, navigation and localization, path tracking, and motion control. Path planning can be further divided into global and local path planning. Global path planning involves planning a path based on the overall task of the mobile robot, decomposing the overall path task, and establishing a global terrain database. Local path planning involves planning feasible paths in real time based on the sub-tasks decomposed from the global plan and the current state information of the mobile robot. Navigation and localization technology determines the position of the mobile robot on the global map and obtains the relative positional relationship between the robot and path tracking in real time. Its key technology is multi-sensor information processing and data fusion. The task of path tracking and motion control technology is to control the mobile robot to follow the path given by local planning, combining the robot's own state information and road information obtained by the navigation and localization system to complete heading and speed control. The path planning, navigation control, and path tracking and motion control technologies of mobile robots are interconnected; imperfections in any system will lead to a decline in overall performance.
1. Main Control Board Software Design
The main control board hardware handles module management, device communication, and robot positioning pulse detection. In practical applications, the main control board hardware also manages the ultrasonic ranging software.
Of the main control board hardware, only the main control board controller requires software design. The primary task of the TMS320LF2407A main control board controller is the software design and management of ultrasonic ranging, along with other basic settings, including orthogonal encoder pulse detection for the motor encoder. The TMS320LF2407A was initially selected as the main control board controller because this control system can serve as a platform for future robot applications. Real-time systems can be embedded into the TMS320LF2407A to improve system performance and facilitate interface development.
The software design of the main control board controller includes module initialization, serial communication, orthogonal encoded pulse detection, and ultrasonic ranging software. This section describes module initialization, serial communication, and orthogonal encoded pulse detection. Figure 1 shows the flowchart of the main control board controller program.
Figure 1 Flowchart of the main control board controller program
The reset vector address serves as the program entry point, followed by program initialization. Initialization includes basic configurations such as extension mode, overflow mode, DARAM, frequency multiplication, and JTAG. It also includes settings for relevant I/O, timers, interrupts, and serial communication. These configurations constitute the basic configuration flow used by the controller. After initialization, the relevant interrupt routines are enabled, followed by the ultrasonic ranging program, which loops continuously. The interrupt service routine is in a ready state and executes immediately upon the occurrence of an interrupt.
In all programs for the TMS320LF2407A, the serial port data transmission and reception procedures need to be explained. Asynchronous communication uses three lines (ground, transmit, and receive) to connect to a terminal using RS-232 format. Each transmitted bit consists of a start bit, 1 to 8 data bits, an optional parity bit, and 1 to 2 stop bits. Therefore, the maximum data unit that serial communication can transmit is 8 bits, or one byte. In the design, the controller and each terminal will exchange various types of data, such as integer data and floating-point data, so data conversion is required for the serial port transmission and reception.
For data transmission of four-byte single-precision floating-point numbers, since the serial port can only transmit one byte at a time, it's sufficient to convert each four-byte floating-point number into byte form before sending. This is achieved using type casting in the design. The same approach can be used for data reception, simply by reversing the conversion. Alternatively, unions can be used for data conversion. The essence of a union is the same as the type conversion described above, except that all data types within a union share the same storage space. Any structure type variable defined within the union can access this storage space. This method is used for serial port data processing in the host computer, and it's very convenient.
For the detection of orthogonal encoded pulses, the TMS320LF2407A has an independent orthogonal encoded pulse unit. With simple settings of the unit registers, the running direction and distance parameters of the robot's drive wheels can be obtained. The TMS320LF2407A sends this data to a host computer via serial port. The host computer then models and processes the data to obtain the robot's pose information.
2 Motor drive software design
The motor drive software handles motor drive control and closed-loop speed regulation. Drive control utilizes the on-chip PWM peripheral unit of the STC12C4052AD motor drive main control chip. The generated PWM signal drives the motor through the motor drive chip. The duty cycle of the PWM signal can be adjusted to regulate the duty cycle of the 24VDC voltage applied to the motor, thereby regulating the motor speed. The PWM duty cycle is controlled by an on-chip 8-bit PWM control register, with a value range of 0-255, representing the continuous change of the PWM signal duty cycle from 1 to 0. Simultaneously, the STC12C4052AD receives pulse signals from the motor's photoelectric encoder, calculates the motor speed using its on-chip clock, and completes closed-loop speed regulation of the motor through a speed control algorithm.
The flowchart of the motor drive and closed-loop speed control software algorithm is shown in Figure 2.
Figure 2 Flowchart of the motor drive controller program
As shown in the diagram above, the program begins with initialization, which includes defining relevant variables, setting registers such as 10ms Timer 0, Timer 1, serial port, external interrupt 0 for pulse counting, and watchdog timer, and initializing motor status parameters (brake, speed). Then it enters a loop, updating the relevant flags in the watchdog register during the loop. Speed detection and closed-loop speed control are completed in external interrupt 0 and Timer 0, respectively. The interrupt service routines thus include external interrupt 0, Timer 0, and the serial port interrupt service routines.
External interrupt 0 is a pulse detection peripheral for the motor's photoelectric encoder. All pulses from the motor's photoelectric encoder will trigger an interrupt in external interrupt 0. The principle of encoder pulse speed measurement is to calculate the number of pulses within a unit time interval of the STCl2C4052AD. Therefore, the interrupt service routine for external interrupt 0 is simply to count the pulses. The target motor speed set by the host computer will also be converted into the number of pulses within this unit time interval. A global variable can be defined, and this variable can be incremented by 1 each time external interrupt 0 is entered. Furthermore, to prevent program interference, the count value should be corrected, such as setting it to 0 when it is less than 0, and setting it to a certain set value when it is greater than a certain set value.
3. Ultrasonic ranging software design
The ultrasonic ranging software in the design utilizes the commonly used time-of-flight method in ultrasonic ranging. The working principle of the time-of-flight method is to start timing simultaneously with the transmission of ultrasonic waves and stop timing upon receiving them, recording the transmission time of the ultrasonic waves as t. The distance s between the ultrasonic ranging module and the obstacle is then expressed by the following formula.
S=v*t/2
Where v is the speed of sound in air, expressed by the following formula.
Where T is the Fahrenheit temperature of the air.
At room temperature, the transmission speed of ultrasound does not change significantly with temperature, and the transmission time of ultrasound is in the millisecond range, so the impact is not substantial. However, a temperature correction module can be added to the ultrasonic ranging module to detect the ambient temperature and then correct it when the main control board calculates the ultrasonic speed. Integrated temperature detection devices are already available on the market, which is quite convenient.
The main process of ultrasonic ranging is as follows: after transmitting an ultrasonic wave, if a reflected ultrasonic signal returns, the distance is calculated by external interrupt 0. Simultaneously with the ultrasonic signal transmission, timer 3 is started, with a timing period equal to the transmission time required for the maximum ultrasonic measurement distance. If no external interrupt 0 event occurs by the timer 3 interrupt (i.e., no reflected ultrasonic signal returns), then the ultrasonic return interrupt and ultrasonic transmission timer 1 are disabled upon entering the timer 3 interrupt cycle, and the next ultrasonic ranging loop begins. The program flowchart is shown in Figure 3.
Figure 3. Flowchart of ultrasonic ranging procedure
If external interrupt 0 receives an ultrasonic ranging signal, it enters the external interrupt 0 service routine to process the ranging procedure. If no ultrasonic signal is returned, a timer interrupt will occur on timer 3, indicating a timeout. The system will then set the ranging range to be free of obstacles. Both scenarios will trigger a change in the waiting flag, causing the program to exit the waiting state, switch to the working ultrasonic ranging module, and proceed with the ranging process of the next ultrasonic module.
The program flowcharts for external interrupt 0 and timer 0 are shown in Figure 4.
Figure 4. Flowchart of External Interrupt 0 and Timer 3
Figure A shows the flowchart of external interrupt 0. Entering the interrupt service routine indicates the return of an ultrasonic signal. The program begins by disabling all maskable interrupts and distance measurement peripherals, reading the Timer 1 count value, and calculating the obstacle distance. The program loop flag is changed, and then the interrupt service routine returns. Figure B shows the flowchart of Timer 3. Entering the interrupt service routine indicates the absence of obstacles within the distance measurement range; therefore, only maskable interrupts and distance measurement peripherals need to be disabled, the program loop flag changed, and the interrupt service routine exited. Setting Timer 1 to not generate an interrupt, and setting Timer 1 to its maximum value, will not trigger a Timer 1 interrupt. Therefore, it is unnecessary to write an interrupt service routine for Timer 1.
4. Conclusion
This main control board coordinates the work of the host computer and various modules. The software design details the data type handling issues in serial port transmission. A pulse width modulation signal is generated using a microcontroller's PWM peripheral to drive the motor, and closed-loop speed control is achieved through an optical encoder. Ultrasonic ranging modules have wide applications; the software program for this module uses the common time-of-flight method to measure distance and uses analog switches to enable time-sharing operation of multiple ultrasonic ranging modules.