Welcome to 8-Channel Tracking Module repository
4.STM32 self-balancing car
STM32 balancing car
1. Experimental preparation
Knowledge reserve
Good programming ability (mainly C language)
Familiar with the architecture of stm32
Material preparation
STM32 balancing car *1
Eight-way tracking module *1
12V battery *1
Several Dupont wires
2. Car wiring
Wiring of balancing car and infrared sensor (this example uses serial communication)
| Balancing Car | Infrared sensor |
|---|---|
| TX2 | RX |
| RX2 | TX |
| 5V | 5V |
| GND | GND |
As shown in the figure:
Main procedures
x
int main(void){ Mid_Angle = -1; //Obtain based on the car bsp_init(); MPU6050_EXTI_Init(); //This interrupt service function is placed last while(!Key1_State(1)); send_control_data(0,0,1);//Send and receive digital data Stop_Flag = 0; //Start controlling
// OLED_Draw_Line("start tracking!", 1, true, true); delay_time(10);//delay 100ms while(1) { if(g_new_package_flag == 1) { g_new_package_flag = 0; } }}
This project uses an external interrupt to perform PID processing for line patrol according to the value of the infrared probe (every 5ms), so that line patrol can be completed on a map with black lines and white background.
In app_irtrackin.c, there is a parameter for adjusting PID line patrol. If you want to increase or decrease the speed and optimize the effect, you can adjust the macro definition value inside.
xxxxxxxxxx
//P//I//D
//Line patrol speedIRTrack_Trun_KP: P value of pid line patrol
IRTrack_Trun_KI: I value of pid line patrol
IRTrack_Trun_KD: D value of pid line patrol
IRR_SPEED: Speed of line patrol
Experimental phenomenon:
On the premise of ensuring that the wiring and installation are correct, after the 8-way line patrol module is calibrated, press the key1 button to start line patrol. If the 8-way module probe cannot detect the black and white lines normally, you need to wait for the module to work normally before pressing the key1 button If the floor is black, you need to put a piece of white paper under our map to cover the black. The main reason is that the material of the map is relatively transparent, which has a greater impact on the 8-way line patrol sensor.