Expand self-driving car

1. Opening instructions

Please read the "Motor Introduction and Usage" in the four-way motor driver board information first to understand the motor parameters, wiring method, and power supply voltage you are currently using. To avoid burning the motherboard or motor.

Usage tips: Since the yaw angle of MPU6050 is easy to drift, or different motors are used, this project may not run perfectly on the track after burning. You can modify the variables according to some key points mentioned in the code analysis below, or replace the MPU6050 with other modules.

2. Experimental preparation

Wheeled car chassis V1 four-wheel drive version, 4*310 motors, 7.4V lithium battery, eight-way patrol module, MPU6050, MSPM0 robot expansion board (optional), MSPM0G3507 core board (Yahboom). The sound and light reminders required in question H are integrated on the MSPM0 robot expansion board (buzzer PB24) and the MSPM0G3507 core board (LED PB2). If the user does not use the MSPM0 robot expansion board, he needs to prepare a buzzer. And the question selection function button K1 (PA2) is located on the MSPM0 robot expansion board

The relationship between the 4 motor interfaces and the car is as follows:

M1 -> upper left motor (left front wheel of the car)

M2 -> lower left motor (left rear wheel of the car)

M3 -> upper right motor (right front wheel of the car)

M4 -> lower right motor (right rear wheel of the car)

Hardware wiring:

Wiring using the mspm0 expansion board

Note: The wire used for the eight-way patrol module and the wire used to connect the MSPM0 robot expansion board and the four-way motor drive module are: PH2.0-4pin cable, double-ended all black, reverse (200mm), the direction of the reverse cable holder is shown in the figure below

扩展板接线

Use msp core board wiring

mspban

Wiring pins:

Four-way motor driver boardMSPM0G3507
RX2PB6
TX2PB7
GNDGND
5V5V
MotorFour-way motor driver board (Motor)
M2M-
V3V3
AH1B
BH1A
GGND
M1M+
8-channel patrol moduleMSPM0G3507
5V5V
SCLPA15
SDAPA16
GNDGND
MPU6050MSPM0G3507
VCC5V
GNDGND
SCLPA1
SDAPA0

3. Key code analysis

According to the motor model you purchased, modify the beginning of empty.c to your own motor model, otherwise the car will easily get out of control when running.

MOTOR_TYPE: used to set the type of motor used. Modify the corresponding number according to the comments based on the motor you are currently using.

During the operation of MPU6050, angle deviation is prone to occur, and the encoder data of different motors will be different. So when running the competition question, you need to modify the variables of angle and mileage in the question.c file according to your own situation. Here, take question 3 as an example to explain some places that may need to be modified

In Q3_STATE_1: object_angle = navigetion_0_360_limit(first_angle + 32); sets the angle to which the car should rotate when running, which is the starting angle + 32°. If 32° cannot reach the corresponding point when running, modify the number 32 according to the offset of your car.

if(LineCheck() == BLACK && odometry_sum >= 1000) here uses the eight-way line inspection sensor to detect whether it has reached the black line and whether the mileage count is greater than or equal to 1000. If the track conditions are not good and the eight-way line inspection sensor is accidentally touched, resulting in entering the next state in advance, you can increase odometry_sum.

In Q3_STATE_2: if((calibratedYaw < 220 && calibratedYaw > 150) && LineCheck() == WHITE), the angle transmitted by MPU6050 is used to determine whether the robot is in the range of 150°-220° and has reached the white background area. However, sometimes when the robot reaches this point, the angle may exceed this range, causing the robot to be unable to enter the next state. At this time, you can choose to modify the angle value here. The specific modification requires actual measurement.

 

First initialize all peripherals. If successful, the LED light will flash twice and the buzzer will sound twice. Then run the task scheduler to obtain the required data in sequence. In the while loop, continue to determine whether the competition topic is selected by pressing the button.

 

This function is used to store the parameters of the motors sold in our store. By modifying the MOTOR_TYPE parameter at the beginning of empty.c, one-click configuration can be achieved. Under normal circumstances, do not modify the code here when using the motors of our store. If you use your own motor, you can select any motor and change the parameters to the parameters of the motor you use. If you do not understand the meaning of these parameters, you can refer to the document "4-way motor driver board control instructions" to understand the specific meaning of each instruction.

4. Experimental phenomenon

After the car is powered on. The peripherals used will be initialized. You need to wait for a while. After the initialization is successful, the LED will flash twice quickly, and the buzzer will beep twice quickly. Then you can press and hold the K1 button on the expansion board to select the competition question. If you hear a beep, it is the first question, and if you hear two beeps, it is the second question, and so on. After selecting the question, press the K1 button again to start the task. The buzzer will beep for a long time, and then start the task.