MSPM0 color follower

MSPM0 color follower1. Opening instructions2. Experimental preparationThe relationship between the 4 motor interfaces and the car is as follows:Hardware wiringWiring using MSPM0 robot expansion boardWiring using MSPM0G3507 core board (Yahboom)Wiring pins3. Key code analysis4. Experimental operation5. Experimental phenomenon

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.

Motor: The case and code take the 520L motor of our store as an example.

2. Experimental preparation

National race chassis V2 four-wheel drive version, 4*L520 motor, 12V lithium battery, K210 vision module, MSPM0 robot expansion board (optional), MSPM0G3507 core board (Yahboom).

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 MSPM0 robot expansion board

During the installation and wiring process, if the wiring length is not enough, you can move the MSPM0 robot expansion board forward a little and install it, as shown in the following figure.

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

PixPin_2025-03-28_15-25-56

Wiring using MSPM0G3507 core board (Yahboom)

 

Wiring pins

Four-way motor driver boardMSPM0G3507 core board (Yahboom)
RX2PB6
TX2PB7
GNDGND
5V5V

Take M1 motor as an example below, and other motors are similar

MotorFour-way motor driver board (Motor)
M+M1+
M-M1-
GNDGND
VCC3V3
BH1A
AH1B
K210 vision moduleMSPM0G3507 core board (Yahboom)
5V5V
GNDGND
TXDPA22
RXDPA21

3. Key code analysis

Get_CMD_Flag: Get the k210 data flag

Clear_CMD_Flag: Clear command data and related flags

Upper_Data_Parse: Parse the saved k210 data and determine the function of k210

Upper_Data_Receive: Save the received k210 data

Motion_Get_APB: Returns half of the current wheel axle spacing of the car

Set_Motor: Sets the motor type of the four-way motor driver board, and changes the motor type according to your actual situation

Motion_Car_Control: Controls the different motion states of the car

Configure motor parameters

Contrl_Speed: Control the speed of 4 motors separately

Contrl_Pwm: Control 4 motors separately through PWM.

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.

USART_Init: Initialize the serial port for communication with the four-way motor driver board

Get_CMD_Flag: Start receiving data from k210

Upper_Data_Parse: Parse the received data from k210. And judge the function

Clear_CMD_Flag: Clear the received data and related flags

4. Experimental operation

  1. Burn the program to MSPM0.
  2. Download the car drive library and PID control library in the K210\library directory to the root directory of the memory card in advance.
  3. Open CanMV IDE and download the follow_color.py code into the K210 module.
  4. Connect all the wires of the car.
  5. Put the car into the map of the visual patrol line, move the K210 module bracket to a suitable angle, and turn on the switch of the car.
  6. After waiting for the system to initialize, the LCD displays the camera screen, and there is a white box in the middle of the screen. Please move the car to fill the white box with the color to be identified, and wait for the white box to turn green to start collecting colors. After the collection is completed, the green box disappears and the program starts running.

5. Experimental phenomenon

After waiting for the system to initialize, the LCD displays the camera image, and there is a white box in the middle of the screen. Please put the color to be identified in the white box, wait for the white box to turn green to start collecting colors, and the green box disappears after the collection is completed, and the program starts running.

The car will move with the color identified by the green box in the previous step. When the color is far away from the car, the car moves forward, when the color is close to the car, the car moves backward, and when the color moves to the left/right, the car also moves to the left/right, so that the identified color remains in the middle of the screen.

If you find that the car often cannot follow the object, please place a solid color object on the white background for the car to follow. If the problem is that the car reacts too slowly or too quickly, you can adjust the values ​​of PID_x and PID_y appropriately.