Pick to

With the development of microelectronics control technology and people’s growing demand for travel tools, a simple and easy to operate, easy to carry, clean pollution-free two rounds of the balance of the car began to come into the mind of the public, but this small transport is there may be some instability and potential safety hazard, this topic mainly by making a simple since the balance of the car in the laboratory, Through bluetooth control of mobile phone, real user driving experience is simulated to improve the stability of the balance car in the simulation experiment and solve possible practical problems. Finally, through the transformation of the self-balancing car system, the basic state control is realized, and it provides some experimental reference for the future use of other complex environment.

This graduate design do upright smart cars can be in the case of don’t need human intervention by PID algorithm, such as maintaining equilibrium state for a long period of time, at the same time can be controlled through corresponding bluetooth control APP, control motions including forward, backward, turn left, turn right and stop, with in turn prompts the buzzer and motion state indicator LED lights.

Key words: balancing vehicle; Bluetooth; PID; STM32

Vertical intelligent vehicle design

ABSTRACT

With the development of microelectronics control technology and people’s growing  demand for travel tools, a simple and easy to operate, easy to carry, clean pollution-freetwo wheels of the balance of the car began to come into the mind of the public, but   this small transport is there may be some instability and potential safety hazard, this   topic mainly by making a simple balance car by mobile phone bluetooth control in thelaboratory, in order to simulate real user driving experience, enhance the stability of thebalance of the car in simulation experiment, solving actual problems that may occur

finally, the basic state control is realized by reforming the self-balancing trolley system, and some experimental references are provided for its use in other complex           environments.

This upright smart car of graduate design can be in the case of don’t need human  intervention by PID algorithm to maintain equilibrium state for a long period of time, at the same time can be controlled by the corresponding bluetooth APP procedure control,including forward, backward, left, right and stop, with the buzzer that indicates a turn and indicator lights indicating the status.

Key word S: Balance car; Bluetooth; PID; STM32

directory

1 introduction… 1

1.1 subject background… 1

1.2 research situation at home and abroad… 1

1.3 research significance… 1

2 system overall scheme design… 3

2.1 design main work and basic requirements… 3

2.2 scheme comparison and selection… 3

2.3 system block diagram analysis… 5

2.4 system overall scheme design… 5

3  系统的硬件设计及系统流程………………………….. 7

3.1 single chip microcomputer control circuit… 7

3.2 the power supply module circuit… 8

3.3 motor driver module circuit… 8

3.4 other peripherals… 9

4 system software design and system… 13

4.1 the hypogyny machine program… 13

4.2 PC program… 16

Problems encountered in the development of five and drawing… 19

5.1 hardware problems and solutions… 19

5.2 a machine under development problems and solutions in the… 20

5.3 PC development problems and solutions in the… 21

6 the conclusion… 23

7 summary… 24

References… 25

Thank you… 26

The appendix… 27

1 introduction

As China’s rail transit and road traffic construction is becoming more and more perfect, people can choose more diversified modes of travel, as a new means of transport balance vehicle began to enter people’s vision. Compared with other means of transportation, the upright balanced vehicle is small in size, green, quick in response and flexible in movement, which is gradually favored by people. In addition to being a vehicle, the control algorithms and architecture of the upright intelligent vehicle can also be transferred to other types of robots, as the driving mechanism of the new robot, which can perform special tasks remotely in a much smaller space. The design takes the principle of inverted pendulum as the core, and designs a mini upright intelligent car that can keep balance for a long time. By simulating the real driving experience of users, it provides some reference significance for the development of manned balanced car in the future.

1.1  Project background

As a vehicle, the production process of the upright intelligent vehicle requires knowledge across many disciplines, including sensors, mechanics, control algorithms, filtering algorithms, communication technology and computer technology. As a branch of robot control field, its control scheme has a wide application prospect and has gradually become a research hotspot in universities and institutes at home and abroad. As intelligent vehicle is a comprehensive complex system integrating attitude calculation, behavior control and event processing [1], its development level can even serve as a reference for a country’s scientific and technological development level.

1.2  Research situation at home and abroad

In 1986, Professor Kazuo Yamto of the Department of Automation of Tokyo Telecommunications University designed a two-wheel car model. In order to ensure the center of gravity on the model, the chip and motor are put on the model, and the attitude detection and motor control are carried out through the gyroscope, and the simplest upright intelligent car model is created. In 2002, Segway launched the first truly upright two-wheeled scooter that could balance itself. In recent years, with the development of sensor technology and energy power technology, the mature control theory, the United States, Japan, Switzerland and other countries balance vehicle research has been rapid development, and the rapid launch of commercial products.

