sy8501 发表于 2023-5-21 18:31:07

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

贴图是现在用的,积分限幅暂时注释了。电流限制设置为15A。

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

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



n_cell 发表于 2023-5-21 19:25:43

这种入门级的问题,chatGPT应该写的代码应该直接就可以用了。

sy8501 发表于 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);
}

sy8501 发表于 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)

sy8501 发表于 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)

sy8501 发表于 2023-5-21 19:53:44

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

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

sy8501 发表于 2023-5-21 23:35:18

其实我想表达的意思是,有电流内环的基础上,做一个位置式的速度环PID,虽然稳态后速度确实可以没有静差。

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

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

https://www.amobbs.com/thread-5778347-1-1.html 关于PD还是PI,之前这个帖子上我提过了。大众普遍叫它PI,我觉得物理意义上,认为它叫PD更合适。
页: [1]
查看完整版本: 有电流环作为内环,速度环的表达式应该怎么才稳妥?