Car Diagonal Movement

Control the car's oblique movement by pressing K1.

Device connection

Hardware connection

Use Type-B data cable to connect Arduino Uno and computer.

Software connection

Open the "Arduino IDE" software and select the model and serial port number corresponding to the development board.

Motion analysis

Yellow arrow: motor rotation direction (upward means forward-motor forward rotation, downward means backward-motor reverse rotation)

Red arrow: actual movement direction of the car

Green arrow: speed decomposition direction (where the dotted arrow is the offset speed component, and the red arrow is the actual speed component)

image-20240602124012358

Control the motor

The motor is directly driven by the underlying driver chip on the Robduino expansion board. The underlying driver chip and the Arduino Uno board use I2C communication, and the I2C address is 0x40.

Control Principle

The motor rotation angle is controlled by changing the duty cycle of the PWM signal that controls the motor signal pin.

Common parameters

Period: The duration of a complete PWM waveform;

Duty cycle: The ratio of the duration of the high level to the cycle time;

Frequency: The reciprocal of the period is called the frequency, that is, the number of PWM periods generated per second;

Control pins

Peripheral moduleI2C register first address number (STC8GK2K64S4)Control motor direction
L1 (upper left corner motor)11Control forward (forward)
L1 (upper left corner motor)10Control reverse (backward)
L2 (lower left corner motor)8Control forward (forward)
L2 (lower left corner motor)9Control reverse (backward)
R1 (upper right corner motor)13Control forward rotation (forward)
R1 (upper right corner motor)12Control reverse rotation (backward)
R2 (lower right corner motor)14Control forward rotation (forward)
R2 (lower right corner motor)15Control reverse rotation (backward)

Code analysis

Here we only briefly introduce the code content. For detailed code, please refer to the corresponding code file, which is provided in the download area!

Experimental results

After compiling the program successfully, upload the code to the Arduino Uno development board.

After the program starts, press the K1 button to start the car's oblique motion function.

Since our code uses blocking delay, pressing the K1 button may not stop the car; so to stop the car from running, you can turn off the power switch on the expansion board or press the Reset button on the expansion board to restart the program back to the original state.