In China, thanks to the introduction of technology, talent and financial support, although China’s smart car started late, the research on two-wheel smart car has also made some achievements. In terms of universities, Xidian University has developed a self-balancing two-wheeled robot [2]. On the commercial side, China’s Nambo Balance Car company acquired well-known brand Segway in 2015. I believe that with the country’s strong support for high and new technology and the improvement of the people’s ability to accept new things, as one of the new technology products of the balance car in Our country will be able to get rapid and benign development.

1.3 Research Significance

The research content of intelligent car control algorithm is not only used in intelligent car, but also can be widely used in other robot control or unmanned control fields. The use of intelligent vehicles greatly reduces the use of fuel, which is of great benefit to improving environmental quality; Its small size, easy to carry, can effectively reduce the problem of traffic congestion in big cities, convenient for citizens to travel; In large shopping malls, restaurants, underground garages or the security scene of some large-scale events, its characteristics of quick response has been the biggest application.

2. Overall scheme design of the system

2.1  Design the main work and basic requirements

The main task of this course design is to design software and hardware and the corresponding Bluetooth control APK program, remote control of the two-wheel car to achieve a variety of self-balancing movement, the movement state includes forward, backward, left, right, with a turn of the buzzer and movement state indicator LED lights.

Main work includes: main chip, driver chip, regulator chip, buzzer and other components selection; Schematic diagram PCB drawing; Component testing and welding; Writing mobile phone APP; Bluetooth communication debugging; Encoder speed measurement algorithm writing; Filtering algorithm writing; Preparation of cascade PID algorithm and debugging of corresponding parameters; Status indicators and buzzers and other peripheral program call; Upright vehicle assembly and overall commissioning.

Basic requirements:

  1. The upright smart car can stay self-balanced for a long time
  2. The phone software can communicate with the smart car in two ways
  3. The upright smart car can move forward, backward, turn left, turn right and park
  4. There is a buzzer prompt and LED light prompt when the status changes

2.2  Program demonstration and selection

  1. About filtering algorithm
  1. Scheme 1: Kalman filter can predict and estimate the optimal state of the system from the data with known measurement variance and noise in the case of a lot of interference [3]. Kalman filter can be used to obtain a group of intelligent vehicle attitude data close to the truth value and relatively accurate from the original data of MPU6050.
  2. Scheme 2: classical digital filter, mainly including low-pass, high-pass, bandpass filter, complementary filter is a variant of bandpass filter. In the calculation of Angle, Angle is generally obtained through angular acceleration and angular velocity. Since the two angles are obtained in different ways, a fusion coefficient is needed in the fusion of original data [4]. After the complementary filtering of the angles obtained by the two methods, a fast response and accurate Angle tracking attitude data can be obtained.

In the comparison of the two schemes, it is found that the MPU6050 chip has its own motion data processing operation unit (DMP), through which the attitude Angle of the chip can be directly output, including pitch Angle, yaw Angle and roll Angle. The pitch Angle is the Angle between the plane where the chip is located and the horizontal plane, which is also the Angle value mentioned above. In this way, DMP of MPU6050 can not only get a more accurate Angle value, but also reduce the calculation burden of microprocessor. But in order to make the final data closer to the true value, low pass filtering algorithm is still used in speed control. The last scheme is to call THE DMP of MPU6050 on the basis of scheme 2. Although a large number of MPU6050 firmware libraries need to be transplanted in the program, the data is more accurate.

  1. About control algorithm

The control algorithm adopts the PID algorithm which has been tested in the industrial field for a long time [5]. Its control algorithm is simple, but its control performance is reliable and stable, and its robustness is strong. The parameter setting scheme is mature and does not need to establish a mathematical model. It involves upright PID, speed PID and steering PID[6].

  1. About the speed measurement algorithm
  1. Scheme 1: position difference method (M method), measure the Angle value of gear rotation within the specified time
  2. Scheme 2: fixed Angle time measurement method (namely T method), measure the time used by the gear to turn the fixed Angle

The program of M method is simple, although there may be some errors when measuring low speed pulse, but the stationarity and accuracy are high when measuring high speed pulse. T method is generally used to measure the time interval between two pulses to determine the measured speed, which is suitable for measuring low speed, but the wheel will produce dozens or hundreds of pulses in a circle. It is not convenient to use T method, so scheme 1 is adopted.

  1. About lower computer development tools
  1. Solution 1: Use Keil MDK-ARM from German Keil Company
  2. Option 2: Use IAR Embedded Workbench from IAR Systems

