最新消息:啵叻潮流,抢鲜了解时尚潮流风向。www.booolo.com

PID Controller based on NXT using ROBOTC

Technology kumuking 22427浏览 0评论

PID controller knowledge and basic ROBOTC is required for this post.
PID controller information can be acquired  here: http://en.wikipedia.org/wiki/PID_controller
ROBOTC knowledge is available here: http://www.robotc.net

In ROBOTC, we’ll write a code for our own PID controller to ensure the robot car will run a specified target. We’ll define the error signal as the actual angle of the encoder and angle set point (target angle). The angle set point is 500 degrees. The motor will run for 10s.

Figure 1: PID control for general system

Since we want to use our own PID controller, we have to disable all inbuilt ROBOTC PID control functions. This can be done using the commands shown below.

nMotorPIDSpeedCtrl[motorA] = mtrNoReg;//disable NXT inbuilt PID

nMotorPIDSpeedCtrl[motorB] = mtrNoReg;//disable NXT inbuilt PID

nSyncedMotors = synchNone;//disable NXT inbuilt PID

We tune the PID controller by Ziegler-Nichols method to find Ku and Tu. It’s a little difficult to find perfect Kp, Ki and Kd though when you know Ku and Tu. As for us, we get the value of Ku and Tu, but we try many times to find good Ki and Kd to make the system run stably.

Pseudocode will be help you understand what we aim to do.

previous_error = 0
proportional = 0
integral = 0
derivative = 0
loop:
  error = setpoint - actual_position
  proportional = error
  integral = integral + (error*dt)
  derivative = (error - previous_error)/dt
  output = (Kp*proportional) + (Ki*integral) + (Kd*derivative)
  previous_error = error
  wait(dt)
loop end;

 

In the pseudocode above, Kp, Ki, Kd and dt are not shown how to be got. Because they are constant values. Value of dt is dependent by you. Kp Ki and Kd could be determined by trial and error. The reason why we tune the system is to find Ku and Tu, so we will know approximate values of the three coefficients.

I post the source file here. The code is well commented  and easy to be understood.

ROBOTC Source File : PIDController.c

Figure 2: PID tuning. Z-N oscillations

When Ku is set to 0.09, the system starts to oscillate.

Figure 3: Zoom in the plot of PID tuning. Z-N oscillations

When we try about 70 times, we find when Ki is equal to 0.0000000075 the response is very good.

Figure 4: A good PID response

It seems there is a tolerance, since our target degree is 500. I explain and give examples in my report you can find in the end of this post.

The overshot for my example is 1.349%. The rise time is 0.511s. The settling time for ± 5% error band is 0.6897s, and for ± 2% is 0.7074s

Dependent on the value we got, I believe the project we did is successful. The values and plot are beautiful.

You can find more information in my report. BTW, excuse my English both in this post and report.

Report: PIDController.docx

ROBOTC Source File : PIDController.c

转载请注明:Yung » PID Controller based on NXT using ROBOTC

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (6)

  1. You are welcome to contact me, if you have any suggestion or question.
    kumuking8年前 (2011-04-30)Reply
  2. 執行這程式 SaveNxtDatalog(); 好像不是text file, 所以無法由Excel叫出?? 是否可指點一下
    莊宏祥7年前 (2012-03-01)Reply
    • 我的excel图表不是自动导出的,是手动输入的。
      kumuking7年前 (2012-03-03)Reply
  3. hi, I tried to debug this code to my nxt. it was working fine yesterday.but today it stops after 2 sec. It looks like something holds the wheel, but i checked it does not bec of that.and i couldnt find why. Can you help me about it? Thank you.
    kubie7年前 (2012-04-21)Reply
    • Did u change any parameter? Or are u sure it stopped? Maybe it had turned the target degree already.
      kumuking7年前 (2012-04-21)Reply
      • No i didnt. but when i change the line: errorB=setPoint-actualDegreesB and errorC=setPoint-actualDegreesC to: errorB=actualDegreesB-setPoint errorC=actualDegreesC-setPoint it works fine.so i did that.
        kubie7年前 (2012-04-23)Reply