[World's Largest High School Robot Contest] About FRC Program ~ About PID Control ~

This article is part of the article here. First, please take a look at this.

FIRST At first.

It's about PID control.

彡 (゚) (゚) "I already know PID control! I don't want to"

For those who say, [Handling PID control in WPILib](Handling PID control in #WPILib). It will be written in a very different way from writing a program normally, so ...

I think PID control is hard to understand at first glance. Please take what you are saying and read it thinking that it is like this.

Even if you don't know the detailed mechanism, you can write the code, and if you touch it, you will understand it (appropriate).

What is PID control?

I think there are N articles, so I'll leave it to you () Here's what I thought was easy to understand.

However, if you don't understand the mind of calculus, it's difficult anyway, so lightly. Derivative is an operation to find the degree of increase in value (slope in a graph). Integral is the total difference from the target value in PID control (the area between the target value and the measured value in the graph).

This is pretty concise What is PID control?

This may be hard in the second half Motor PID control method

This can be difficult without knowing math and terms I will explain PID control in the universe in an easy-to-understand manner

Handling of PID control in WPILib

Now that you understand PID control, it's a programmatic story.

Before that, I would like to sort out the terms. If you compare it to an air conditioner

Temperature sensor, input part The output part where the air is sent

Gain what is indicated by kp, ki, kd

Is called.

Basic

In WPILib, PID control is performed by a class called PIDController.

Set a target value such as pidController.setPoint (setpoint) and move it.

So what you need is the gain, input and output parts. This is set in the constructor.

new PIDController(kp, ki, kd, SourceModule, OutputModule)

ʻInputModule must be the input part that inherits the interface PIDSource, and ʻOutputModule must be the output part that inherits PIDOutput. There is one more thing I need to do, but I will introduce it later.

PID control processing flow

PID control in WPILib is executed in 0.05 seconds per loop by setting up another thread. (By the way, this loop is every 0.20 seconds)

Every loop, it receives the current value from the input part, calculates based on it, and outputs it to the output part.

About the input part

To receive the current value from the input part, use the function double pidGet () of PIDSource. Of course PIDSource is an interface, so you need to override this function. If it is an encoder, use a function that returns the distance, and if it is a gyro, use a function that returns the angle, and return it as a double type.

Alternatively, you must override void setPIDSourceType (PIDSourceType pidSource) or PIDSourceType getPIDSourceType (). However, PIDSourceType is

PIDSourceType.java


public enum PIDSourceType {
  kDisplacement,
  kRate
}

To be honest, there is no use for it, so let's override it appropriately.

About the output part

When outputting in the output part, use the function void pidWrite (double output) of PID Output. Of course, PIDOutput is an interface, so you need to override this function. Substitute the argument ʻoutput` to the motor.

** Assignment must be closed within this function ** If you inadvertently assign in this thread, the PID control system will drop considerably with assignment every 0.20 seconds.

How to use PIDController

I will use it when it becomes possible to assign an instance and use it.

Set the target value (Setpoint) with pidController.setSetpoint (double setpoint) and set it. If you enable it with pidController.enable (), it will work.

By the way, if Setpoint simply passes the value of the input part with pidGet (), it will be substituted with ** absolute coordinates ** based on the initialized state of the input part.

Taking the undercarriage motor as an example, If the encoder is initialized at the start point, the target value will be treated as the distance based on the start point, no matter how much it moves.

If you initialize the encoder, go 1m forward, and then want to go 2m down from there If you enter pidController.setSetpoint (-2.0), it will drop 3m from there.

To make it work properly Substitute pidController.setSetpoint (-1.0), or more specifically pidController.setSetpoint (1.0 --2.0).

Supplement

If you want to run the robot straight, you need two PID controls for the undercarriage. It is necessary to separate the one for moving forward and the one for not shifting sideways.

LAST Finally.

I think it was quite difficult to understand because I was not good at explaining. I'm sorry. I was sleepy when I was writing (excuse) Even if you don't understand it, it's pretty good. Then.

Previous article ⇒ Main related Next article ⇒ Drive related

Recommended Posts

[World's Largest High School Robot Contest] About FRC Program ~ About PID Control ~
[World's Largest Junior and Senior High School Robot Contest] About FRC Program ~ Terms ~
[World's Largest Junior and Senior High School Robot Contest] About FRC Program ~ Grabber Related ~
[World's Largest Junior and Senior High School Robot Contest] About FRC Program ~ Lift Related ~
[World's Largest Junior and Senior High School Robot Contest] About the program at FRC ~ Main related ~
About the program of the world's largest high school student Robocon FRC ~ Climb relations ~