KEIL and IAR are software development tools for a variety of embedded processors, mainly used to compile programs. Compared with KEIL, KEIL does not support stacked folders. IAR not only supports stacked folders, but also has a highly optimized compiler, that is, the compilation speed is faster than KEIL. However, some errors will occur when the project files generated by IAR are opened with other versions of IAR, that is, there are version incompatibility problems, while KEIL does not have such problems. Considering that the next computer program will be transplanted between versions in the iterative process, and most users of STM32 CubeMX software use MDK-ARM-V5, the learning materials are relatively rich, so the first scheme is selected.

  1. About library Functions
  1. Plan one: use standard library function development
  2. Scheme 2: Hal library function development

ST provides developers with the LL library in addition to the above two, but has abandoned it due to the lack of chip types currently supported. The standard library was older than Hal, and the two were incompatible but had similar structures and interface calls. Although there are more standard library users, HAL (Hardware Abstraction Layer) for Hardware Abstraction Layer, with ST company’s new Abstraction software STM32 CubeMX graphical code generation, can greatly facilitate developers, to achieve the maximum span of different products portability, And with a set of user-friendly API function interface. Although HAL still had some minor problems in the early stage, all the programming of the smart car was based on HAL library functions out of the exploration spirit of learning new tools and technologies.

  1. About upper computer development tools
  1. Solution 1: Use Qt Creator from Qt Company
  2. Option 2: Use Google’s Android Studio

Compared with Android Studio, the mainstream integrated development tool, Qt Creator is relatively small, and Qt Creator may be unstable in some complex operations. However, this course design does not involve complex operations. A lightweight and easy-to-use software development tool is enough to achieve functions. Qt Creator can be cross-platform, that is, the developed software can run on Windows, Mac OS, Android and Even Linux platforms with a little modification [7], which reduces the workload of the later transplantation of the upper computer, so scheme 1 is selected.

2.3System block diagram analysis

The circuit board of the intelligent car uses 7.2V nickel-chromium battery. Through two components in the voltage conversion module, 7.2V is converted into two voltages to supply power to other chips on the circuit board. The main chip and attitude detection sensor MPU6050 carry out I2C communication to obtain the current Angle of the intelligent vehicle, providing data support for the next adjustment of the Angle of the intelligent vehicle; The main chip through the encoder data orthogonal decoding real-time detection of the current car real speed, for the control of intelligent car speed data support; Download program to main chip through download interface; The main chip and bluetooth module for two-way communication, bluetooth module and mobile phone program two-way communication, data exchange, the main chip received mobile phone instructions through THE PWM signal control motor rotation, and then the upright intelligent car attitude adjustment; At the same time, the corresponding buzzer and LED light can be used for state control, and the software watchdog ensures the normal operation of the program.

Figure 2-1 System block diagram

2.4 System overall scheme design

      1. Chip selection

Main chip: because in the communication process with MPU6050 to transplant its firmware library, and library function content is more, the ROM of the single chip, considering the peripheral may be added later, the number of pins of the single chip, so give up the small single chip similar to 51 single chip; Consider the development cycle, the use of ARM architecture MCU; Although the intelligent car circuit board is powered by nickel-chromium battery, it is only used for experimental simulation. The nickel-chromium battery of 2000mAH is fully enough to give up MSP430, which is generally used in low power consumption or ultra-low power consumption. As intelligent interconnection terminal becomes a hot research topic at home and abroad, application schemes based on STM32 are becoming more and more mature [8]. Therefore, STM32 microcontroller, which is more mainstream in the market, is finally selected.

Drive chip: choose the drive current up to 43A high current integrated chip BTN7960, the internal integrated drive Ic has logic level input function, so the main chip can directly drive chip PWM signal can control the motor rotation, but because it is a half-bridge drive chip, so it needs two chips to control a motor. In the measurement process, the current consumed by the motor running at full speed is no more than 500mA, and the driving capacity is fully adequate. Besides, the control is simple, the circuit is mature and the performance is stable [9], so the BTN7960 driver chip is selected.

      1. The power on

After 7.2V supplies power to the circuit board of the intelligent car, it is converted into two voltages by two voltage regulating circuits. The two LDO are LM2596, which reduces 7.2V to 5V, and AMS117_3.3, which reduces 5V to 3.3V. LM2596 is produced by TI can output 3A current regulator buck chip, the input voltage can reach 37V, less peripheral devices, its output 5V voltage to the intelligent car circuit board on the buzzer, Bluetooth, MPU6050 and some other peripherals power; AMS117_3.3 is a forward low voltage drop regulator, output current is 1A, intelligent car circuit board is 3.3V fixed output version, accuracy is 1%, output voltage to the main chip STM32F103, 74LVC245, Hall encoder and LED lights and other peripherals.

      1. Download the aspects

