搜索
bottom↓
回复: 6

有电流环作为内环,速度环的表达式应该怎么才稳妥?

[复制链接]

出0入0汤圆

发表于 2023-5-21 18:31:07 | 显示全部楼层 |阅读模式
贴图是现在用的,积分限幅暂时注释了。电流限制设置为15A。

目前P不为0,I和D暂时为0。
存在的问题:
P参数可以给的很大,比如30,这样目标速度给到500rpm之后,实际速度大概在495rpm左右。
但超低速,它是转不起来的。比如1rpm就没有反应了。

I参数不为0之后,如果 I 给的很小,静差消除的很慢。
如果I给的再大一丢丢,静差虽然消除的快了,但肯定会产生超调。
而且速度给0之后,还有余速,慢慢转了几圈才停。



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入63汤圆

发表于 2023-5-21 19:25:43 | 显示全部楼层
这种入门级的问题,chatGPT应该写的代码应该直接就可以用了。

出0入0汤圆

 楼主| 发表于 2023-5-21 19:48:37 | 显示全部楼层
n_cell 发表于 2023-5-21 19:25
这种入门级的问题,chatGPT应该写的代码应该直接就可以用了。
(引用自2楼)

让ChatGPT写一段 电流环上叠加速度环的代码

// 定义电流环参数
float kp_current = 0.1;  // 电流环比例增益
float ki_current = 0.05; // 电流环积分增益

// 定义速度环参数
float kp_velocity = 0.2;  // 速度环比例增益
float ki_velocity = 0.1; // 速度环积分增益

// 初始化变量
float current_error = 0.0;
float current_integral = 0.0;
float velocity_error = 0.0;
float velocity_integral = 0.0;
float control_output = 0.0;

// 循环运行控制
while (true) {
    // 读取电流传感器值
    float current_sensor_value = readCurrentSensor();

    // 计算电流环误差
    current_error = desired_current - current_sensor_value;

    // 计算电流环积分项
    current_integral += current_error;

    // 计算电流环输出
    float current_output = kp_current * current_error + ki_current * current_integral;

    // 读取速度传感器值
    float velocity_sensor_value = readVelocitySensor();

    // 计算速度环误差
    velocity_error = desired_velocity - velocity_sensor_value;

    // 计算速度环积分项
    velocity_integral += velocity_error;

    // 计算速度环输出
    float velocity_output = kp_velocity * velocity_error + ki_velocity * velocity_integral;

    // 计算总的控制输出
    control_output = current_output + velocity_output;

    // 执行控制输出
    executeControlOutput(control_output);
}

出0入0汤圆

 楼主| 发表于 2023-5-21 19:49:50 | 显示全部楼层
重新提问,电流环作为内环,速度环作为外环,写一段代码

# 定义电流环参数
kp_current = 0.1  # 电流环比例增益
ki_current = 0.05  # 电流环积分增益

# 定义速度环参数
kp_velocity = 0.2  # 速度环比例增益
ki_velocity = 0.1  # 速度环积分增益

# 初始化变量
current_error = 0.0
current_integral = 0.0
velocity_error = 0.0
velocity_integral = 0.0
control_output = 0.0

# 循环运行控制
while True:
    # 读取速度传感器值
    velocity_sensor_value = readVelocitySensor()

    # 计算速度环误差
    velocity_error = desired_velocity - velocity_sensor_value

    # 计算速度环积分项
    velocity_integral += velocity_error

    # 计算速度环输出
    velocity_output = kp_velocity * velocity_error + ki_velocity * velocity_integral

    # 读取电流传感器值
    current_sensor_value = readCurrentSensor()

    # 计算电流环误差
    current_error = velocity_output - current_sensor_value

    # 计算电流环积分项
    current_integral += current_error

    # 计算电流环输出
    current_output = kp_current * current_error + ki_current * current_integral

    # 执行控制输出
    executeControlOutput(current_output)

出0入0汤圆

 楼主| 发表于 2023-5-21 19:50:34 | 显示全部楼层
你没做积分限幅吗?

# 定义电流环参数
kp_current = 0.1  # 电流环比例增益
ki_current = 0.05  # 电流环积分增益

# 定义速度环参数
kp_velocity = 0.2  # 速度环比例增益
ki_velocity = 0.1  # 速度环积分增益

# 定义积分限幅
current_integral_limit = 10.0
velocity_integral_limit = 20.0

# 初始化变量
current_error = 0.0
current_integral = 0.0
velocity_error = 0.0
velocity_integral = 0.0
control_output = 0.0

# 循环运行控制
while True:
    # 读取速度传感器值
    velocity_sensor_value = readVelocitySensor()

    # 计算速度环误差
    velocity_error = desired_velocity - velocity_sensor_value

    # 计算速度环积分项
    velocity_integral += velocity_error

    # 限制速度环积分项
    velocity_integral = max(min(velocity_integral, velocity_integral_limit), -velocity_integral_limit)

    # 计算速度环输出
    velocity_output = kp_velocity * velocity_error + ki_velocity * velocity_integral

    # 读取电流传感器值
    current_sensor_value = readCurrentSensor()

    # 计算电流环误差
    current_error = velocity_output - current_sensor_value

    # 计算电流环积分项
    current_integral += current_error

    # 限制电流环积分项
    current_integral = max(min(current_integral, current_integral_limit), -current_integral_limit)

    # 计算电流环输出
    current_output = kp_current * current_error + ki_current * current_integral

    # 执行控制输出
    executeControlOutput(current_output)

出0入0汤圆

 楼主| 发表于 2023-5-21 19:53:44 | 显示全部楼层
n_cell 发表于 2023-5-21 19:25
这种入门级的问题,chatGPT应该写的代码应该直接就可以用了。
(引用自2楼)

chatGPT没有调试经验,只能抄别人的代码改改,没有什么亮点。

出0入0汤圆

 楼主| 发表于 2023-5-21 23:35:18 | 显示全部楼层
其实我想表达的意思是,有电流内环的基础上,做一个位置式的速度环PID,虽然稳态后速度确实可以没有静差。

但是积分值稍微小一些,静差就会收敛过慢,值超微大一些,就会产生收敛时间也很慢的超调,很难找到一个鲁棒性很好的平衡点。

无电流内环的情况下,使用增量式PID,情况就好的多。从表达式的物理意义上看,是没有积分的存在,只有PD,鲁棒性超级好。

https://www.amobbs.com/thread-5778347-1-1.html 关于PD还是PI,之前这个帖子上我提过了。大众普遍叫它PI,我觉得物理意义上,认为它叫PD更合适。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-4 13:16

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表