Design and Implementation of a Line-Following Robot Based on DSP and Fuzzy Control
2026-04-06 08:32:45··#1
In recent robotics and electronic design competitions, many challenges require robots to move along white or black guide lines within a designated area. Some researchers have proposed line-following robot design strategies, primarily focusing on guide line detection, but without addressing the overall robot design. This paper, based on a summary of such competitions, proposes a general design method for a robot's walking mechanism that uses a DSP (Digital Signal Processor) and CPLD (Complex Programmable Logic Device) as the core processor and employs a fuzzy control strategy to process signals from guide line detection sensors. 1. Vehicle Body Mechanical Design Due to the strict size limitations imposed on participating robots in robotics competitions, it is necessary to rationally arrange various mechanisms within a limited space. This paper presents the relative positions of the drive wheels, photoelectric sensors, and control chip when the vehicle body is at its minimum size, as shown in Figure 1. The robot uses a dual DC stepper motor drive system with a rated voltage of 24V. Photoelectric sensor detection boards are installed at the front and rear ends of the vehicle body to detect the guide lines. The distance between adjacent photoelectric sensors is slightly less than the width of the guide line, ensuring that two sensors can detect the guide line simultaneously. 2 Hardware Circuit Design This section mainly introduces the connection between the core controller DSP and the function expansion chip CPLD, and briefly describes the hardware implementation of other functional modules. The overall system structure is shown in Figure 2. 2.1 Core Controller Design Currently, most robot core controllers use microcontrollers. Considering the long instruction cycle and limited available resources of microcontrollers, which make it difficult to meet the requirements of real-time robot control, the author, after considering factors such as cost-effectiveness and development cycle, selected TI's dedicated DSP for motor digital control—TMS320F240 (hereinafter referred to as F240)—as the core controller. It has a very effective event manager for motion control, including 12 compare/PWM channels, which can easily control the speed of DC motors; using its three on-chip 16-bit general-purpose timers that can work in six modes, it can complete the control of most robot movements; and 16 10-bit A/D converters can easily read analog signals. Since the return signal from the robot guide line detection module can be regarded as a feedback signal, a stepper motor is selected as the robot drive motor. By setting the F240 timer and outputting a set pulse signal through the I/O port, this signal drives the stepper motor to travel a set distance via the stepper motor drive circuit. The specific implementation is described in the software design section. Other on-chip I/O, PWM ports, and A/D converters of the F240 are all brought out with input/output lines for easy expansion. As can be seen from the characteristics of the F240, it can be used to implement complex control algorithms and perform complex robot motion control. However, according to the vehicle design scheme, 20 photoelectric sensors need to be installed on the vehicle, occupying 20 I/O ports of the controller. This significantly reduces the number of I/O ports available for expansion functions on the F240. Robots experience severe impacts during competitions, and designing various functional digital circuits would seriously reduce the reliability of the control board. Therefore, Altera's EPM7128 is selected as the core processor's expansion and fuzzy control input. To meet the collaborative processing requirements between the DSP and CPLD, the F240 and EPM7128 can be connected using the circuit shown in Figure 2. The 16 data lines of F240 and the 4 address lines A12 to A15 are connected to EPM7128. The read and write operations of EPM7128 are completed by the selection signal, write signal and read signal. The I/O ports of EPM7128 are mainly implemented by software and hardware pin settings in the MAX+PlusⅡ programming environment. This DSP+CPLD structure can fully expand the system functions while making the DSP more capable of its powerful computing function [4]. The voltage regulator circuit is mainly composed of LM7805 chip; the signal input circuit is sent to the DSP by micro switch through inverter 71HC14, the micro switch input circuit has decoupling circuit, and the output signal is added with pull-up resistor; the display module is driven by MAX7219 chip, eight-digit LED digital tube, each LED corresponds to three I/O ports. 2.2 Photoelectric detection module The function of the photoelectric detection module is to accurately detect the guide line. Here, the reflective optocoupler TCRT5000 is mainly used. This is a device with a built-in light-emitting diode and phototransistor. The relationship between its collector current Ic and the reflection distance d is shown in Figure 3. The application circuit of TCRT5000 is shown in Figure 4. When green ground is detected, due to low reflectivity, Ic1 is too small, transistor T2 is cut off, and a high level is output. When white ground is detected, due to high reflectivity, Ic1 is larger, transistor T2 saturates, and a low level is output, thus realizing the detection of white lines. A 555 timer forms a Schmitt trigger, used to remove noise generated by reflective optocouplers and to shape the waveform. 2.3 Motion Motor Control Circuit During the robot's line-following movement, specified actions need to be completed. The completion of these actions does not require controlling the speed of the corresponding motion motor. This paper directly uses I/O output control signals to drive solid-state relays, thereby causing the DC motor to move. The solid-state relay selected is a Panasonic double-pole double-throw (DPDT) type, model DS2Y-S-DC5V. Although this relay controls at 5V, which is compatible with TTL logic levels, the output current of a typical TTL chip is less than its input current of 40mA. An open-collector gate (OC gate) can increase the output current, and the input resistance at the two control terminals of the relay can serve as the pull-up resistor required for the OC gate output. Specifically, the ULN2003 chip with an OC gate structure is selected; it is a high-voltage, high-current Darlington driver composed of seven NPN Darlington transistors. Because each DS2Y-S-DC5V provides two normally open ports, connecting the positive terminal of the motor power supply and ground to the NO ports of the two sets of ports respectively allows two relays to control the forward and reverse rotation of the motor. Since the relay coil generates a large back electromotive force when switching voltages, a freewheeling diode needs to be added across the relay's voltage switching terminals to eliminate electrical sparks during switching, avoid large inrush currents, and reduce electromagnetic interference generated by the relay. 3 Fuzzy Control Strategy The design idea of the robot is to use photoelectric detection sensors to detect the size of the deviation of the vehicle body from the guide line and adjust the traveling speed of the left and right drive stepper motors so that the robot can travel along the guide line. This is exactly in line with the idea of fuzzy control [5]. The photoelectric detection sensors on the front and rear photoelectric detection boards are numbered, and the number of the photoelectric detection sensor with the largest number of the detected guide line is taken as the distance of the vehicle body deviation. The numbering method is shown in Table 1. In this way, the fuzzy controller has two inputs: the input number of the front and rear photoelectric detection boards; the fuzzy controller has two outputs: the number of driving pulses of the left and right stepper motors. The fuzzy subset of the linguistic value of the input quantity of the fuzzy controller is selected as: {LB, LS, ZO, RS, RB}. Wherein: LB = left large; LS = left small; ZO = center; RS = right small; RB = right large. The fuzzy subset of the linguistic value of the output quantity is selected as: {NB, NM, NS, ZO, PS, PM, PB}. Wherein: NB = negative large; NM = negative medium; NS = negative small; ZO = zero; PS = positive small; PM = positive medium; PB = positive large. Based on the definition and selection rules of membership functions, the membership degrees of the input variables, the front position iF and the rear position iB, are the same, as shown in Figure 5. The membership degrees of the output variables, the left wheel speed OUL and the right wheel speed OUR, are also the same, as shown in Figure 6. Based on multiple experiments and corrections, the left wheel speed control rule table is obtained as shown in Table 2 (the right wheel speed control rule table corresponds to the left wheel speed control rule table; for example, when iF is RB and iB is LB, the corresponding OUL is NB, and similarly, the right wheel speed control rule table can be obtained). Fuzzy inference uses the Mamdani method. Defuzzification uses the centroid method, ultimately yielding the left wheel speed control signal output table as shown in Table 3 (the right wheel speed control signal output table can be obtained using a similar method to the right wheel speed control rule table). Table 3 is stored in the F240 storage space in tabular form, and the corresponding output can be obtained based on the input. The acquisition of the above fuzzy signals is implemented using VHDL programming on an EPM7128. This part of the programming is relatively simple and will not be elaborated further. Since changes in the photoelectric sensor signal can be reflected in the CPLD output in real time, the F240 only needs to periodically read this signal and perform corresponding processing. Assuming the signals from the front and rear photoelectric detection boards are stored in the high and low nibbles of the RE_CPLD byte respectively, if these two signals are greater than 10, the original data remains unchanged; otherwise, the offset of this value in the speed control signal output table is calculated based on the signal magnitude: Where #04h is the page containing the tachometer, #MATRIXL is the offset of the tachometer's starting address within the page, and ADDER_PS is the offset of the lookup value relative to the tachometer's starting address. If the changed value obtained from the lookup table is saved as the period of a timer controlling the stepper motor's speed, the stepper motor's speed can be changed in real time: 4. Implementation of Stepper Motor Speed Control A stepper motor is a purely digitally controlled motor. It converts electrical pulse signals into angular displacement; that is, given a pulse signal, the motor rotates by a certain angle. The stepper motor controller's input ports are: VDD—motor power positive; GND—power ground; OPTO—common anode for control signals; DIR—motor direction control terminal; FREE—offline input terminal; CP—pulse input terminal (CP must be high to cut off the internal optocoupler when pulse application stops). Applying a high level to DIR here makes the robot move only forward; the program only needs to process the CP terminal. Pulse generation is achieved by controlling the level changes of the I/O ports. After setting various parameters for the timer interrupt, a flag word is continuously incremented by 1 in the timer interrupt handler. The walking distance can be set in the main program; the time interval of the timer interrupt determines the pulse frequency, which in turn determines the stepper motor's speed. Here, the value 2000 represents the robot's walking distance unit. By using a fuzzy control strategy, changing the timer period of the two stepper motors and the walking distance, the robot can achieve line-following movement. Based on a summary of recent participation in robotics and electronic design competitions, and addressing the common requirement of line-following robot movement, a robot implementation method based on DSP+CPLD and fuzzy control strategy is proposed. Robots designed using this method participated in various robotics competitions (such as the National Undergraduate Robot TV Competition, a sub-event of the Soccer Robot Competition, and electronic design competitions), performing well and achieving satisfactory results, thus verifying the effectiveness of this design. References 1 Xu Huan, Tang Jingxin. Modulated light line finding and its application in autonomous walking robots. Journal of Tsinghua University (Natural Science Edition), 2002; 42(1): 115-117 2 Wan Yonglun, Ding Jiexiong. A robot line finding control system. Journal of University of Electronic Science and Technology of China, 2003; 32(1): 47-50 3 TMS320C240X DSP Controllers CPU, System, and Instruction Set. Texas Instruments, 1997 4 Cao Weihua, Wu Min, Chen Xin. Design and implementation of a soccer robot car based on DSP control. Robotics Technology Application, 2002; 3: 19-21 5 Cong Shuang. Neural networks, fuzzy systems and their applications in motion control. Hefei: University of Science and Technology of China Press, 2001