There are two main ways to download STM32: ISP download (serial port download), JLINK download and STLINK download. Serial download can not be online simulation, it will cause inconvenience to the later software and hardware debugging, so it is abandoned; JLINK download mode and STLINK download mode support simulation debugging and support most OF the ARM kernel chips on the market, the difference is that the mainstream JLINK download tool has 20 pins, and STLINK only 4 pins, for the intelligent car circuit board volume is not easy to be too large and to install and debug convenient consideration, Choose to use STLINK download tool for program download and late simulation debugging of the main chip.

      1. communications

In early application of Internet of things, out of respect for embedded system security, equipment most of the connection between the cable way, but with the development of technology and equipment installation position on the rise, wireless transmission has been applied more widely, including bluetooth modular simplicity, just a receiving module and a wireless sending module can be realized data passthrough [10], So the smart car communicates with the phone app via a Bluetooth module.

3 hardware design of the systemAnd system processes

3.1 Single chip microcomputer control circuit

ARM cortex-M series microprocessor is the more mainstream chip in the market. After multiple comparisons, STM32F103C8T6 is selected as the core chip for this experimental platform, which is a new generation cortex-M3 core microprocessor. It has 72 MHz main frequency, 20K byte SRAM, 128K byte flash, provides two 12-bit ADCs (16 channels), three universal 16-bit timers plus a PWM timer, up to two I2Cs and SPIs, and three USArt [11]. One USB, one CAN, two watchdog timers, CRC computing unit, 7 channel DMA controller. Moreover, there is a special development library provided by the official, which makes the operation and debugging more convenient and simple [12]. The peripheral circuit module is designed around the main chip, and its main components and functions are as follows:

Crystal oscillator circuit: the circuit board of intelligent car adopts high-speed crystal oscillator circuit, and crystal oscillator provides clock signal flow for single chip microcomputer.

Reset circuit: the automatic reset circuit is adopted. The single-chip microcomputer automatically resets after being powered on. After the reset, the single-chip microcomputer program runs again.

Startup mode setting circuit: the BOOT0 and BOOT1 pins of STM32 are configured to set the startup mode of the single chip microcomputer, that is, from which region the single chip microcomputer is started, and the main chip of the test board is started from the main flash memory region.

See the figure below for specific circuits

Figure 3-1 Microcontroller control circuit

3.2 Power module circuit

Figure 3-2 Circuit of the power module

3.3Motor drive module circuit

As the drive current of the main chip pin is too small, and the direct control drive chip is easy to be damaged by the inverting current, a three-state output eight-way bus transceiver, 74LVC245, is added between the main chip and the driver chip for drive isolation, as shown in the figure below.

FIG. 3-374 lvc245 circuit

The PWM signal output by the main chip reaches the logic signal input pin of BTN7960 after the isolation chip, and the output voltage of the drive chip is adjusted. By sending different PWM signals to the two drive chips, the voltage difference between the motor can be guaranteed, and the motor can be controlled for different degrees of positive and negative rotation. The diagram below shows the circuit diagram of a motor driving the smart car. In order to prevent chip damage or other abnormal conditions resulting in the circuit output a particularly large voltage, and then burn the motor, a varistor is added at both ends of the motor, when the voltage between the motor exceeds 12V, the varistor absorbs the excess current, voltage clamp to ensure that the motor is not burned out.

Figure 3-4 Motor drive circuit

3.4Other peripherals

  1. Buzzer: the use of 5V active buzzer, power on the sound, easy to control. As shown in the figure, the positive end of the buzzer is connected to 5V, and the negative pole is connected to an NPN triode. The triode base pole is connected to the main chip pin through a resistor. When the pin is set to high voltage, the triode is on and the buzzer works; otherwise, the buzzer does not work.

Figure 3-5 Buzzer circuit

  1. MPU6050 module interface: MPU6050 does not have a separate circuit, but directly uses GY-521 three-axis acceleration electronic gyroscope. However, the module does not add any extra circuit, and the original data of MPU6050 is obtained by the communication between the single chip computer and it. MCU and MPU6050 communicate through I2C, as shown in the figure below. The four interface lines are power supply, ground, data line and clock line respectively.

Figure 3-6 mpu6050 interface

  1. LED indicator light: as shown in the figure below, it is the indicator light in the four directions of the intelligent car circuit board, which is distributed on the four corners of the circuit board. The 1K resistance plays a role of current limiting. If the LED light is not too bright, it can be replaced by a small resistance value.

Figure 3-7LED indicator circuit

  1. Download interface: as shown in the figure, the four wires of the download interface are respectively the power supply and ground for the main chip, and SWCLK and SWDIO for communication with the single chip.

