使实时信号斜坡平滑

时间:2019-06-05 14:08:19

标签: python signals live timestep

我有实时模拟控制信号,其值可以从200到-200。第一个问题是,它的加速和减速太快了,所以我制作了限制加减速的python代码(是的,在这里python是唯一的选择):

def signal_ramp(Guide_Signal, ramp_signal_pre, acc, dec = 0):
    if dec == 0:
        dec = acc

    if sign(Guide_Signal) != sign(ramp_signal_pre) and ramp_signal_pre != 0:  # If guide signal has different direction than ramp_signal, then first brake and then accelerate
        Guide_Signal = 0

    singal_d = abs(Guide_Signal) - abs(ramp_signal_pre)
    if singal_d < 0 and abs(singal_d) > dec:  # Brake
        if Guide_Signal == 0:
            return ramp_signal_pre - dec * sign(ramp_signal_pre)
        else:
            return ramp_signal_pre - dec * sign(Guide_Signal)
    elif singal_d > 0 and abs(singal_d) > acc:  # Accelerate
        return ramp_signal_pre + acc * sign(Guide_Signal)
    else:
        return Guide_Signal

这将为信号生成斜坡,如下所示:enter image description here

红线是引导信号,绿线是斜坡信号。

我的问题是,我想使坡道末端平滑,但我不知道如何做。我想制作更像“ Sigmoid函数”的信号,但我不知道是否可以使用实时信号或解决此问题的正确方法。

0 个答案:

没有答案
相关问题