打印
[牛人杂谈]

我让chatGPT帮我写PID,它写的好像不对呀

[复制链接]
339|9
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
gp, pi, pid



增量式PID控制的C程序: 以下为一个使用C语言编写的基本增量式PID控制程序:
#include <stdio.h>
//Define Variables
int target;
int KP;
int KI;
int KD;

//Function definition
void pid_control(int Error){
    int Proportional_Control, Integral_Control, Derivative_Control, Output;
   
    Proportional_Control = Error * KP;        //Proportional Control

    Integral_Control = Error * KI;           //Integral Control

    Derivative_Control = Error * KD;         //Derivative Control

    Output = Proportional_Control + Integral_Control + Derivative_Control;      //Calculate the Output

    if (Output > 0){                                  //Limit the output
       printf("Increase output");                     //Do appropriate action
    }
    else {
       printf("Decrease output");                     //Do appropriate action
    }
}

int main(){
    printf("Enter the Target Value:");
    scanf("%d", &target);                             //Read the target value

    //Calculate PID coefficients
    KP = 2.5;
    KI = 0.5;
    KD = 0.1;

    pid_control(target);                              //Call the function to control the system

    return 0;
}
然后我让它再写一份

#include <stdio.h>

int main()
{
    float error, prevError;
    float Kp, Ki, Kd;
    float output;

    // Proportional gain
    Kp = 0.5;

    // Integral gain
    Ki = 0.1;

    // Derivative gain
    Kd = 0.05;

    while (1)
    {
        // Compute Error
        prevError = error;
        error = getError();  // This should return the process error as a float

        // Compute output from PID algorithm
        float pTerm = Kp * error;
        float iTerm = Ki * (error + prevError);
        float dTerm = Kd * (error - prevError);
        output = pTerm + iTerm + dTerm;
         
        // Send output to the system to be controlled
        outputControl(output);   // This should send the processed output to the system being controlled
     }
     return 0;
}
我怎么看第一个不对,大家说它写的对吗?

使用特权

评论回复
沙发
gaoyang9992006|  楼主 | 2023-2-15 09:03 | 只看该作者
又给我来了一段
/*
* Program to illustrate Incremental PID control
*/
# include <stdio.h>
int main()
{
     double Kp, Ki, Kd; // Proportional, Integral, Derivative constants
     int i;

     // Get the user input
     printf("Enter the Proportional(Kp), Integral(Ki), and Derivative(Kd) values:");
     scanf("%lf %lf %lf", &Kp, &Ki, &Kd);

     // Compute the incremental PID output
     double increment = Kp + Ki + Kd;

     // Apply the incremental PID output
     for (i=0; i<1000; i++) {
         printf("Incremental PID Output at Timestep %d = %f\n", i, increment);

     }

     // Exit gracefully
     return 0;
}

使用特权

评论回复
板凳
小明的同学| | 2023-2-19 18:15 | 只看该作者
哈哈,这东西参考还可以,用我是不敢。

使用特权

评论回复
地板
小小蚂蚁举千斤| | 2023-2-23 16:11 | 只看该作者
chatGPT说是这个写论文太可以了

使用特权

评论回复
5
huangcunxiake| | 2023-2-23 21:54 | 只看该作者
好玩,怎么安装的,分享个key吧

使用特权

评论回复
6
AdaMaYun| | 2023-2-24 08:48 | 只看该作者
这是科技还是狠活,文字类看过文章好像效果不错,这么看代码不行

使用特权

评论回复
7
gaoyang9992006|  楼主 | 2023-2-24 08:49 | 只看该作者
AdaMaYun 发表于 2023-2-24 08:48
这是科技还是狠活,文字类看过文章好像效果不错,这么看代码不行

是的,这东西其实并没真正理解什么是PID算法。只是胡乱匹配数据库内的资料。

使用特权

评论回复
8
AloneKaven| | 2023-3-1 20:16 | 只看该作者
这个只适合搞点文章吧

使用特权

评论回复
9
phoenixwhite| | 2023-3-11 21:58 | 只看该作者
就当人脑看就行了。              

使用特权

评论回复
10
janewood| | 2023-3-14 15:48 | 只看该作者
不知道在哪里搜索来的呢              

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

认证:西安公路研究院南京院
简介:主要工作从事监控网络与通信网络设计,以及从事基于嵌入式的通信与控制设备研发。擅长单片机嵌入式系统物联网设备开发,音频功放电路开发。

1897

主题

15634

帖子

198

粉丝