Figure 3-8 Download circuit

  1. Speed measurement interface: Hall encoder is used for motor speed measurement, which can convert angular displacement into a series of digital pulse output. When the gear is turned round, encoder A meets to output A fixed number of pulses, encoder B is output to turn, encoder AB is connected to the pin of the single chip microcomputer, the single chip microcomputer captures the signal and then orthogonal decoding, through M method, that is, to calculate the number of pulses received within A fixed time can be converted to the speed. As shown in the figure below, the four interface lines are the power supply, ground, phase A and phase B of the encoder respectively.

Figure 3-9 Ports for detecting speed

  1. Bluetooth interface: The Bluetooth module uses the master-slave HC05 Bluetooth serial port module. The Bluetooth parameters, the serial port parameters of the single chip and the bluetooth receiving parameters of the mobile phone program are all 9600bits/s, with stop bit 1 and no check bit. The single chip communicates with the Bluetooth module through serial port 2, and the Bluetooth sends the single chip instructions to the mobile phone with TTL level. Data inversion is similar. As shown below, bluetooth module adopts 5V power supply, module RX pin connected to TX2, TX pin connected to RX2.

Figure 3-10 Bluetooth port

  1. Obstacle avoidance interface: when the photoelectric sensor module encounters obstacles, it will output a high level, and connect its output pin to the interface below. The single chip microcomputer will detect the high level and conduct obstacle avoidance processing.

Figure 3-11 Ports for avoiding obstacles

  1. Steering gear control interface: the 9G steering gear SG90 belongs to analog steering gear. After 5V power supply, the steering gear can be controlled by PWM signal.

Figure 3-12 Steering gear control ports

The circuit board of intelligent car can perform filtering, decoupling and anti-high current operations by adding appropriate components such as resistors, capacitors, inductors, diodes and fuses, while eliminating some small probability interference [13]. At the same time, in the process of designing circuit board, in addition to anti-interference processing, welding position, welding temperature and welding material are strictly controlled in the process of welding components [14], which eliminates potential safety risks of circuit board from the root.

4. System software design and system process

4.1Lower computer program

Keil Software’s Keil μVision5 IDE is the compilation and development tool used in the lower computer. The development language is C language; The accompanying development tool is the graphical configuration tool STM32CubeMX that can be associated with Keil μVision5 IDE. The library functions used are HAL library functions; The program starts from the main flash memory area; The download tool is STLINK.

The main operations of STM32 in the program are as follows: I2C communication with MPU6050 to know the current posture; Through PWM control motor rotation; Detect the current motor speed; GPIO to control buzzer, LED, etc. Software watchdog; Two-way communication with Bluetooth.

4.1.1Lower computer program flow chart

The program starts with system initialization, including clock initialization, GPIO initialization, I2C initialization, timer initialization, orthogonal decoding initialization, serial port initialization, MPU6050 and its DMP initialization, watchdog initialization and PID parameter initialization. Before while (1), the above program is executed only once after startup. The unified system initialization code is used in the following flowchart.

All control is handled in an external interrupt routine, and other interrupts are triggered by the MPU6050. Because the data in the DMP is updated every 10ms, the interrupt output pin of the MPU6050 module is configured to carry out a level conversion every 5ms. When the single chip microcomputer captures the falling edge of the pin, the data will be processed to ensure the accuracy of data and the timeliness of processing.

Internal processing steps of interrupt are shown in the figure below. After receiving bluetooth, corresponding processing includes forward, backward, left, right, buzzer prompt and LED indication, etc.

Figure 4-1 Flowchart of the lower computer program

4.1.2Algorithm is introduced

  1. Low pass filter algorithm: Encoder_Least =(speed_left+speed_right)-0;

Encoder * = 0.8;

Encoder + = Encoder_Least * 0.2;

Where Encoder_Least is the latest speed deviation; The second and third programs can be understood as Y(n)=αX(n)+(1-α)Y(n-1), where X(n) is equal to Encoder_Least, representing the sampling value; Y(n-1) is equivalent to Encoder and represents the output value of the last filtering; α is the filtering coefficient, which is 0.2 in the above equation.

  1. First-order complementary filtering algorithm: g_fAngle = 0.02 * Angle_ax + (0.98) * (g_fAngle + GY * dt);

G_fAngle on the left in the above equation is the actual Angle obtained; Angle_ax is the Angle value after conversion of angular acceleration. Because angular acceleration will produce high-frequency noise due to vehicle body shock and other factors, low-pass filtering is carried out to filter the high-frequency signal, so the fusion coefficient is small. G_fAngle on the right can be interpreted as the last Angle; GY is angular velocity, dt is time, GY * calculates the Angle passed in dt period, and obtains a more accurate Angle through continuous integration of the Angle, with high reliability and fusion coefficient, somewhat similar to high-pass filtering.

  1. PID algorithm: balance= Carangle.kpBias+CarAngle.KdGyro.

          Velocity=EncoderCarSpeed.Kp+Encoder_IntegralCarSpeed.Ki;       

          Turn = -Turn_Target * Kp – gyro * Kd;                             

