Intelligent toy car design based on optical sensors
2026-04-06 07:45:08··#1
Intelligent robots are increasingly widely used in today's society. From ordinary toy robots to industrial control robots, from robots that can cook to robots that can explore space, it is foreseeable that the applications of intelligent robots will become even more widespread in the future. Everyone is familiar with ordinary wireless remote-controlled cars, and everyone finds Nintendo's Wii video games amazing. The common problem is that familiar things aren't fun, and amazing things are too expensive to play. This design takes a completely new approach, creating an intelligent car that can be played with in daily life, to satisfy readers with similar interests. System Overall Design The principle of the intelligent car system is that a three-dimensional coordinate sensor is installed on the car, giving it intelligent sensing capabilities, allowing it to move in the same direction as the target object. The system mainly consists of three components: First, a 3D coordinate optical sensor (ETOMS-ET21X111) is used to collect the movement coordinates of the target object; this sensor is very easy to use. Second, an MCU (EMC-EM78P156) reads the sensor data to control the motor rotation. The EM78P156 is a common MCU on the market, easy to use and inexpensive. Third, the motor; a regular DC motor can be used, controlled by PWM. The overall system framework is shown in Figure 1. Figure 1: Overall System Framework. In short, the overall function of this design is to allow the car to follow a person (or a target object). Specifically, it needs to achieve the following three functions: First, the sensor must correctly read the X, Y, and Z coordinate values; this is the primary condition. Second, the MCU must correctly determine the magnitude changes of the X and Z coordinate values; this is crucial. Some may wonder why the Y coordinate change isn't considered. This is because the car cannot jump up and down (the vertical axis is the Y-axis). Third, the MCU controls the motor's direction and PWM timing based on the coordinate value changes; this is the result. Hardware System Design 1. Sensor Peripheral Circuit Design The ETOMS-ET21X111 is a high-performance optical sensor with X, Y, and Z coordinate data output capabilities. It features: high-speed data output, up to 75 frames per second; low-voltage operation, voltage range 2.7–3.5V; standard RS232 serial data output format; external crystal oscillator, range 0.5–12MHz, typically 3.58MHz; and controllable exposure interfaces EO4–EO7. These four interfaces are used for exposure control, which can be implemented via software or hardware. The appropriate interface should be selected based on your needs. This design uses hardware to set all four interfaces to high level. The detailed interface circuit of the sensor is shown in Figure 2. As shown in Figure 2, EO4–EO7 are high, indicating that the exposure setting is hardware-pulled high, but it can also be set in software. When the IC is working normally, the coordinate data is output from the RS232 port. Note that the four LEDs in Figure 2 are infrared LEDs. The IC operates at 3.3V, while the system uses a 5V power supply. The IC uses a 3.58MHz external crystal oscillator and automatically resets upon power-up before commencing normal operation. Figure 2 shows the sensor interface circuit. 2. MCU Interface Circuit Design: The detailed design of the MCU peripheral control circuit is shown in Figure 3. In Figure 3, L and L+ control the PWM of the left motor, and R and R+ control the PWM of the right motor. RS232 receives sensor coordinate data input. The IC operates at 3.3V and automatically resets upon power-up. The system clock uses a 4MHz external crystal oscillator. Figure 3 shows the MCU interface circuit. 3. Left Motor Control Circuit: The left motor control circuit is shown in Figure 4. The right motor control circuit is the same as the left. Q3 and Q4 in the figure use PNP transistors. L and L+ cannot be both LOW simultaneously to avoid short circuits. Figure 4 shows the left motor control circuit software system design. After the system powers on, initialization is performed first, setting the registers of the EMC78P156, enabling the interrupt flag register, and waiting for interrupts. Figure 5 is the main program flowchart. [IMG=Main Program Flowchart]/uploadpic/THESIS/2007/12/20071205171229947643.jpg[/IMG] Figure 5 Main Program Flowchart When an interrupt occurs, the interrupt handling subroutine is entered. First, the interrupt flag is turned off and the context is saved. Then, the XYZ coordinate values are read and parsed, and divided into the following cases. (1) Determine the change in the X-axis. If the X value is greater than 14 and less than or equal to 17, the motor does not rotate left or right. Then determine the change in the Z-axis coordinate value. If the Z value is also greater than 14 and less than or equal to 17, the motor does not rotate forward or backward. (2) If the X-axis coordinate value is greater than 17, determine the Z-axis coordinate. If the Z value is greater than 17, the right motor is reversed, and then the left and right motors rotate backward. If the Z value is less than 14, the left motor rotates forward, and then the left and right motors rotate forward. Otherwise, the motor does not rotate. (3) If the X-axis coordinate value is less than 14, determine the Z-axis coordinate. If the Z value is greater than 17, reverse the left motor, and then the left and right motors rotate backward; if the Z value is less than 14, rotate the right motor clockwise, and then the left and right motors rotate forward; otherwise, the motors do not rotate. The flowchart of the interrupt handling subroutine is shown in Figure 6. Figure 6 Flowchart of interrupt handling subroutine Design Tips 1 Sensor Design Tips The ET21X111 has the best spectral response to infrared light, but natural light contains a large amount of infrared light, so strong natural light will affect the sensor data, resulting in a large deviation between the output coordinates and the actual coordinates. The solution is to add a filter, but this can only play an attenuation role, and the specific application depends on the situation. 2. Motor Control Circuit Design Techniques: When designing the circuit to control the forward and reverse rotation of the motor, pay attention to the following: Because the I/O state is uncertain when the MCU is powered on, the program should set both I/Os of Q3 and Q4 to HI (if Q3 and Q4 are PNP transistors, set them to LOW if they are NPN transistors) at the beginning to prevent both I/Os from being LOW when powered on, causing Q3 and Q4 to conduct and form a short circuit. Also, note that only one of Q3 and Q4 can be conducting at any given time. 3. MCU Design Techniques: When a brushed DC motor starts or rotates, it generates significant power glitches. This is very detrimental to the MCU's operation, so an LCπ-type filter circuit is added, as shown in Figure 7. Figure 7: Filter Circuit 4. Programming Techniques: During the operation of the intelligent car, it needs to read coordinate data from the sensors while controlling the motor's PWM output. The sensors output coordinate data every 12ms, so the best approach is to use interrupts to read the sensor data and perform PWM output during the periods when there is no data output.