Production of TT motor balance trolley

Production of TT motor balance trolley

I bought a Taobao tracking car kit when I was bored during the holidays, and made a tracking car and remote control function. Later, when I saw a balance car, I wanted to make one.
I went to search for the solutions, which are basically the encoder motor and car model of the home of the balance car. There are hundreds of them in one search, and the student party is not very affordable.
There is also a TT motor with an encoder, which can also achieve the same function, but it is found that a TT motor with an encoder is more than 20 or 30, think about it or forget it.
In the end, I decided to try it with only TT motors.

use modules

1. Motor drive
The motor drive uses TB6612FNG, and the instructions are too simple to explain. The module with two wheels is smaller in size, and the PCB is easy to make.
2. The balance angle measurement
MPU6050 module has a lot of routines on the Internet. After searching for a long time, I finally found a master who wrote it. The compatibility is not bad. But in fact, all the routines are similar, and there is no need to worry about various algorithms. I don’t care much about Kalman and first-order filtering, as long as the results can be produced.
3. Display part
In fact, the display part is not very useful after finishing, but it is convenient for debugging, and IIC communication OLED is added, as long as it still displays an angle, it is convenient for debugging and observation.
4. The remote control part
decided to add the remote control function. After all, it is only balanced and boring. I bought HC’s Bluetooth when I was making a tracking car, but I decided to use it.
5. Ultrasonic part
Ultrasonic is also used on the tracking vehicle. I don’t want to use it for the time being, but the interface is reserved, and the PCB is also added. If you want to use it, you can change the code and it will still work.
6. Power
supply There is nothing to say about the power supply. Two 18650, 7.2V and a step-down module will have 5V power. All modules can accept 5V power, including the input of the motor drive. 5V can also drive the motor, and the speed is also high. Can.
7. Motor
The motor is an ordinary TT motor, the one with deceleration, and the one with a small yellow casing. Encoders and speedometers are not used here (because they are poor).

All the modules use these. At the beginning, they used perforated boards to plug them in for debugging. Finally, the PCB was made after the function was realized. When you come back, you can directly use the PCB as the bottom plate, and stick the wheels to both sides with hot melt adhesive.

PCB

Balance car PCB1. The PCBs I drew by myself are all made into plug-ins. For the student party, the modules are still quite expensive to buy, so they can be recycled.
2. The four corners on the left are for the step-down module, and the bottom hole is for a switch. You can directly buy the tracking car kit, which has wheels and a switch. The price is about the same as buying two wheels directly. .
3. The two holes in the middle of the single-chip microcomputer are used to fix the battery. The bottom of the single-chip microcomputer is empty when plugged in. The battery is placed on the back. , the MCU is covered and cannot be seen.
4. On the right side is the motor drive and MPU6050. The balance detection should be placed in the middle as much as possible. The one on the top is the Bluetooth socket.
5. The top one in the middle is the interface reserved for ultrasonic waves. The initialization and detection distance are also written in the code, but it is not called, and I have not thought about the purpose of the detection distance.
6. There is a gap for the motor on both sides of the board, discharge the motor.

software

The STM32F103C8T6 chip used is enough.

Allocation of major resources.

1 serial port

In fact, the serial port is not used too much, and the serial port 1 is used to connect to Bluetooth. After initialization, it is the interrupt service function, which is used to adjust the remote control movement.

2 timers

There are quite a lot of timers used. If they are used in disorder, the pin conflicts may not be enough. It is still necessary to plan carefully.
It is quite convenient to set the general-purpose timer, so the general-purpose timer is used, timer 234.

Timer 2 is used for timing interrupts, and the control functions of the car are all in the interrupt processing of timer 2.

Timer 3 is used to output the PWM wave to give the motor speed signal. The motor needs two channels in total, and two channels are enough.

Timer 4 is reserved for the ultrasonic module for distance measurement, but it doesn’t matter if you just use the timer channel pin, just find a free pin. (I tried it, and there are a few pins with special functions that don't seem to work, or maybe I don't know how to set them)

3 IIC

The OLED and MPU6050 I bought on hand are both IIC communication, and the pins of IIC communication are not very clear now, basically they are set according to the routine, and other functions are not affected.

There is nothing to say about MPU6050, just get the data.

In fact, in addition to displaying an angle, the rest of the OLED is only good-looking. Of course, you can also add Bluetooth remote control status, which is reserved and can be added.

code programming

  1. The main function is all peripheral initialization. The last while (1), which always executes the display of OLED. The rate is not too high, so reduce waste. The main resource is for the timer, and nothing else.
  2. PWM initialization is trivial.
  3. The OLED is initialized, and the font library is set.
  4. The MPU6050 is initialized, and it is good to be able to call the measurement results.
  5. The focus is on the interrupt function, that is, the balance control, which is interrupted every 5ms by the timer. In the interrupt processing function, the deviation and the deviation change rate are detected, and the vertical loop, speed loop and steering loop are used to control respectively, and the PWM signal is given to the motor. . Bluetooth controls the car to go straight or turn by modifying the angle difference, or the positive and negative of the left and right motors.
  6. The code is a bit long, after the PCB assembly is completed, please read it again when you have time.

Physical map

frontThe back
The battery is going to be added on the back, but it hasn't been added yet.

operation result

The battery has not been added yet, the balance effect video link https://b23.tv/ELZCO9, go here first, and then adjust it later.
After buying the battery, I found that the car kept shaking when the left and right remote controls were used. After debugging for a long time, I finally found that the left and right motors were connected backwards. . . The effect is OK. The video effect link is below. https://v.youku.com/v_show/id_XNDY3MjMxODEyNA==.html

There are open source materials in the video comment area of ​​station b.

Guess you like

Origin blog.csdn.net/weixin_46253745/article/details/106027839
TT