The first program above is the vertical PD algorithm, namely the Angle loop control algorithm, which belongs to the position PD algorithm [15]. Through this algorithm, the short time upright balance state of intelligent vehicle can be realized. Bias is the Angle of deviation from the horizontal plane, and when the value is 0, it is parallel to the ground. Gyro is the value of angular velocity, which can slow down the car shock by adjusting Kd. The specific adjustment steps are shown in Figure 4-2. When the car is tipped forward, the wheels follow the forward direction of the car so that it has a backward force, and vice versa. The best phenomenon when adjusting parameters is that the car is sensitive to Angle changes and does not shock.

Figure 4-2 Motion model of the upright car

The second program is speed PI control, Encoder is the current speed value output by low pass filter, because the output value of speed control and vertical control is to be added together, low pass filter can slow down the interference of speed difference on vertical control; Encoder_Integral is the integral of velocity, displacement, and the integral controls the static difference of velocity, and the limiter for Encoder_Integra is the limiter for velocity; The upright ring and the speed ring can be debugged together to realize the car standing upright for a long time [16]. The upright ring is a negative feedback, and the speed ring is a positive feedback, that is, when the car accelerates in the same direction due to the upright ring, the function of the speed ring is to produce a faster speed in the same direction.

The third program is the steering PD algorithm. Turn_Target is the steering speed value. When the value is large, the steering speed block is slow; Gyro is the value of angular velocity. Gyro * Kd can reduce the vibration of the car when it turns. According to the body control method is to subtract the steering PD output value from the PWM output value of the left wheel of the car, and add the steering PD output value to the PWM output value of the right wheel of the car.

4.2Upper computer program

The upper computer development tool is Qt Creator, a cross-platform graphical interface application development framework developed by Qt Company in 1991. The software functions are bluetooth switch, Bluetooth status detection, search and pairing connection, etc. The most important is wireless data transmission through Bluetooth module and MCU.

2Upper computer program flow chart

System initialization includes creating animation, setting animation, animation adaptive, start animation; Set timer; Set scrolling display character, color, display time, scrolling direction; Set bluetooth UUID code, allocate socket memory, limit socket protocol; Set the size, position and transparency of the display background; Write slot functions and other callback functions corresponding to key signals.

The operation after initialization is shown in figure 1.

Figure 4-3 Program flow chart of the upper computer

4.2.2  Upper computer function introduction

The host computer uses the application development framework Qt Creator development, in the use of its own interface designer for page design, in the code management page for C language programming, logic implementation. During the debugging process, graphical debugging was carried out, that is, after the program and the page are associated with all-round debugging. In debug mode, the program is observed and tracked in real time, the problem is located and solved or the corresponding configuration is modified, and the actual application is carried out in the final experimental stage, and the effect is good.

Using Qt Creator for development, first of all, build the compilation environment, the main steps are :(1) select the appropriate compiler; 2) Configure environment variables; (3) Select the compiler for the Qt file system; (4) Select library files, because the upper computer designed for this course develops Android software under Windows system, so a cross-compiler is required [17]. The main functions are as follows:

  1. Scan to refresh nearby Bluetooth devices
  2. Display bluetooth device on your phone
  3. Button pressing instructions are displayed in the upper left corner for control

holdingsInstructions for use of upper computer

After that, the App will automatically search for surrounding Bluetooth devices and display them on the screen. If there is a new device, you can click the refresh button at the bottom of the page. If there is a paired device, the phone will be highlighted. Turning on the Bluetooth button will say “Connecting…” , the connection failure will show the connection failure, the successful connection will automatically enter the 440ms car start animation, the animation above the scroll display “starting…” , as shown in Figure 4-5.

After the animation is played, the control page is entered, as shown in FIG. 4-6. Pressing a button will send corresponding instructions, such as pressing “up” to send 0x31 and 0x32, pressing “Down” to send 0x33 and 0x34. The commands that can be sent include up, down, left, right, park and buzzer. Press the Bluetooth icon in the upper right corner, and the APP page will jump to the Bluetooth connection page.

PC each for a command to update, buzzer will beep, forward two led lights up front, back behind the two led lights up, turn left at the left two light, turn right when the right two lights up, ringing the buzzer, click the stop button, the car to stop all light is lit, and the current state of light all inversion, The buzzer starts to beep, click it again, the buzzer stops emitting sound, and all the current indicator states are reversed again. Figure 4-7 shows the icon of this software. The software name is “Central Console”.

