stm32 Bluetooth balanced car project experience (two)

Continued on the contents of a.

First, the car is required to the individual modules and the configuration and initialization functions, to mention here, some of which Briefly;

GPIO motor encoder configured to GPIO_Mode_IN_FLOATING (floating input) mode; frequency and then a timer is arranged for calculating electrical encoder output frequency is changed to each of the encoders;
and an encoder mode is configured to:
TIM_EncoderInterfaceConfig (TIM3, TIM_EncoderMode_TI12 , TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);

Run-balanced vehicle body is mainly done in interrupt here to clarify the timing of the car, can be set by the broken MPU6050 or a timer, an interrupt every 5ms launch, read two motor encoder interruption in the calculating velocity values, then the data acquisition MPU6050 can be directly transplanted packaged MPU6050 punctual atoms file using DMP (or with a complementary filtering, or Kalman filtering) (y-axis angles relative to the car) solves for Roll, gyroy (relative to the car y-axis acceleration), gyroz (car acceleration relative to the z-axis).

These data can be calculated by the car's own state have the ability to obtain it, and then reintroduced into an upstanding ring comes to the speed loop and the steering ring.

PWM_OUT = Vertical_Out (standing ring) -Velocity_Out (speed loop);

MOTOR1 = PWM_OUT-Turn_Out; // left wheel motor output value
MOTOR2 = PWM_OUT + Turn_Out; // right wheel motor output value

Then configure the car interrupt priority, in order to maintain car balance, interrupt output is calculated must be a priority of the highest, it will not be interrupted by other interrupts to ensure that affected the balance of the car.

There is to be the output of the motor car limit, the maximum number is set pwm, limits on the maximum value of the motor car output as much.

Plus some of the details down is encountered:
1, the program written, powered car did not respond?
Possible reason is that, when powered car, MPU6050 may not be ready, which led to MPU6050 initialization program does not perform to, so the car does not respond.

Solution:
can the car before initialization, the first delay of almost 100ms, wait MPU6050 ready to re-initialize it.

2, due to the excessive speed loop control, the car can not cause problems upright?
In fact, because of the speed ring for upright ring is an inhibitory effect, but in fact has always been our aim is to erect the car, where we need to be able to keep the car stable under the premise of reducing the effect of the speed control loop.

Solution:
be appropriate to reduce the car's speed loop Kp, Ki size, but not always possible to make the car stable. Therefore, there is a method, is to regulate the speed loop control period, probably about ten times may be provided in the standing ring. Each control standing ring ten times, the speed control loop output once again.

Adjust the balance of the car is the most difficult transplant MPU6050 file and pid parameters.

MPU6050 transplantation can refer to:

Transplant MPU6050 DMP file

Tune PID parameters, then also no skills, attention tone before the first test in polarity, after determining the positive and negative, and the rest rely on patience it!

Ah, you first think of so many others have thought even more. Great God, please exhibitions!

And then once on a Figure:

Here Insert Picture Description
The next chapter is Bluetooth control, it is easier to introduce numerical control Bluetooth to how motor output value into the car inside.

Then I would put the whole project in my program to share public micro-channel number, there is a need to when you can download. If anxious can add micro-channel contact me on my public micro-channel number to me, I can share directly.

Readers want to be helpful, like it can look at my public, then I will study notes made in the above, we will be able to learn together!

Here Insert Picture Description
Alt

Published 19 original articles · won praise 12 · views 6101

Guess you like

Origin blog.csdn.net/Rosen_er/article/details/104739111