TargetTicksPerFrame program that setting a parameter value, its annotations mean to set the target value of speed (in the encoder pulse number of each cycle to express),
Double TargetTicksPerFrame;//target speed in ticks per frame
My question is what the cycle period?
The Error in the program of calculation is:
P - & gt; TargetTicksPerFrame - input;
Of which the input is change before and after two cycles of encoder values (the cycle should be PID computation period), then TargetTicksPerFrame value should also be with cycle in the target to be meaningful? So, according to my understanding, TargetTicksPerFrame value should be the set speed into PID computation period the number of encoder pulses within 1/30 of a second (PID_RATE=30//HZ),
However, when I "m 20 20" command, let the motor speed setting is 20 pulses per second, this value is directly given 20, namely cycle is 1 second,
Great god answer, please.
The relevant code:
PID computation part:
Double TargetTicksPerFrame;//target speed in ticks per frame each frame ticks value of the corresponding target speed
Long Encoder;//encoder count encoder count
Long PrevEnc;//the last encoder count on a encoder count
Int PrevInput;//the last input on an input
Int PrevErr;//the last error test
Int ITerm.//integrated term
Long the output;//the last motor output setting
Input=p - & gt; Encoder - p - & gt; PrevEnc;
Perror=p - & gt; TargetTicksPerFrame - input;
The output=(Kp * Perror - Kd * (input - p - & gt; PrevInput) + p - & gt; ITerm)/Ko.
P - & gt; PrevEnc=p - & gt; Encoder;
The output +=p - & gt; The output;
Void updatePID () {//PDD update function, including the encoder collection, PID and set motor PWM, we adjust the actual function,
LeftPID. Encoder=readEncoder (LEFT);
RightPID. Encoder=readEncoder (RIGHT);
if (! Moving) {
If (leftPID PrevInput!=0 | | rightPID PrevInput!=0) resetPID ();
return;
}
/* Compute PID update for each motor */
DoPID (& amp; RightPID);
DoPID (& amp; LeftPID);
/* Set the motor speeds accordingly */
SetMotorSpeeds (leftPID. The output, rightPID. Output);
Speed setting part code:
Case MOTOR_SPEEDS://this setting speed, the corresponding command format is m arg1 arg2
/* Reset the auto stop the timer */
LastMotorCommand=millis ();
If (arg1==0 & amp; & Arg2==0) {
SetMotorSpeeds (0, 0);
ResetPID ();
Moving=0;
}
The else moving=1;
LeftPID. TargetTicksPerFrame=arg1;
RightPID. TargetTicksPerFrame=arg2;
Serial. Println (" OK ");
break;
CodePudding user response:
Controller is usually loop driveWhile (true)
{
Dowork ();
}
A cycle from red to blue, there is a cycle contains the code has been completed
Single-chip computer, PLC and other basic it is such a logic
CodePudding user response: