Home > other >  About the problem of PID algorithm in ROSArduinobridge
About the problem of PID algorithm in ROSArduinobridge

Time:12-01

Recently in learning ROSArduinobridge PID program,
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 drive
While (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:

reference 1/f, worldy response:
controller are generally loop drive
While (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 logical


Void loop () {

While (Serial. The available () & gt; 0 {

//Read the next character
CRH=Serial. The read ();

//the Terminate a command with a CR
If (CRH==13) {
If (arg==1) argv1 [index]=NULL;
Else if (arg==2) argv2 [index]=NULL;
RunCommand ();
ResetCommand ();
}
//Use Spaces to delimit with parts of the command
Else if (CRH==' ') {
//Step through the arguments
If (arg==0) arg=1;
Else if (arg==1) {
Argv1 [index]=NULL;
Arg=2;
The index=0;
}
continue;
}
The else {
If (arg==0) {
//The first arg is The single - letter command
CMD=CRH;
}
Else if (arg==1) {
//Subsequent arguments can be more than one character
Argv1 [index]=CRH;
Index++;
}
Else if (arg==2) {
Argv2 [index]=CRH;
Index++;
}
}

}

//If we are using the base control, run a PID calculation at the appropriate intervals
# ifdef USE_BASE
If (millis () & gt; NextPID) {
UpdatePID ();
NextPID +=PID_INTERVAL;
}

//Check to see if we have exceeded the auto - stop interval
If ((millis () - lastMotorCommand) & gt; AUTO_STOP_INTERVAL) {;
SetMotorSpeeds (0, 0);
Moving=0;
}
# endif
Code, this cycle is PID_INTERVAL,
So, in the application of PID algorithm and calculation Error, with the target value of 1 SEC minus the actual value of 1/30 of a second, so also can?

CodePudding user response:

Can't, of course,

Computing speed you must calculate encoder difference except in timing time difference, this is the speed value

CodePudding user response:

reference worldy reply: 3/f
can't, of course,

Computing speed you must calculate encoder difference time in addition to the time difference, this is the speed value


This is the place where I doubt, but this is the source ROSArduinobridge inside is so written,
I saw a lot of all sorts of blog in CSDN, no one mentioned this problem, so I always doubt is own understanding there is a problem,

Attach all code address:
https://blog.csdn.net/qq_29735067/article/details/81561261

CodePudding user response:

If ( millis () & gt; NextPID {
)UpdatePID ();
NextPID +=PID_INTERVAL;
}

Fixed red statement put updatePID call cycle, cycle T can not participate in calculation, so long as is a fixed value, because/T will end up setting the PID coefficient in

CodePudding user response:

reference 5 floor worldy reply:
if ( millis () & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related