​ 

Figure 4-4 Bluetooth connection Figure 4-5 Startup animation

Figure 4-6 Bluetooth control Figure 4-7 Software icon

5  Diagram of problems and achievements encountered during development

5.1Hardware problems and solutions

  1. As the driver chip is blown down from other circuit boards, the first temperature is not well controlled to blow the chip
  2. Manual welding STM32F103C8T6, pin spacing is only 0.5mm, the pin welding short; To avoid short-circuiting between pins due to rolling in a tin ball, tape the main chip together
  3. The diameter of the fixing hole is set to 2.54mm, and the plastic stud used for fixing is 3mm, which can only be fixed by glue rod
  4. The brightness of the indicator light is too dim because of the excessive current limiting resistance selected
  5. During PID parameter tuning, the chip will burn out due to long time high-frequency jitter
  6. The buzzer doesn’t sound very much because the sticker hasn’t been removed
  7. Supply power to the main chip first and then to the driver chip. Otherwise, the wheel may turn randomly during initialization of the main chip

The following figure is the PCB diagram of circuit board. The schematic diagram was first drawn in Altium Designer and then converted into PCB. The following figure was obtained after the disorderly components in PCB were arranged and connected electrically.

Figure 5-1 Circuit board (PCB

5.2Problems and solutions in the development of lower computer

  1. Bluetooth cannot send or receive data: The default baud rate of a Bluetooth module is 115,200 bits/s, which is different from that of a single chip microcomputer. It needs to be set to the same with the AT instruction
  2. Sometimes the external interrupt of MPU6050 cannot be received: the external interrupt is interrupted by another interrupt, and the corresponding external interrupt has the first priority
  3. When the car is completely down, it will turn blind: judge whether the inclination Angle of MPU6050 exceeds plus or minus 25 degrees, and then it will not be controlled
  4. PID adjustment has upright ring, speed ring, steering ring, debugging should be upright ring and speed ring together, otherwise it can not keep upright
  5. The communication address of the I2C address depends on whether a pin of the MPU6050 is grounded. The default value is 0X68
  6. Speed hysteresis: the speed should be limited, otherwise when the variable overshoots, it is easy to appear that the speed cannot fall or rise
  7. The car always runs in one direction: there is a difference between the mechanical median set in the program and the actual installation position of the MPU6050.
  8. In STM32cubeMX UART2 tx pin mode default only PP (reuse push-pull) one, to change to OD (open leakage) mode, you can directly change in the source program
  9. The hardware I2C of STM32cubemx HAL has a BUG that puts __HAL_RCC_I2C2_CLK_ENABLE() after GPIO initialization.
  10. Modify the program generated by STM32cubemxUSER. The content must be written between “CODE BEGIN X” and “CODE END X”. Otherwise, the program will disappear after the next generation

The following figure is the finished PCB circuit diagram processed by the factory and welded onto the components. It can be used after powering on and connecting the corresponding circuit correctly.

Figure 5-2 Schematic diagram of the circuit board

5.3Problems and solutions in the development of upper computer

  1. Unable to add a background image: To add a background image to the listWidget, it must be set to transparent first
  2. Mobile phones cannot scan Bluetooth: Android 6.0 or higher devices need to enable location permission before scanning Ble devices
  3. Unable to display irregular ICONS: Use a dedicated icon button
  4. Android detected problems with API compatibility Android occurs when the software is first opened. The reason is that after the mobile phone system is upgraded to Android 9.0, Google background limits developers to call unofficial public API. This problem has not been solved due to the mobile phone system update, but it does not affect the use after clicking “OK”

Below for the vehicle physical figure, bluetooth in upper part, indicator light on the four corners, the battery in the circuit board directly with copper column and circuit board, to prevent the occurrence of problems for the battery cooling leads to the car circuit board, in order to guarantee the stability of the sensor, with rubber seal at the bottom of the car, directly wiring plug in own fool proof design don’t have to worry about the, fall off with a card lock don’t have to worry about.

Figure 5-3 Physical picture of the balancing vehicle

reference

[1] Lin Feng, CAI Yanguang. Design and implementation of double closed-loop PID control system for dual-wheel self-balancing vehicle [J]. Industrial control computer,2017,30(06):73-75.

[2] Liu Yongpeng. Design of intelligent balance vehicle based on STM32 [J]. Science & technology economic guide,2018,26(30):39.

[3] Liu ERlin, Jiang Xiangju. Attitude Detection of Two-wheel Self-balancing Vehicle Based on Kalman Filter [J]. Automation & Instrumentation,2015(02):52-54.

[4] Xia Guoqing, Chen Huazhen, ZHEN Wenjin. Design of two-wheel robot motion control system based on complementary filtering [J]. Automation technology and application,2018,37(10):72-78.

[5] Wang Yaohui, Qiang Tianwei. A Brief Analysis of PID Control Principle [J]. Cleaning and Air Conditioning Technology,2013(03):79-82.

[6] Yan Dong. Design of Autonomous Balancing Vehicle Based on PID Control Algorithm [J]. Science and Technology Vision,2018(33):14-15.]

