Flisikar Smart car motor PID

Source: Internet
Author: User

PID control that comes to mind when it comes to vehicle control, which is also a term that won't be missed in all technical reports. In the series of the flykar xs128 (II) some motor control items have been mentioned in the PWM module, mainly about using PID and bang-bang control to control the motor, that is, using bang-bang to control the power, PID is used to control the accuracy. The following is a detailed description.

First, let's talk about control. The so-called control is divided by closed-loop control and open-loop control, namely, feedback and no feedback. Of course, PID is clearly controlled by feedback. The so-called closed-loop control is to participate in the calculation based on the actual situation of the control to determine the operation volume size or direction. In a single loop control system, the controlled parameters deviate from the given values due to the disturbance, resulting in deviations, the Adjustment Unit of the automatic control system compares the measured value from the transmitter with the given value for proportional, integral, and differential operations, and outputs unified standard signals, to control the action of the Execution Agency to automatically control the temperature, pressure, flow and speed.

However, it involves advanced PID, such as adaptive control, fuzzy control, predictive control, neural network control, and intelligent expert control. Fuzzy Control takes some time and I don't know anything about it, no.

 

Proportional, integral, and differential linear combination, constitute the control u (t), called: proportional (proportional), integral (Integral) and differential (differentiation) control, PID control. Proportional P is only proportional to the deviation. Integral I is the accumulation of deviation on time, while differential d is the variation rate of deviation.

In an image metaphor, proportional p represents the present, integral I represents the past, and differential D represents the future.

 

Formula

In terms of proportion, points, and differentiation, there are a lot of information on the Internet, which I will not talk about.

The following is the key to the normal temperature operation of the entire PID system when the proportional coefficient, integral coefficient, and differential coefficient are adjusted properly.

The best way to find the PID parameter is to calculate the parameter based on the system's mathematical model and the desired response. Most of the time, a detailed mathematical description does not exist. At this time, you need to adjust the PID parameter from the actual situation.

 

Ziegler -- nickls Method

 

Ziegler-The nickls method is a PID tuning method based on system stability analysis. In the design process, there is no need to consider any characteristics, and the tuning method is simple.

 

The setting value of tyreus -- luyben reduces the impact of shock and enhances the system stability.

In theory, I will not talk much about it. I am too lazy to read it.

/*************************************** *************************
Code War or 5.0
Target: mc9s12xs128
CRYSTAL: 16.000 MHz
By: PANG Hui
Wuhu General Assembly's apsikar Project Team
**************************************** **************************/

Sint16 ideal_speed; // ideal speed of the car

// Select the pulse for the dial Switch
Const sint16 speed_arr1 [1, 253] = {
, 37

};
Const sint16 speed_arr2 [1, 253] = {
38,38, 38,90, 90,90, 38,38, 38
};


Const sint16 speed_arr3 [253] = {
40, 40, 40, 95, 40, 40
};

Const sint16 speed_arr4 [253] = {
45, 45, 45, 95, 45, 45
};

Const sint16 speed_arr5 [1, 253] = {
50, 50, 50, 95, 50, 50
};

Const sint16 speed_arr6 [1, 253] = {
37,37, 37,100,100,100, 37,37, 37

};

Const sint16 speed_arr7 [10] =
{
40, 40, 40,100,100,100, 40, 40
};


Void motor_change (void)
{



If (porta_pa0 = 0)
{
Ideal_speed = speed_arr1 [POS _ + 4];
}
Else if (porta_pa1 = 0)
{
Ideal_speed = speed_arr2 [POS _ + 4];
}
Else if (porta_pa2 = 0)
{
Ideal_speed = speed_arr3 [POS _ + 4];
}
Else if (porta_pa3 = 0)
{
Ideal_speed = speed_arr4 [POS _ + 4];
}
Else if (porta_pa4 = 0)
{
Ideal_speed = speed_arr5 [POS _ + 4];
}
Else if (porta_pa5 = 0)
{
Ideal_speed = speed_arr6 [POS _ + 4];
}
Else if (porta_f6 = 0)
{
Ideal_speed = speed_arr7 [POS _ + 4];
}
Else
{
Ideal_speed = speed_arr1 [POS _ + 4];
}

// Ideal_speed = speed_arr7 [POS _ + 4];

Speed_error = ideal_speed-pulse_count;

If (speed_error> = 10) // Case 1, Full acceleration
{
Set_pwm01( 10000,100 00 );
}

Else if (speed_error>-10) // Case 2, use PID to slow down
{
PID ();
}
Else
{
Set_pwm01 (0,10000 );
}

}

 

# Define kp_motor 15
# Define ki_motor 4 // 1
# Define kd_motor 8 // 10

Sint16 speed_error; // deviation between ideal and actual speed
Sint16 pre_error; // speed error value of the previous Speed PID ideal_speed-pulse_count
Sint16 pre_d_error; // speed error d_error-pre_d_error of the previous speed error of the Speed PID
Sint16 PK; // Speed PID Value

Void PID (void)
{
Sint16 error, d_error, dd_error;

Error = ideal_speed-pulse_count;
D_error = Error-pre_error;
Dd_error = d_error-pre_d_error;

Pre_error = error; // store the current Deviation
Pre_d_error = d_error;

PK + = kp_motor * d_error + ki_motor * error + kd_motor * dd_error;

If (primary key> = 10000)
{
PK = 10000;
}
Else if (Pk <= 0)
{
PK = 0;
}

Set_pwm01 (PK, 10000 );
}

The code of the photoelectric car is used here. We will go to Hangzhou for the competition next week. The depressing thing is that we will switch from the electromagnetic field to the photoelectric field, and wish ourselves good results first.

Many teams are too afraid of PID. In fact, if you really don't want to adjust the PID parameter, or you don't have time to adjust it, you can simply write three numbers for other teams, which is better than open-loop, as I went to the Anhui division last month, I did see a lot of games without PIDs. If I didn't talk about PIDs, You would not dare to speed up when you go straight. Otherwise, you will definitely die when you go over the road, of course, this should also work with the reverse brake. This is also to be written. Don't worry, it should be faster.

 

Bytes ------------------------------------------------------------------------------------------------------

 

Repost my blog article solemnly states: the famous author of a technical website can be reprinted, and a commercial website can be reprinted only with my consent; otherwise, the website will be held accountable --

Pang123hui blog:

Blog Park http://www.cnblogs.com/pang123hui/

Csdnhttp: // blog.csdn.net/pang123hui/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.