[7] Zhao Beigeng. Construction of Qt graphical interface integrated development environment under Windows System [J]. Science & Technology Economic Guide,2016(09):20.

[8] Sizu Hou, Shengming Wu, Fengying Kong, Xiaoling Cui,Xuan Zhang.  Design andrealization of family  intelligent interactive terminal based on STM32[C].  IEEE. 2012.06.

[9] Yang Minghui, SUN Mengmeng, ZHANG Yubing et al. BTN7960 dc servo motor drive plate design [J]. Science and technology outlook,2015,25(18):110.

[10] Cao Shuwei, Yang Xue. Design and implementation of bluetooth switch control circuit for smart home phone [J]. Journal of chifeng university (natural science edition),2019,35(01):25-27.

[11] Li Shuainan. Design of dual-wheel self-balancing car based on STM32 control [J]. Modern industrial economics and reliability,2018,8(13):34-35.

[12] Wang Lei, Ning Xin. Shandong Industrial Technology,2018(13):54.

[13] Ling Linyu. Electronic Testing,2017(09):93-94. (in Chinese)

[14] Yin tao. Technology Innovation and Application,2018(28):114-115.

[15] KE LIN,TING LEI HUANG,PIN LIU.Designof the smart car comtrol system based on adaptive PID algorithm[C]. Proceedings of 2011 InternationalConference on Intelligent Computing an Integrated Systems(ICISS2011), Guilin University of Electronic Technology IEEE Beijing Section,2011.

[16] Yuan Xinhong, Wang Xing. Attitude Detection and Control Scheme of Balancing Vehicle Based on MPU6050 Six-axis Sensor [J]. Information & Computer (Theory Edition),2018(23):103-104.

[17] Zhao Haohao, Wang LAN, Dai Xianchun et al. Construction of embedded development platform based on Qt [J]. Railway communication signal,2018,54(02):37-40.

6 the conclusion

In the hardware side to complete the control of the main chip, the motor drive and speed detection, the Angle of the balance car detection, and control the voltage of the output voltage regulator; Hardware program used PID control algorithm and filtering algorithm, as well as other used PWM control, serial port receiving and sending, clock management, I2C communication, pin configuration, timer and external interrupt related procedures; The mobile phone program by writing the corresponding Bluetooth control APK program, remote connection to the balance car Bluetooth, simple direction control and some corresponding modules on the circuit board control (such as turn signal and buzzer).

This graduation project through the software and hardware design and the preparation of the corresponding Bluetooth control APK program, the realization of the control of the two-wheel car of various self-balance movement, including forward, backward, left, right turn and parking, at the same time can be turned by the buzzer and LED lights for the movement state indication. Through simple experiments, the motion state of the car under different loads, different voltages and different sections is tested. If the load is too heavy, the center of gravity will move up, and the corresponding PID parameters need to be adjusted. When the voltage is too low, the motor of the car can not be fully driven, resulting in a timely response or even unable to stand upright; The worse the section, the greater the error of the speed integration will be, resulting in a shorter time to balance.

The biggest advantage of the design is the strong portability of the program. The HAL library based on CUBE is used for the development of the lower computer, so as long as it is ST company’s chip, only need to change the parameters and corresponding pins in the graphical configuration page can be transplanted. If the same PC APP needs to run on Linux, Windows and other platforms, it only needs to change the compilation output environment on Qt software to complete.

7conclusion

The rapid development of technology has led to the deep integration between disciplines, which provides a theoretical basis for the birth of the new upright intelligent car. With the advent of the Internet of Things era and “unmanned” era, the amount of sensors and data processed by the upright intelligent vehicle will increase exponentially, and the human-computer interaction will become simple and efficient, with more powerful functions.

The upright intelligent car designed by this graduation project has realized the basic functions of autonomous balance and short-range control of mobile phone, and some additional peripherals can also make the user’s driving immersion feeling stronger. However, there are still some problems, such as the need to sway back and forth slightly to maintain balance, and the balance is not completely still, and there are some incompatible problems in the mobile APP. These problems still need to find solutions, at the same time, the future will try to improve the intelligent car more intelligent, keep pace with the development of the era of technology, to a higher level.